-
Notifications
You must be signed in to change notification settings - Fork 736
rpk: add OAUTHBEARER SASL mechanism support #30169
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a1a4bd2
rpk: add OAUTHBEARER SASL mechanism support
david-yu 4b3f789
rpk: add unit tests for OAUTHBEARER SASL support
david-yu 8d87e83
rpk: include PLAIN in profile doc mechanism list
david-yu 03d7388
rpk: update -X help text to list all SASL mechanisms
david-yu 2d5f797
rpk: add NewFranzClient SASL error path tests
david-yu d8ac846
rpk: add copyright headers to new test files
david-yu 319275c
Merge branch 'dev' into rpk-oauthbearer-support
david-yu bcf5806
ci: empty commit to retrigger build
david-yu eeab01c
Merge branch 'dev' into rpk-oauthbearer-support
david-yu 7dd8eb0
rpk: address OAUTHBEARER PR review feedback
david-yu 33b24f1
Merge branch 'dev' into rpk-oauthbearer-support
david-yu c4e9f70
rpk: reject OAUTHBEARER up front in remote debug bundle
david-yu f47f4c1
rpk: add OAUTHBEARER tests and ordering comment for SR client
david-yu 2fa9579
rpk: reference follow-up issue in remote debug bundle guard
david-yu 2e13ac5
Merge branch 'dev' into rpk-oauthbearer-support
david-yu 4dcd842
Merge branch 'dev' into rpk-oauthbearer-support
david-yu ce7880a
rpk: regenerate BUILD files for OAUTHBEARER test additions
david-yu 7a003d6
Merge branch 'dev' into rpk-oauthbearer-support
david-yu 9a73bbb
rpk: fix $HOME-unset failures in OAUTHBEARER tests
david-yu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| // Copyright 2026 Redpanda Data, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the file licenses/BSL.md | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0 | ||
|
|
||
| package adminapi | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/redpanda-data/common-go/rpadmin" | ||
| "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetAuth(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| profile *config.RpkProfile | ||
| wantTyp rpadmin.Auth | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "no SASL returns NopAuth", | ||
| profile: &config.RpkProfile{}, | ||
| wantTyp: &rpadmin.NopAuth{}, | ||
| }, | ||
| { | ||
| name: "SCRAM-SHA-256 returns BasicAuth", | ||
| profile: &config.RpkProfile{ | ||
| KafkaAPI: config.RpkKafkaAPI{ | ||
| SASL: &config.SASL{ | ||
| User: "admin", | ||
| Password: "secret", | ||
| Mechanism: "SCRAM-SHA-256", | ||
| }, | ||
| }, | ||
| }, | ||
| wantTyp: &rpadmin.BasicAuth{Username: "admin", Password: "secret"}, | ||
| }, | ||
| { | ||
| name: "OAUTHBEARER with token prefix returns BearerToken", | ||
| profile: &config.RpkProfile{ | ||
| KafkaAPI: config.RpkKafkaAPI{ | ||
| SASL: &config.SASL{ | ||
| Password: "token:my-jwt-token", | ||
| Mechanism: "OAUTHBEARER", | ||
| }, | ||
| }, | ||
| }, | ||
| wantTyp: &rpadmin.BearerToken{Token: "my-jwt-token"}, | ||
| }, | ||
| { | ||
| name: "OAUTHBEARER with raw token returns BearerToken", | ||
| profile: &config.RpkProfile{ | ||
| KafkaAPI: config.RpkKafkaAPI{ | ||
| SASL: &config.SASL{ | ||
| Password: "my-jwt-token", | ||
| Mechanism: "OAUTHBEARER", | ||
| }, | ||
| }, | ||
| }, | ||
| wantTyp: &rpadmin.BearerToken{Token: "my-jwt-token"}, | ||
| }, | ||
| { | ||
| name: "OAUTHBEARER case-insensitive", | ||
| profile: &config.RpkProfile{ | ||
| KafkaAPI: config.RpkKafkaAPI{ | ||
| SASL: &config.SASL{ | ||
| Password: "my-jwt-token", | ||
| Mechanism: "oauthbearer", | ||
| }, | ||
| }, | ||
| }, | ||
| wantTyp: &rpadmin.BearerToken{Token: "my-jwt-token"}, | ||
| }, | ||
| { | ||
| name: "OAUTHBEARER with empty password errors", | ||
| profile: &config.RpkProfile{ | ||
| KafkaAPI: config.RpkKafkaAPI{ | ||
| SASL: &config.SASL{ | ||
| Mechanism: "OAUTHBEARER", | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: "OAUTHBEARER requires a token", | ||
| }, | ||
| { | ||
| name: "OAUTHBEARER with token: prefix only errors", | ||
| profile: &config.RpkProfile{ | ||
| KafkaAPI: config.RpkKafkaAPI{ | ||
| SASL: &config.SASL{ | ||
| Password: "token:", | ||
| Mechanism: "OAUTHBEARER", | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: "OAUTHBEARER requires a token", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := GetAuth(tt.profile) | ||
| if tt.wantErr != "" { | ||
| require.ErrorContains(t, err, tt.wantErr) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| require.IsType(t, tt.wantTyp, got) | ||
| require.Equal(t, tt.wantTyp, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_oauthBearerToken(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| password string | ||
| want string | ||
| }{ | ||
| { | ||
| name: "token prefix stripped", | ||
| password: "token:eyJhbGciOiJSUzI1NiJ9.payload.sig", | ||
| want: "eyJhbGciOiJSUzI1NiJ9.payload.sig", | ||
| }, | ||
| { | ||
| name: "raw token returned as-is", | ||
| password: "eyJhbGciOiJSUzI1NiJ9.payload.sig", | ||
| want: "eyJhbGciOiJSUzI1NiJ9.payload.sig", | ||
| }, | ||
| { | ||
| name: "empty password returns empty", | ||
| password: "", | ||
| want: "", | ||
| }, | ||
| { | ||
| name: "token prefix only returns empty", | ||
| password: "token:", | ||
| want: "", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := oauthBearerToken(tt.password) | ||
| require.Equal(t, tt.want, got) | ||
| }) | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.