-
Notifications
You must be signed in to change notification settings - Fork 536
fix(controller): return error instead of panicking on unknown auth mode #1791
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ limitations under the License. | |
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/kagent-dev/kagent/go/core/internal/httpserver/auth" | ||
| "github.com/kagent-dev/kagent/go/core/pkg/app" | ||
| pkgauth "github.com/kagent-dev/kagent/go/core/pkg/auth" | ||
|
|
@@ -31,7 +33,10 @@ import ( | |
| func main() { | ||
| authorizer := &auth.NoopAuthorizer{} | ||
| app.Start(func(bootstrap app.BootstrapConfig) (*app.ExtensionConfig, error) { | ||
| authenticator := getAuthenticator(bootstrap.Config.Auth) | ||
| authenticator, err := getAuthenticator(bootstrap.Config.Auth) | ||
| if err != nil { | ||
| return nil, err | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, the defer-skip is real. practical flush impact at this specific call site is small (very few spans are buffered between tracing init and the suggested |
||
| } | ||
| return &app.ExtensionConfig{ | ||
| Authenticator: authenticator, | ||
| Authorizer: authorizer, | ||
|
|
@@ -41,13 +46,13 @@ func main() { | |
| }, nil) | ||
| } | ||
|
|
||
| func getAuthenticator(authCfg struct{ Mode, UserIDClaim string }) pkgauth.AuthProvider { | ||
| func getAuthenticator(authCfg struct{ Mode, UserIDClaim string }) (pkgauth.AuthProvider, error) { | ||
| switch authCfg.Mode { | ||
| case "trusted-proxy": | ||
| return auth.NewProxyAuthenticator(authCfg.UserIDClaim) | ||
| return auth.NewProxyAuthenticator(authCfg.UserIDClaim), nil | ||
| case "unsecure": | ||
| return &auth.UnsecureAuthenticator{} | ||
| return &auth.UnsecureAuthenticator{}, nil | ||
| default: | ||
| panic("unknown auth mode: " + authCfg.Mode + " (valid modes: unsecure, trusted-proxy)") | ||
| return nil, fmt.Errorf("unknown auth mode %q (valid modes: unsecure, trusted-proxy)", authCfg.Mode) | ||
| } | ||
| } | ||
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.
good catch. pushed
4431347fwhich asserts the error message includes both the invalid mode name and the list of supported modes, so a regression that drops either signal would fail the test now.