Skip to content

Commit

Permalink
feat(server): support name claim for RBAC SSO (#10927)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
  • Loading branch information
agilgur5 committed Apr 18, 2023
1 parent 09d48ef commit d41add4
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ define protoc
-I $(CURDIR) \
-I $(CURDIR)/vendor \
-I $(GOPATH)/src \
-I $(GOPATH)/pkg/mod/github.com/gogo/protobuf@v1.3.1/gogoproto \
-I $(GOPATH)/pkg/mod/github.com/gogo/protobuf@v1.3.2/gogoproto \
-I $(GOPATH)/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.16.0/third_party/googleapis \
--gogofast_out=plugins=grpc:$(GOPATH)/src \
--grpc-gateway_out=logtostderr=true:$(GOPATH)/src \
Expand Down
3 changes: 3 additions & 0 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4811,6 +4811,9 @@
"issuer": {
"type": "string"
},
"name": {
"type": "string"
},
"serviceAccountName": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8742,6 +8742,9 @@
"issuer": {
"type": "string"
},
"name": {
"type": "string"
},
"serviceAccountName": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions docs/workflow-controller-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ data:
scopes:
- groups
- email
- profile
# RBAC Config. >= v2.12
rbac:
enabled: false
Expand Down
139 changes: 95 additions & 44 deletions pkg/apiclient/info/info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apiclient/info/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ message GetUserInfoResponse {
bool emailVerified = 5;
string serviceAccountName = 6;
string serviceAccountNamespace = 7;
string name = 8;
}

message CollectEventRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Name | Type | Description | Notes
**emailVerified** | **Boolean** | | [optional]
**groups** | **List&lt;String&gt;** | | [optional]
**issuer** | **String** | | [optional]
**name** | **String** | | [optional]
**serviceAccountName** | **String** | | [optional]
**serviceAccountNamespace** | **String** | | [optional]
**subject** | **String** | | [optional]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/auth/sso/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (s *sso) HandleCallback(w http.ResponseWriter, r *http.Request) {
Groups: groups,
Email: c.Email,
EmailVerified: c.EmailVerified,
Name: c.Name,
ServiceAccountName: c.ServiceAccountName,
PreferredUsername: c.PreferredUsername,
ServiceAccountNamespace: c.ServiceAccountNamespace,
Expand Down
1 change: 1 addition & 0 deletions server/auth/types/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Claims struct {
Groups []string `json:"groups,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
Name string `json:"name,omitempty"`
ServiceAccountName string `json:"service_account_name,omitempty"`
ServiceAccountNamespace string `json:"service_account_namespace,omitempty"`
PreferredUsername string `json:"preferred_username,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions server/info/info_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (i *infoServer) GetUserInfo(ctx context.Context, _ *infopkg.GetUserInfoRequ
Subject: claims.Subject,
Issuer: claims.Issuer,
Groups: claims.Groups,
Name: claims.Name,
Email: claims.Email,
EmailVerified: claims.EmailVerified,
ServiceAccountName: claims.ServiceAccountName,
Expand Down
3 changes: 2 additions & 1 deletion server/info/info_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (

func Test_infoServer_GetUserInfo(t *testing.T) {
i := &infoServer{}
ctx := context.WithValue(context.TODO(), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Issuer: "my-iss", Subject: "my-sub"}, Groups: []string{"my-group"}, Email: "my@email", EmailVerified: true, ServiceAccountName: "my-sa"})
ctx := context.WithValue(context.TODO(), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Issuer: "my-iss", Subject: "my-sub"}, Groups: []string{"my-group"}, Name: "myname", Email: "my@email", EmailVerified: true, ServiceAccountName: "my-sa"})
info, err := i.GetUserInfo(ctx, nil)
if assert.NoError(t, err) {
assert.Equal(t, "my-iss", info.Issuer)
assert.Equal(t, "my-sub", info.Subject)
assert.Equal(t, []string{"my-group"}, info.Groups)
assert.Equal(t, "myname", info.Name)
assert.Equal(t, "my@email", info.Email)
assert.True(t, info.EmailVerified)
assert.Equal(t, "my-sa", info.ServiceAccountName)
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/userinfo/components/user-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class UserInfo extends BasePage<RouteComponentProps<any>, State> {
<dt>Groups:</dt>
<dd>{(this.state.userInfo.groups && this.state.userInfo.groups.length > 0 && this.state.userInfo.groups.join(', ')) || '-'}</dd>
</dl>
<dl>
<dt>Name:</dt>
<dd>{this.state.userInfo.name || '-'}</dd>
</dl>
<dl>
<dt>Email:</dt>
<dd>{this.state.userInfo.email || '-'}</dd>
Expand Down
1 change: 1 addition & 0 deletions ui/src/models/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface GetUserInfoResponse {
subject?: string;
issuer?: string;
groups?: string[];
name?: string;
email?: string;
emailVerified?: boolean;
serviceAccountName?: string;
Expand Down

0 comments on commit d41add4

Please sign in to comment.