-
Notifications
You must be signed in to change notification settings - Fork 727
feat(scim): add GET /scim/v2/Users/{id} #2671
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
Open
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
915febd
feat(scim): store a per-provider SCIM token hash
xlgmokha 6df5a18
feat(scim): add GET /scim/v2/Users/{id}
xlgmokha b741d18
refactor(scim): delegate to current bearer token extractor
xlgmokha 05874da
refactor(scim): use existing context key
xlgmokha 3a868ca
refactor: convert ContextKey to generic lookup
xlgmokha caef6e8
refactor: rename self to match other declarations
xlgmokha 893274a
refactor: extract a provisioned user type
xlgmokha cad340a
refactor: delegate to srv.NotFound()
xlgmokha cffafd7
refactor: extract methods for loading a provisioned user
xlgmokha a850877
refactor: rename Email() to PrimaryEmail()
xlgmokha 03f4209
refactor: extract method Meta#As to attach timestamps
xlgmokha 3d861eb
refactor: rever to value type instead of pointer
xlgmokha 043fe88
refactor: extract method for sso provider key
xlgmokha fda4de5
refactor(scim): extract Resource interface
xlgmokha 3322570
test: fix incorrect assertion
xlgmokha cd67db1
test: extract scim_users_test.go
xlgmokha b2f16e3
test: generate n users for two different tenants in tests
xlgmokha 4a99624
test: update the claims to match an actual saml assertion
xlgmokha 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package scim | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
|
|
||
| "github.com/supabase/auth/internal/api/scim/protocol" | ||
| "github.com/supabase/auth/internal/api/shared" | ||
| "github.com/supabase/auth/internal/models" | ||
| "github.com/supabase/auth/internal/observability" | ||
| ) | ||
|
|
||
| func (srv *Server) Authenticate(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| ctx, ok := srv.authenticate(w, r) | ||
| if !ok { | ||
| return | ||
| } | ||
| next.ServeHTTP(w, r.WithContext(ctx)) | ||
| }) | ||
| } | ||
|
|
||
| func (srv *Server) authenticate(w http.ResponseWriter, r *http.Request) (context.Context, bool) { | ||
| ctx := r.Context() | ||
|
|
||
| token, err := srv.extract(r) | ||
| if err != nil { | ||
| unauthorized(w) | ||
| return nil, false | ||
| } | ||
|
|
||
| provider, err := models.FindSSOProviderBySCIMToken(srv.db.WithContext(ctx), token) | ||
| if err != nil { | ||
| if models.IsNotFoundError(err) { | ||
| unauthorized(w) | ||
| return nil, false | ||
| } | ||
| srv.internalError(w, r, err) | ||
| return nil, false | ||
| } | ||
|
|
||
| if !provider.IsEnabled() { | ||
| protocol.SendError(w, http.StatusForbidden, "", "SCIM is not available for this provider") | ||
| return nil, false | ||
| } | ||
|
|
||
| observability.LogEntrySetField(r, "sso_provider_id", provider.ID.String()) | ||
|
|
||
| return shared.WithSSOProvider(ctx, provider), true | ||
| } | ||
|
|
||
| func unauthorized(w http.ResponseWriter) error { | ||
| w.Header().Set("WWW-Authenticate", "Bearer") | ||
| return protocol.SendError(w, http.StatusUnauthorized, "", "A valid SCIM bearer token is required") | ||
| } | ||
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,29 @@ | ||
| package core | ||
|
|
||
| type AuthenticationSchemeType string | ||
|
|
||
| const ( | ||
| AuthenticationSchemeOAuthBearerToken AuthenticationSchemeType = "oauthbearertoken" | ||
| ) | ||
|
|
||
| type AuthenticationScheme struct { | ||
| Type AuthenticationSchemeType `json:"type"` | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
| SpecURI string `json:"specUri,omitempty"` | ||
| Primary bool `json:"primary"` | ||
| } | ||
|
|
||
| func NewOAuthBearerToken() *AuthenticationScheme { | ||
| return &AuthenticationScheme{ | ||
| Type: AuthenticationSchemeOAuthBearerToken, | ||
| Name: "OAuth Bearer Token", | ||
| Description: "Authentication scheme using the OAuth Bearer Token Standard", | ||
| SpecURI: "http://www.rfc-editor.org/info/rfc6750", | ||
| } | ||
| } | ||
|
|
||
| func (scheme *AuthenticationScheme) AsPrimary() *AuthenticationScheme { | ||
| scheme.Primary = true | ||
| return scheme | ||
| } |
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 was deleted.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package core | ||
|
|
||
| type SupportedFeature struct { | ||
| Supported bool `json:"supported"` | ||
| } | ||
|
|
||
| type BulkFeature struct { | ||
| Supported bool `json:"supported"` | ||
| MaxOperations int `json:"maxOperations"` | ||
| MaxPayloadSize int `json:"maxPayloadSize"` | ||
| } | ||
|
|
||
| type FilterFeature struct { | ||
| Supported bool `json:"supported"` | ||
| MaxResults int `json:"maxResults"` | ||
| } |
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 |
|---|---|---|
| @@ -1,14 +1,23 @@ | ||
| package core | ||
|
|
||
| // Meta is the resource metadata common attribute defined in RFC 7643, Section 3.1. | ||
| import "time" | ||
|
|
||
| type Meta struct { | ||
| ResourceType ResourceTypeName `json:"resourceType"` | ||
| Created time.Time `json:"created,omitzero"` | ||
| LastModified time.Time `json:"lastModified,omitzero"` | ||
| Location string `json:"location,omitempty"` | ||
| } | ||
|
|
||
| func NewMeta(baseURL string, resourceType ResourceTypeName, endpoint string) Meta { | ||
| return Meta{ | ||
| ResourceType: resourceType, | ||
| Location: baseURL + endpoint, | ||
| } | ||
| func NewMeta(baseURL string, resourceType ResourceType) Meta { | ||
| return resourceType.Meta(baseURL) | ||
| } | ||
|
|
||
| func (m Meta) For(r Resource) Meta { | ||
| created, updated := r.Timestamps() | ||
|
|
||
| m.Location += "/" + r.ResourceID() | ||
| m.Created, m.LastModified = created.UTC(), updated.UTC() | ||
|
|
||
| return m | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package core | ||
|
|
||
| import "time" | ||
|
|
||
| type Resource interface { | ||
| ResourceID() string | ||
| ResourceType() ResourceType | ||
| Timestamps() (created, updated time.Time) | ||
| } |
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,31 @@ | ||
| package core | ||
|
|
||
| var ( | ||
| ResourceTypeServiceProviderConfig = ResourceType{ | ||
| Name: "ServiceProviderConfig", | ||
| Endpoint: "/ServiceProviderConfig", | ||
| } | ||
|
|
||
| ResourceTypeUser = ResourceType{ | ||
| Name: "User", | ||
| Endpoint: "/Users", | ||
| } | ||
| ) | ||
|
|
||
| type ResourceTypeName string | ||
|
|
||
| type ResourceType struct { | ||
| Name ResourceTypeName | ||
| Endpoint string | ||
| } | ||
|
|
||
| func (r ResourceType) Meta(baseURL string) Meta { | ||
| return Meta{ | ||
| ResourceType: r.Name, | ||
| Location: r.Location(baseURL), | ||
| } | ||
| } | ||
|
|
||
| func (r ResourceType) Location(baseURL string) string { | ||
| return baseURL + r.Endpoint | ||
| } |
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,24 @@ | ||
| package core | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestResourceType(t *testing.T) { | ||
| r := ResourceType{Name: "Resource", Endpoint: "/Resources"} | ||
|
|
||
| t.Run("Meta", func(t *testing.T) { | ||
| baseURL := "http://localhost:9999/scim/v2" | ||
|
|
||
| t.Run("locates a resource that is its own endpoint", func(t *testing.T) { | ||
| meta := r.Meta(baseURL) | ||
|
|
||
| require.Equal(t, ResourceTypeName("Resource"), meta.ResourceType) | ||
| require.Equal(t, baseURL+"/Resources", meta.Location) | ||
| require.Zero(t, meta.Created) | ||
| require.Zero(t, meta.LastModified) | ||
| }) | ||
| }) | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Severity: LOW
The server returns HTTP 403 for a valid token whose provider is disabled, versus HTTP 401 for any unknown token. This status-code difference lets an attacker use a disabled SCIM provider as an oracle — submitting candidate tokens and distinguishing valid-but-forbidden ones (403) from invalid ones (401), effectively confirming token validity without gaining access.
Helpful? Add 👍 / 👎
💡 Fix Suggestion
Suggestion: Replace the HTTP 403 response for a disabled provider with the same
unauthorized(w)call (HTTP 401) used for unknown tokens. This eliminates the status-code oracle by returning a uniform 401 response whether the token is unrecognised or resolves to a disabled provider, so an attacker can no longer confirm token validity by observing the response code.