Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
976bd165
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
976bd165
编写于
10月 28, 2019
作者:
K
KubeSphere CI Bot
提交者:
GitHub
10月 28, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1213 from wansir/caddy
improve path exclusion rule
上级
9bf01ebe
2d14a0f5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
28 deletion
+65
-28
pkg/apigateway/caddy-plugin/authenticate/authenticate.go
pkg/apigateway/caddy-plugin/authenticate/authenticate.go
+4
-3
pkg/apigateway/caddy-plugin/authenticate/auto_load.go
pkg/apigateway/caddy-plugin/authenticate/auto_load.go
+11
-9
pkg/apigateway/caddy-plugin/authentication/authentication.go
pkg/apigateway/caddy-plugin/authentication/authentication.go
+6
-5
pkg/apigateway/caddy-plugin/authentication/auto_load.go
pkg/apigateway/caddy-plugin/authentication/auto_load.go
+12
-11
pkg/apigateway/caddy-plugin/internal/exclusion_rule.go
pkg/apigateway/caddy-plugin/internal/exclusion_rule.go
+32
-0
未找到文件。
pkg/apigateway/caddy-plugin/authenticate/authenticate.go
浏览文件 @
976bd165
...
...
@@ -24,6 +24,7 @@ import (
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/apigateway/caddy-plugin/internal"
"kubesphere.io/kubesphere/pkg/simple/client/redis"
"log"
"net/http"
...
...
@@ -46,7 +47,7 @@ type Rule struct {
RedisOptions
*
redis
.
RedisOptions
TokenIdleTimeout
time
.
Duration
RedisClient
*
redis
.
RedisClient
Exc
eptedPath
[]
string
Exc
lusionRules
[]
internal
.
ExclusionRule
}
type
User
struct
{
...
...
@@ -61,8 +62,8 @@ var requestInfoFactory = request.RequestInfoFactory{
GrouplessAPIPrefixes
:
sets
.
NewString
(
"api"
)}
func
(
h
Auth
)
ServeHTTP
(
resp
http
.
ResponseWriter
,
req
*
http
.
Request
)
(
int
,
error
)
{
for
_
,
path
:=
range
h
.
Rule
.
ExceptedPath
{
if
httpserver
.
Path
(
req
.
URL
.
Path
)
.
Matches
(
path
)
{
for
_
,
rule
:=
range
h
.
Rule
.
ExclusionRules
{
if
httpserver
.
Path
(
req
.
URL
.
Path
)
.
Matches
(
rule
.
Path
)
&&
(
rule
.
Method
==
internal
.
AllMethod
||
req
.
Method
==
rule
.
Method
)
{
return
h
.
Next
.
ServeHTTP
(
resp
,
req
)
}
}
...
...
pkg/apigateway/caddy-plugin/authenticate/auto_load.go
浏览文件 @
976bd165
...
...
@@ -19,9 +19,9 @@ package authenticate
import
(
"fmt"
"kubesphere.io/kubesphere/pkg/apigateway/caddy-plugin/internal"
"kubesphere.io/kubesphere/pkg/simple/client/redis"
"strings"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"time"
"github.com/mholt/caddy"
...
...
@@ -59,8 +59,8 @@ func Setup(c *caddy.Controller) error {
func
parse
(
c
*
caddy
.
Controller
)
(
*
Rule
,
error
)
{
rule
:=
&
Rule
{
ExceptedPath
:
make
([]
string
,
0
)
}
rule
:=
&
Rule
{}
rule
.
ExclusionRules
=
make
([]
internal
.
ExclusionRule
,
0
)
if
c
.
Next
()
{
args
:=
c
.
RemainingArgs
()
switch
len
(
args
)
{
...
...
@@ -118,18 +118,20 @@ func parse(c *caddy.Controller) (*Rule, error) {
return
nil
,
c
.
ArgErr
()
}
case
"except"
:
if
!
c
.
NextArg
()
{
return
nil
,
c
.
ArgErr
()
}
rule
.
ExceptedPath
=
strings
.
Split
(
c
.
Val
(),
","
)
method
:=
c
.
Val
(
)
for
i
:=
0
;
i
<
len
(
rule
.
ExceptedPath
);
i
++
{
r
ule
.
ExceptedPath
[
i
]
=
strings
.
TrimSpace
(
rule
.
ExceptedPath
[
i
]
)
if
!
sliceutil
.
HasString
(
internal
.
HttpMethods
,
method
)
{
r
eturn
nil
,
c
.
ArgErr
(
)
}
if
c
.
NextArg
()
{
return
nil
,
c
.
ArgErr
()
for
c
.
NextArg
()
{
path
:=
c
.
Val
()
rule
.
ExclusionRules
=
append
(
rule
.
ExclusionRules
,
internal
.
ExclusionRule
{
Method
:
method
,
Path
:
path
})
}
}
}
...
...
pkg/apigateway/caddy-plugin/authentication/authentication.go
浏览文件 @
976bd165
...
...
@@ -23,6 +23,7 @@ import (
"fmt"
"k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/endpoints/request"
"kubesphere.io/kubesphere/pkg/apigateway/caddy-plugin/internal"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"log"
"net/http"
...
...
@@ -38,21 +39,21 @@ import (
)
type
Authentication
struct
{
Rule
Rule
Rule
*
Rule
Next
httpserver
.
Handler
}
type
Rule
struct
{
Path
string
Exc
eptedPath
[]
string
Path
string
Exc
lusionRules
[]
internal
.
ExclusionRule
}
func
(
c
Authentication
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
if
httpserver
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
c
.
Rule
.
Path
)
{
for
_
,
path
:=
range
c
.
Rule
.
ExceptedPath
{
if
httpserver
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
path
)
{
for
_
,
rule
:=
range
c
.
Rule
.
ExclusionRules
{
if
httpserver
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
rule
.
Path
)
&&
(
rule
.
Method
==
internal
.
AllMethod
||
r
.
Method
==
rule
.
Method
)
{
return
c
.
Next
.
ServeHTTP
(
w
,
r
)
}
}
...
...
pkg/apigateway/caddy-plugin/authentication/auto_load.go
浏览文件 @
976bd165
...
...
@@ -19,10 +19,10 @@ package authentication
import
(
"fmt"
"strings"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
"kubesphere.io/kubesphere/pkg/apigateway/caddy-plugin/internal"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"kubesphere.io/kubesphere/pkg/informers"
)
...
...
@@ -59,10 +59,10 @@ func Setup(c *caddy.Controller) error {
return
nil
}
func
parse
(
c
*
caddy
.
Controller
)
(
Rule
,
error
)
{
rule
:=
Rule
{
ExceptedPath
:
make
([]
string
,
0
)}
func
parse
(
c
*
caddy
.
Controller
)
(
*
Rule
,
error
)
{
rule
:=
&
Rule
{}
rule
.
ExclusionRules
=
make
([]
internal
.
ExclusionRule
,
0
)
if
c
.
Next
()
{
args
:=
c
.
RemainingArgs
()
switch
len
(
args
)
{
...
...
@@ -83,17 +83,18 @@ func parse(c *caddy.Controller) (Rule, error) {
break
case
"except"
:
if
!
c
.
NextArg
()
{
return
rule
,
c
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
rule
.
ExceptedPath
=
strings
.
Split
(
c
.
Val
(),
","
)
method
:=
c
.
Val
(
)
for
i
:=
0
;
i
<
len
(
rule
.
ExceptedPath
);
i
++
{
r
ule
.
ExceptedPath
[
i
]
=
strings
.
TrimSpace
(
rule
.
ExceptedPath
[
i
]
)
if
!
sliceutil
.
HasString
(
internal
.
HttpMethods
,
method
)
{
r
eturn
nil
,
c
.
ArgErr
(
)
}
if
c
.
NextArg
()
{
return
rule
,
c
.
ArgErr
()
for
c
.
NextArg
()
{
path
:=
c
.
Val
()
rule
.
ExclusionRules
=
append
(
rule
.
ExclusionRules
,
internal
.
ExclusionRule
{
Method
:
method
,
Path
:
path
})
}
break
}
...
...
pkg/apigateway/caddy-plugin/internal/exclusion_rule.go
0 → 100644
浏览文件 @
976bd165
/*
*
* Copyright 2019 The KubeSphere Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* /
*/
package
internal
import
"net/http"
const
AllMethod
=
"*"
var
HttpMethods
=
[]
string
{
AllMethod
,
http
.
MethodPost
,
http
.
MethodDelete
,
http
.
MethodPatch
,
http
.
MethodPut
,
http
.
MethodGet
,
http
.
MethodOptions
,
http
.
MethodConnect
}
// Path exclusion rule
type
ExclusionRule
struct
{
Method
string
Path
string
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录