-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Changes for tctl sso test, tctl sso configure commands [OIDC]
#12519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a713d86
Changes for tctl sso test, tctl sso configure commands [OIDC]
Tener c5285f3
Lint.
Tener 0c94cac
Merge branch 'master' into tener/tctl-sso-oidc
Tener 9001753
Lint.
Tener 707c54e
Merge branch 'master' into tener/tctl-sso-oidc
Tener 0ad78e2
Add missing license.
Tener 6e4a7b4
Fix tests broken by stricter validation.
Tener 93b75c3
Prompt removal of temp OIDC client in test flow.
Tener 2940fd5
Add missing context param in tests.
Tener 063c7ae
Merge branch 'master' into tener/tctl-sso-oidc
Tener 8a10ab9
Update lib/auth/auth_with_roles_test.go
Tener f704c54
godoc
Tener 4619e01
Make getClaimsFun part of Server configuration.
Tener 8c46b21
Merge branch 'master' into tener/tctl-sso-oidc
Tener a0532e9
Eager initialization of getClaimsFun field.
Tener fe28ff8
Remove diagnostic code from tests.
Tener 82a229d
Merge branch 'master' into tener/tctl-sso-oidc
Tener 10ad06c
Merge branch 'master' into tener/tctl-sso-oidc
Tener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| Copyright 2022 Gravitational, Inc. | ||
|
|
||
| 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 types | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "time" | ||
|
|
||
| "github.com/gravitational/trace" | ||
| ) | ||
|
|
||
| // OIDCClaims is a redefinition of jose.Claims with additional methods, required for serialization to/from protobuf. | ||
| // With those we can reference it with an option like so: `(gogoproto.customtype) = "OIDCClaims"` | ||
| type OIDCClaims map[string]interface{} | ||
|
|
||
| // Size returns size of the object when marshaled | ||
| func (a *OIDCClaims) Size() int { | ||
| bytes, err := json.Marshal(a) | ||
| if err != nil { | ||
| return 0 | ||
| } | ||
| return len(bytes) | ||
| } | ||
|
|
||
| // Unmarshal the object from provided buffer. | ||
| func (a *OIDCClaims) Unmarshal(bytes []byte) error { | ||
| return trace.Wrap(json.Unmarshal(bytes, a)) | ||
| } | ||
|
|
||
| // MarshalTo marshals the object to sized buffer | ||
| func (a *OIDCClaims) MarshalTo(bytes []byte) (int, error) { | ||
| out, err := json.Marshal(a) | ||
| if err != nil { | ||
| return 0, trace.Wrap(err) | ||
| } | ||
|
|
||
| if len(out) > cap(bytes) { | ||
| return 0, trace.BadParameter("capacity too low: %v, need %v", cap(bytes), len(out)) | ||
| } | ||
|
|
||
| copy(bytes, out) | ||
|
|
||
| return len(out), nil | ||
| } | ||
|
|
||
| // OIDCIdentity is a redefinition of oidc.Identity with additional methods, required for serialization to/from protobuf. | ||
| // With those we can reference it with an option like so: `(gogoproto.customtype) = "OIDCIdentity"` | ||
| type OIDCIdentity struct { | ||
| // ID is populated from "subject" claim. | ||
| ID string | ||
| // Name of user. Empty in current version of library. | ||
| Name string | ||
| // Email is populated from "email" claim. | ||
| Email string | ||
| // ExpiresAt populated from "exp" claim, represents expiry time. | ||
| ExpiresAt time.Time | ||
| } | ||
|
|
||
| // Size returns size of the object when marshaled | ||
| func (a *OIDCIdentity) Size() int { | ||
| bytes, err := json.Marshal(a) | ||
| if err != nil { | ||
| return 0 | ||
| } | ||
| return len(bytes) | ||
| } | ||
|
|
||
| // Unmarshal the object from provided buffer. | ||
| func (a *OIDCIdentity) Unmarshal(bytes []byte) error { | ||
| return trace.Wrap(json.Unmarshal(bytes, a)) | ||
| } | ||
|
|
||
| // MarshalTo marshals the object to sized buffer | ||
| func (a *OIDCIdentity) MarshalTo(bytes []byte) (int, error) { | ||
| out, err := json.Marshal(a) | ||
| if err != nil { | ||
| return 0, trace.Wrap(err) | ||
| } | ||
|
|
||
| if len(out) > cap(bytes) { | ||
| return 0, trace.BadParameter("capacity too low: %v, need %v", cap(bytes), len(out)) | ||
| } | ||
|
|
||
| copy(bytes, out) | ||
|
|
||
| return len(out), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright 2022 Gravitational, Inc | ||
| // | ||
| // 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 types | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestOIDCClaimsRoundTrip(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| src OIDCClaims | ||
| }{ | ||
| { | ||
| name: "empty", | ||
| src: OIDCClaims{}, | ||
| }, | ||
| { | ||
| name: "full", | ||
| src: OIDCClaims(map[string]interface{}{ | ||
| "email_verified": true, | ||
| "groups": []interface{}{"everyone", "idp-admin", "idp-dev"}, | ||
| "email": "superuser@example.com", | ||
| "sub": "00001234abcd", | ||
| "exp": 1652091713.0, | ||
| }), | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| buf := make([]byte, tt.src.Size()) | ||
| count, err := tt.src.MarshalTo(buf) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.src.Size(), count) | ||
|
|
||
| dst := &OIDCClaims{} | ||
| err = dst.Unmarshal(buf) | ||
| require.NoError(t, err) | ||
| require.Equal(t, &tt.src, dst) | ||
| }) | ||
| } | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.