Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
bb9e12be
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看板
未验证
提交
bb9e12be
编写于
4月 14, 2020
作者:
H
hongming
提交者:
GitHub
4月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix iam admission webhook (#2008)
Signed-off-by:
N
hongming
<
talonwan@yunify.com
>
上级
864b244c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
13 deletion
+37
-13
config/samples/iam_v1alpha2_user.yaml
config/samples/iam_v1alpha2_user.yaml
+1
-1
config/webhook/iam.yaml
config/webhook/iam.yaml
+16
-2
pkg/apis/iam/v1alpha2/register.go
pkg/apis/iam/v1alpha2/register.go
+1
-0
pkg/controller/user/user_webhook.go
pkg/controller/user/user_webhook.go
+19
-10
未找到文件。
config/samples/iam_v1alpha2_user.yaml
浏览文件 @
bb9e12be
...
...
@@ -6,4 +6,4 @@ metadata:
name
:
admin
spec
:
email
:
admin@kubesphere.io
password
:
$2a$04$wr/XmTQ99uQpgi335xPyoOM08h34ZQk265pdqHMv5Yw6Xo2vfiO/6
password
:
P@88w0rd
config/webhook/iam.yaml
浏览文件 @
bb9e12be
---
apiVersion
:
admissionregistration.k8s.io/v1beta1
kind
:
MutatingWebhookConfiguration
metadata
:
...
...
@@ -53,3 +51,19 @@ webhooks:
-
UPDATE
resources
:
-
users
---
apiVersion
:
v1
kind
:
Service
metadata
:
name
:
webhook-service
namespace
:
kubesphere-system
spec
:
ports
:
-
port
:
443
targetPort
:
443
selector
:
app
:
ks-controller-manager
tier
:
backend
\ No newline at end of file
pkg/apis/iam/v1alpha2/register.go
浏览文件 @
bb9e12be
...
...
@@ -50,6 +50,7 @@ func Resource(resource string) schema.GroupResource {
func
addKnownTypes
(
scheme
*
runtime
.
Scheme
)
error
{
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
&
User
{},
&
UserList
{},
&
Role
{},
&
RoleList
{},
&
RoleBinding
{},
...
...
pkg/controller/user/user_webhook.go
浏览文件 @
bb9e12be
...
...
@@ -21,7 +21,6 @@ package user
import
(
"context"
"encoding/json"
"fmt"
"golang.org/x/crypto/bcrypt"
"kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
"net/http"
...
...
@@ -51,28 +50,26 @@ func (a *EmailValidator) Handle(ctx context.Context, req admission.Request) admi
return
admission
.
Errored
(
http
.
StatusBadRequest
,
err
)
}
email
:=
user
.
Spec
.
Email
allUsers
:=
v1alpha2
.
UserList
{}
err
=
a
.
Client
.
List
(
ctx
,
&
v1alpha2
.
UserList
{}
,
&
client
.
ListOptions
{})
err
=
a
.
Client
.
List
(
ctx
,
&
allUsers
,
&
client
.
ListOptions
{})
if
err
!=
nil
{
return
admission
.
Errored
(
http
.
StatusInternalServerError
,
err
)
}
found
:=
emailAlreadyExist
(
allUsers
,
email
)
alreadyExist
:=
emailAlreadyExist
(
allUsers
,
user
)
if
!
found
{
return
admission
.
Denied
(
fmt
.
Sprintf
(
"email %s must be unique"
,
email
)
)
if
alreadyExist
{
return
admission
.
Denied
(
"user email already exists"
)
}
return
admission
.
Allowed
(
""
)
}
func
emailAlreadyExist
(
users
v1alpha2
.
UserList
,
email
string
)
bool
{
for
_
,
user
:=
range
users
.
Items
{
if
user
.
Spec
.
Email
==
email
{
func
emailAlreadyExist
(
users
v1alpha2
.
UserList
,
user
*
v1alpha2
.
User
)
bool
{
for
_
,
exist
:=
range
users
.
Items
{
if
exist
.
Spec
.
Email
==
user
.
Spec
.
Email
&&
exist
.
Name
!=
user
.
Name
{
return
true
}
}
...
...
@@ -109,3 +106,15 @@ func hashPassword(password string) (string, error) {
bytes
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
password
),
bcrypt
.
MinCost
)
return
string
(
bytes
),
err
}
// InjectDecoder injects the decoder.
func
(
a
*
PasswordCipher
)
InjectDecoder
(
d
*
admission
.
Decoder
)
error
{
a
.
decoder
=
d
return
nil
}
// InjectDecoder injects the decoder.
func
(
a
*
EmailValidator
)
InjectDecoder
(
d
*
admission
.
Decoder
)
error
{
a
.
decoder
=
d
return
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录