Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
3c73471f
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看板
未验证
提交
3c73471f
编写于
4月 01, 2020
作者:
Z
zryfish
提交者:
GitHub
4月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix path authorizer give no opinion on resource requests (#1981)
上级
c8dc3a40
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
19 deletion
+15
-19
pkg/apiserver/apiserver.go
pkg/apiserver/apiserver.go
+8
-8
pkg/apiserver/authorization/path/path.go
pkg/apiserver/authorization/path/path.go
+0
-4
pkg/apiserver/filters/authorization.go
pkg/apiserver/filters/authorization.go
+7
-7
pkg/kapis/config/v1alpha2/register.go
pkg/kapis/config/v1alpha2/register.go
+0
-0
未找到文件。
pkg/apiserver/apiserver.go
浏览文件 @
3c73471f
...
...
@@ -25,6 +25,7 @@ import (
"kubesphere.io/kubesphere/pkg/apiserver/filters"
"kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/informers"
configv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/config/v1alpha2"
iamv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/iam/v1alpha2"
loggingv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/logging/v1alpha2"
monitoringv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/monitoring/v1alpha2"
...
...
@@ -33,7 +34,6 @@ import (
operationsv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/operations/v1alpha2"
resourcesv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/resources/v1alpha2"
resourcev1alpha3
"kubesphere.io/kubesphere/pkg/kapis/resources/v1alpha3"
"kubesphere.io/kubesphere/pkg/kapis/serverconfig/v1alpha2"
servicemeshv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/servicemesh/metrics/v1alpha2"
terminalv1alpha2
"kubesphere.io/kubesphere/pkg/kapis/terminal/v1alpha2"
"kubesphere.io/kubesphere/pkg/models/iam/am"
...
...
@@ -133,7 +133,7 @@ func (s *APIServer) PrepareRun() error {
}
func
(
s
*
APIServer
)
installKubeSphereAPIs
()
{
urlruntime
.
Must
(
v1alpha2
.
AddToContainer
(
s
.
container
,
s
.
Config
))
urlruntime
.
Must
(
config
v1alpha2
.
AddToContainer
(
s
.
container
,
s
.
Config
))
urlruntime
.
Must
(
resourcev1alpha3
.
AddToContainer
(
s
.
container
,
s
.
InformerFactory
))
// Need to refactor devops api registration, too much dependencies
//urlruntime.Must(devopsv1alpha2.AddToContainer(s.container, s.DevopsClient, s.DBClient.Database(), nil, s.KubernetesClient.KubeSphere(), s.InformerFactory.KubeSphereSharedInformerFactory(), s.S3Client))
...
...
@@ -181,20 +181,20 @@ func (s *APIServer) buildHandlerChain() {
}
handler
:=
s
.
Server
.
Handler
handler
=
filters
.
WithKubeAPIServer
(
handler
,
s
.
KubernetesClient
.
Config
(),
&
errorResponder
{})
handler
=
filters
.
WithMultipleClusterDispatcher
(
handler
,
dispatch
.
NewClusterDispatch
(
s
.
InformerFactory
.
KubeSphereSharedInformerFactory
()
.
Tower
()
.
V1alpha1
()
.
Agents
()
.
Lister
()))
excludedPaths
:=
[]
string
{
"/oauth/*"
,
"/kapis/config.kubesphere.io/*"
}
pathAuthorizer
,
_
:=
path
.
NewAuthorizer
(
excludedPaths
)
authorizer
:=
unionauthorizer
.
New
(
pathAuthorizer
,
authorizerfactory
.
NewOPAAuthorizer
(
am
.
NewFakeAMOperator
()))
handler
=
filters
.
WithAuthorization
(
handler
,
authorizer
)
// union authorizers are ordered, don't change the order here
authorizers
:=
unionauthorizer
.
New
(
pathAuthorizer
,
authorizerfactory
.
NewOPAAuthorizer
(
am
.
NewFakeAMOperator
()))
handler
=
filters
.
WithAuthorization
(
handler
,
authorizers
)
// authenticators are unordered
authn
:=
unionauth
.
New
(
anonymous
.
NewAuthenticator
(),
basictoken
.
New
(
basic
.
NewBasicAuthenticator
(
im
.
NewFakeOperator
())),
bearertoken
.
New
(
jwttoken
.
NewTokenAuthenticator
(
token
.
NewJwtTokenIssuer
(
token
.
DefaultIssuerName
,
s
.
Config
.
AuthenticationOptions
,
s
.
CacheClient
))))
bearertoken
.
New
(
jwttoken
.
NewTokenAuthenticator
(
token
.
NewJwtTokenIssuer
(
token
.
DefaultIssuerName
,
s
.
Config
.
AuthenticationOptions
,
s
.
CacheClient
))))
handler
=
filters
.
WithAuthentication
(
handler
,
authn
)
handler
=
filters
.
WithRequestInfo
(
handler
,
requestInfoResolver
)
s
.
Server
.
Handler
=
handler
...
...
pkg/apiserver/authorization/path/path.go
浏览文件 @
3c73471f
...
...
@@ -47,10 +47,6 @@ func NewAuthorizer(alwaysAllowPaths []string) (authorizer.Authorizer, error) {
}
return
authorizer
.
AuthorizerFunc
(
func
(
a
authorizer
.
Attributes
)
(
authorizer
.
Decision
,
string
,
error
)
{
if
a
.
IsResourceRequest
()
{
return
authorizer
.
DecisionNoOpinion
,
""
,
nil
}
pth
:=
strings
.
TrimPrefix
(
a
.
GetPath
(),
"/"
)
if
paths
.
Has
(
pth
)
{
return
authorizer
.
DecisionAllow
,
""
,
nil
...
...
pkg/apiserver/filters/authorization.go
浏览文件 @
3c73471f
...
...
@@ -13,23 +13,23 @@ import (
)
// WithAuthorization passes all authorized requests on to handler, and returns forbidden error otherwise.
func
WithAuthorization
(
handler
http
.
Handler
,
a
authorizer
.
Authorizer
)
http
.
Handler
{
if
a
==
nil
{
func
WithAuthorization
(
handler
http
.
Handler
,
a
uthorizers
authorizer
.
Authorizer
)
http
.
Handler
{
if
a
uthorizers
==
nil
{
klog
.
Warningf
(
"Authorization is disabled"
)
return
handler
}
s
erializer
:=
serializer
.
NewCodecFactory
(
runtime
.
NewScheme
())
.
WithoutConversion
()
defaultS
erializer
:=
serializer
.
NewCodecFactory
(
runtime
.
NewScheme
())
.
WithoutConversion
()
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
ctx
:=
req
.
Context
()
attributes
,
err
:=
G
etAuthorizerAttributes
(
ctx
)
attributes
,
err
:=
g
etAuthorizerAttributes
(
ctx
)
if
err
!=
nil
{
responsewriters
.
InternalError
(
w
,
req
,
err
)
}
authorized
,
reason
,
err
:=
a
.
Authorize
(
attributes
)
authorized
,
reason
,
err
:=
a
uthorizers
.
Authorize
(
attributes
)
if
authorized
==
authorizer
.
DecisionAllow
{
handler
.
ServeHTTP
(
w
,
req
)
return
...
...
@@ -41,11 +41,11 @@ func WithAuthorization(handler http.Handler, a authorizer.Authorizer) http.Handl
}
klog
.
V
(
4
)
.
Infof
(
"Forbidden: %#v, Reason: %q"
,
req
.
RequestURI
,
reason
)
responsewriters
.
Forbidden
(
ctx
,
attributes
,
w
,
req
,
reason
,
s
erializer
)
responsewriters
.
Forbidden
(
ctx
,
attributes
,
w
,
req
,
reason
,
defaultS
erializer
)
})
}
func
G
etAuthorizerAttributes
(
ctx
context
.
Context
)
(
authorizer
.
Attributes
,
error
)
{
func
g
etAuthorizerAttributes
(
ctx
context
.
Context
)
(
authorizer
.
Attributes
,
error
)
{
attribs
:=
authorizer
.
AttributesRecord
{}
user
,
ok
:=
request
.
UserFrom
(
ctx
)
...
...
pkg/kapis/
server
config/v1alpha2/register.go
→
pkg/kapis/config/v1alpha2/register.go
浏览文件 @
3c73471f
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录