-
Notifications
You must be signed in to change notification settings - Fork 47
Determine authentication host based on WWW-Authenticate header #5502
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
Conversation
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.
Hello @evankanderson, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on improving the authentication process for the Minder CLI by enabling the determination of the authentication host based on the WWW-Authenticate
header. This eliminates the need to explicitly set the identity
parameters on the client side. The changes include modifications to the CLI commands to leverage the gRPC configuration, fetching the realm URL dynamically, and adjusting the server-side interceptor to provide the WWW-Authenticate
header. Additionally, a fix is included to address a regression introduced by a previous PR that broke minder auth login
for the default configuration.
Highlights
- Dynamic Authentication Host Determination: The CLI now determines the authentication host based on the
WWW-Authenticate
header, simplifying the configuration process. - gRPC Configuration Integration: The CLI commands now utilize the gRPC configuration for establishing connections and retrieving tokens.
- Server-Side Interceptor Enhancement: The server-side interceptor now provides a
WWW-Authenticate
header hint for authentication, improving the client's ability to discover the authentication realm. - Bug Fix: Addresses a regression introduced by Remove hard-coded 'stacklok' realm from minder #5478 that broke
minder auth login
for the default configuration.
Changelog
Click here to see the changelog
- cmd/cli/app/auth/auth_token.go
- Modified the
TokenCommand
function to use the gRPC configuration for getting the gRPC address and transport credentials. - Replaced direct usage of
issuerUrl
,realm
, andclientId
with gRPC configuration-based retrieval.
- Modified the
- cmd/cli/app/auth/offline_token/offline_use.go
- Modified the
offlineUseCommand
function to fetch the realm URL dynamically usingGetRealmUrl
. - Updated the
RefreshCredentials
call to use the fetched realm URL instead of the issuer URL and realm.
- Modified the
- cmd/cli/app/root.go
- Added
config.SetViperStructDefaults
to set default values for the client configuration.
- Added
- internal/controlplane/handlers_token.go
- Modified
TokenValidationInterceptor
to be a method on theServer
struct. - Added logic to send a
WWW-Authenticate
header in case of an unauthenticated request, providing the realm URL and scope. - The interceptor now sends the
WWW-Authenticate
header to help clients discover the authentication realm.
- Modified
- internal/controlplane/server.go
- Updated the gRPC server to use
s.TokenValidationInterceptor
instead of the standaloneTokenValidationInterceptor
function.
- Updated the gRPC server to use
- internal/util/cli/credentials.go
- Removed unused
tls
import. - Modified
GetGrpcConnection
to acceptGRPCClientConfig
instead of individual host, port, and insecure parameters. - Modified
GetToken
to accept the server address and gRPC dial options. - Added
GetRealmUrl
function to retrieve the realm URL from the server'sWWW-Authenticate
header or fall back to static configuration. - Modified
RefreshCredentials
to accept the realm URL instead of the issuer URL and realm. - Added
extractWWWAuthenticateRealm
function to parse theWWW-Authenticate
header and extract the realm. - The
GetToken
function now usesGetRealmUrl
to dynamically determine the realm URL.
- Removed unused
- internal/util/cli/credentials_test.go
- Modified
TestGetGrpcConnection
to useGRPCClientConfig
. - Modified
TestRefreshCredentials
to pass only the issuer URL instead of issuer URL and realm.
- Modified
- internal/util/cli/rpc_client.go
- Modified
GrpcForCommand
to useGRPCClientConfig
inGetGrpcConnection
. - Modified
EnsureCredentials
to useGRPCClientConfig
inGetToken
. - Modified
Login
to useGRPCClientConfig
andGetRealmUrl
.
- Modified
- pkg/config/client/config.go
- Moved
GRPCClientConfig
frompkg/config/common.go
topkg/config/client/config.go
. - Added
RegisterGRPCClientConfigFlags
to register the gRPC client configuration flags. - Added
GetGRPCAddress
andTransportCredentialsOption
methods toGRPCClientConfig
. - The
GRPCClientConfig
struct and related functions have been moved and refactored.
- Moved
- pkg/config/common.go
- Removed
GRPCClientConfig
andRegisterGRPCClientConfigFlags
.
- Removed
- pkg/config/server/identity.go
- Added
Scope
field toIdentityConfig
. - Added
GetRealmURL
method toIdentityConfig
.
- Added
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
In realms of code, where tokens roam,
Authentication's the key to home.
A header whispers, a realm's address,
No more hardcoding, less of a mess.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a significant improvement by dynamically determining the authentication host based on the WWW-Authenticate
header. The changes aim to simplify client-side configuration and enhance the overall user experience. The code is generally well-structured, but there are a few areas that could benefit from further attention.
Summary of Findings
- Missing error check: In
internal/util/cli/credentials.go
, theconn.Close()
call inGetRealmUrl
is deferred but the error is not checked. It's good practice to handle potential errors when closing resources. - Potential nil pointer dereference: In
internal/util/cli/rpc_client.go
, the code readsclientConfig.GRPCClientConfig.Host
andclientConfig.GRPCClientConfig.Port
before checking ifclientConfig
is nil. This could lead to a nil pointer dereference if the config fails to load. - Mixed error handling: In
internal/util/cli/rpc_client.go
, theLogin
function returns aloginError
type in some cases and a generic error in others. This could make error handling on the client side more complex. - TODO comment: In
internal/util/cli/rpc_client.go
, there's a TODO comment about getting scopes fromWWW-Authenticate
rather than hardcoding them. This is a good area for future improvement.
Merge Readiness
While the changes in this pull request offer valuable enhancements, there are a few issues that should be addressed before merging. Specifically, the missing error check and potential nil pointer dereference should be resolved to ensure code stability. The mixed error handling in the Login
function could also be improved for better client-side error management. I am unable to approve this pull request, and recommend that it not be merged until those issues are addressed (at a minimum), and that others review and approve this code before merging.
e6ad94c
to
4c78cb9
Compare
Let me know if you'd like me to break out the config changes from the other changes... I sort of ended up refactoring a bunch of stuff that had felt awkward, but I can see that it makes a large total set of things to keep in your head. |
/gemini review |
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.
Code Review
This pull request introduces a significant feature by enabling the determination of the authentication host based on the WWW-Authenticate header. This eliminates the need for client-side identity parameters and simplifies the configuration process. The changes are well-structured and include manual testing and a fix for a previously introduced bug. However, there are some areas where the code could be improved, particularly in error handling and code clarity.
Summary of Findings
- Error handling in GetRealmUrl: The GetRealmUrl function attempts to fetch the realm URL from the server headers but falls back to static configuration if that fails. The error handling in the initial connection attempt could be improved to provide more informative error messages or logging.
- TODO comment in GetToken: The GetToken function contains a TODO comment indicating that rp.NewRelyingPartyOIDC from zitadel should be used rather than making its own URL. Implementing this would improve the code's maintainability and potentially its security.
- Inconsistent error handling: There are inconsistencies in how errors are handled and propagated throughout the codebase. Some functions return errors directly, while others use cli.MessageAndError, which can make it harder to track the original error.
Merge Readiness
The pull request is not yet ready for merging. While the core functionality appears to be working correctly, the identified issues related to error handling and code clarity should be addressed to ensure the code's long-term maintainability and robustness. I am unable to approve this pull request, and recommend that the author address the issues surfaced in the review comments before merging. It's also recommended that other reviewers take a look at this code before merging.
-
Error handling in GetRealmUrl: we do not want to alarm users when operating with a normal fallback, so additional errors or logging is not appropriate.
-
TODO comment in GetToken: I left the TODO to make it findable in the future, but this PR is big enough as-is.
-
Inconsistent error handling: this is probably a fair complaint, but I don't think I've made things substantially worse, and using cli.MessageAndError is probably appropriate in many of the places it is used.
Summary
With these changes, I no longer need to set the client-side
identity
parameters, and I can call Minder as:And it will log in with the local keycloak instance. For other production instances, it should be possible to simply use
--grpc-host
to select them, and not need to explicitly know about their Keycloak configuration. (And, at some point, it could be non-keycloak...)On the server side, this requires something like the following
identity
configuration:Change Type
Mark the type of change your PR introduces:
Testing
Manual testing with a number of different configurations. Along the way, I discovered that #5478 actually broke
minder auth login
for Stacklok / the default configuration, because we weren't setting themapstructure
defaults on the client, only on the server. (There's a fix in here for that).Review Checklist: