-
Notifications
You must be signed in to change notification settings - Fork 13
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
ROX-23709: Refactor authentication handler #1789
Conversation
Skipping CI for Draft Pull Request. |
6be6984
to
47dc705
Compare
config/dataplane-oidc-issuers.yaml
Outdated
@@ -0,0 +1,4 @@ | |||
--- | |||
# A list of DataPlane OpenID Connect issuers that should be verified for issued tokens. | |||
# Endpoints must be given in the format https://<endpoint>/auth/realms/<your-realm> without trailing slash. |
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.
That format is explicit for keycloak, but not for other issuers. Just mention that you should provide the issuer as specificed in the tokens you are attempting to verify would be better IMO.
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.
You are right. Fixed.
pkg/client/iam/config.go
Outdated
} | ||
|
||
// AdditionalSSOIssuers ... | ||
type AdditionalSSOIssuers struct { | ||
// OIDCIssuers ... |
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.
Let's give this a proper comment.
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.
Done
pkg/client/iam/config.go
Outdated
@@ -190,7 +215,58 @@ func (a *AdditionalSSOIssuers) resolveURIs() error { | |||
return nil | |||
} | |||
|
|||
func getOpenIDConfiguration(c http.Client, baseURL string) (*openIDConfiguration, error) { | |||
func autoSenseHTTPClient(url string) (*http.Client, error) { |
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.
Let's just call it createHTTPClient
? Seems like an easier read.
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.
done
} | ||
// default client | ||
return &http.Client{ | ||
Timeout: time.Minute, |
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.
Do we have any proxy settings we have to respect for fleet manager?
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.
I'm not aware of any proxy settings.
func getOpenIDConfiguration(c http.Client, baseURL string) (*openIDConfiguration, error) { | ||
func autoSenseHTTPClient(url string) (*http.Client, error) { | ||
// Fleet Manager runs on the Data Plane cluster | ||
if url == kubernetesIssuer { |
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.
Is this a special case in local deployment/testing? Would be great to mention this explicitly, same applies for the isLocalCluster
case.
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.
Right, added clarifying comments.
if err != nil { | ||
return err | ||
} |
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.
What will happen if resolveURIs
/ ReadFiles
will err out - will we just log this or the process will exit? Just want to avoid being in a state where we only have a partial read of issuers.
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.
It should return error and the process should exit
pkg/client/iam/config.go
Outdated
func isLocalHost(host string) bool { | ||
if ip := net.ParseIP(host); ip != nil { | ||
return ip.IsLoopback() | ||
} | ||
return strings.ToLower(host) == "localhost" | ||
} |
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.
nit: we can use the stackrox netutil lib for that.
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.
Fixed. TBH I was "inspired" by it 😜
4451c39
to
14e2b6c
Compare
b838e27
to
9af3abd
Compare
9af3abd
to
62d0537
Compare
7c3d605
to
cdec282
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
cdec282
to
4834ca2
Compare
4834ca2
to
9353319
Compare
@@ -0,0 +1 @@ | |||
- https://127.0.0.1:6443 |
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.
Maybe as a sane default for dev clusters adding https://kubernetes.default.svc
would make sense as well - at the very least that's the issuer in "my" dev k8s cluster.
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.
The intention was to run Fleet Manager locally (not in container)
|
||
privateAPIHandlerBuilder := authentication.NewHandler(). | ||
Logger(authnLogger). | ||
KeysURL(IAMConfig.RedhatSSORealm.JwksEndpointURI). |
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.
Eventually we'd remove this one, as we don't expect sso tokens to be valid anymore for the private API? Any plans on that? Would make sense to leave a marker here just in case.
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.
Yes, I added an item to the checklist in the ticket.
) | ||
|
||
func (h *compositeAuthenticationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
if strings.HasPrefix(r.URL.Path, adminAPIPrefix) { |
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.
Shouldn't this be routes.AdminAPIPrefix
? Same applies below for the private API one.
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.
No, it should be the full path. adminAPIPrefix
contains routes.AdminAPIPrefix
KeysURL(IAMConfig.JwksURL). // ocm JWK JSON web token signing certificates URL | ||
KeysFile(IAMConfig.JwksFile). // ocm JWK backup JSON web token signing certificates |
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.
You haven't really added this, but: what's the issuer for those? It should be SSO tokens simply, so not sure where it's pointing to?
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.
I see the following reasons for having IAMConfig.JwksURL
and IAMConfig.JwksFile
- Use the mock authentication server in integration tests;
- Add an JWKS for the static token auth.
JwksURL: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/certs", | ||
JwksFile: "config/jwks-file.json", |
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.
Those should just be the RedHatSSORealm
's config, right? So why do we set this now here statically, when RedHatSSORealm
will resolve to this dynamically.
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.
See the comment above.
9353319
to
26b84f6
Compare
26b84f6
to
d0507ef
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dhaus67, kovayur The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description
This change splits the authentication handler into 3 parts, each dedicated to a different API: private, public, admin.
The goal is to limit the number of trusted issuers for a particular API.
Every part has its own
issuerURIs
which allows to limit the issuers for every API:private
handler represented by the newDataplaneOIDCIssuers
configuration parameter;admin
handler is configured with theInternalSSORealm
issuer uri.default
handler serves the rest (excl.InternalSSORealm
)JwksURL
andJwksFile
were moved to fromServerConfig
toIAMConfig
to avoid circular dependency between packages.Checklist (Definition of Done)
Test manual
ROX-12345: ...
Test manual
TODO: Add manual testing efforts