Skip to content
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

Merged
merged 3 commits into from
May 22, 2024

Conversation

kovayur
Copy link
Contributor

@kovayur kovayur commented May 6, 2024

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 new DataplaneOIDCIssuers configuration parameter;
  • admin handler is configured with the InternalSSORealm issuer uri.
  • default handler serves the rest (excl. InternalSSORealm)

JwksURL and JwksFile were moved to from ServerConfig to IAMConfig to avoid circular dependency between packages.

Checklist (Definition of Done)

  • Unit and integration tests added
  • Added test description under Test manual
  • Documentation added if necessary (i.e. changes to dev setup, test execution, ...)
  • CI and all relevant tests are passing
  • Add the ticket number to the PR title if available, i.e. ROX-12345: ...
  • Discussed security and business related topics privately. Will move any security and business related topics that arise to private communication channel.
  • Add secret to app-interface Vault or Secrets Manager if necessary
  • RDS changes were e2e tested manually
  • Check AWS limits are reasonable for changes provisioning new resources
  • (If applicable) Changes to the dp-terraform Helm values have been reflected in the addon on integration environment

Test manual

TODO: Add manual testing efforts

# To run tests locally run:
make db/teardown db/setup db/migrate
make ocm/setup
make verify lint binary test test/integration

@kovayur kovayur requested a review from dhaus67 May 6, 2024 16:44
Copy link
Contributor

openshift-ci bot commented May 6, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@@ -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.
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Fixed.

}

// AdditionalSSOIssuers ...
type AdditionalSSOIssuers struct {
// OIDCIssuers ...
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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) {
Copy link

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.

Copy link
Contributor Author

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,
Copy link

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?

Copy link
Contributor Author

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 {
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, added clarifying comments.

Comment on lines +202 to +208
if err != nil {
return err
}
Copy link

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.

Copy link
Contributor Author

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

Comment on lines 262 to 264
func isLocalHost(host string) bool {
if ip := net.ParseIP(host); ip != nil {
return ip.IsLoopback()
}
return strings.ToLower(host) == "localhost"
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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 😜

@kovayur kovayur force-pushed the yury/ROX-23709-fleetshard-auth branch from 4451c39 to 14e2b6c Compare May 7, 2024 12:20
@kovayur kovayur marked this pull request as ready for review May 7, 2024 18:56
@kovayur kovayur force-pushed the yury/ROX-23709-fleetshard-auth branch from b838e27 to 9af3abd Compare May 8, 2024 14:50
@kovayur kovayur force-pushed the yury/ROX-23709-fleetshard-auth branch from 9af3abd to 62d0537 Compare May 8, 2024 14:51
@kovayur kovayur force-pushed the yury/ROX-23709-fleetshard-auth branch from 7c3d605 to cdec282 Compare May 10, 2024 19:17
@kovayur
Copy link
Contributor Author

kovayur commented May 10, 2024

@@ -0,0 +1 @@
- https://127.0.0.1:6443
Copy link

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.

Copy link
Contributor Author

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).
Copy link

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.

Copy link
Contributor Author

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) {
Copy link

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.

Copy link
Contributor Author

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

Comment on lines +90 to +91
KeysURL(IAMConfig.JwksURL). // ocm JWK JSON web token signing certificates URL
KeysFile(IAMConfig.JwksFile). // ocm JWK backup JSON web token signing certificates
Copy link

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?

Copy link
Contributor Author

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

  1. Use the mock authentication server in integration tests;
  2. Add an JWKS for the static token auth.

Comment on lines +109 to +110
JwksURL: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/certs",
JwksFile: "config/jwks-file.json",
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment above.

@kovayur kovayur force-pushed the yury/ROX-23709-fleetshard-auth branch from 26b84f6 to d0507ef Compare May 21, 2024 12:48
@kovayur kovayur requested a review from dhaus67 May 21, 2024 16:17
Copy link
Contributor

openshift-ci bot commented May 22, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kovayur kovayur merged commit cdc535a into main May 22, 2024
7 checks passed
@kovayur kovayur deleted the yury/ROX-23709-fleetshard-auth branch May 22, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants