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

Backport PR #112 to 1.9.x #113

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const (

// aliasNameSourceUnset provides backwards compatibility with preexisting roles.
aliasNameSourceUnset = ""
aliasNameSourceSAToken = "sa_token"
aliasNameSourceSAPath = "sa_path"
aliasNameSourceDefault = aliasNameSourceSAToken
aliasNameSourceSAUid = "serviceaccount_uid"
aliasNameSourceSAName = "serviceaccount_name"
aliasNameSourceDefault = aliasNameSourceSAUid
)

var (
// when adding new alias name sources make sure to update the corresponding FieldSchema description in path_role.go
aliasNameSources = []string{aliasNameSourceSAToken, aliasNameSourceSAPath}
aliasNameSources = []string{aliasNameSourceSAUid, aliasNameSourceSAName}
errInvalidAliasNameSource = fmt.Errorf(`invalid alias_name_source, must be one of: %s`, strings.Join(aliasNameSources, ", "))
)

Expand Down
4 changes: 2 additions & 2 deletions path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func (b *kubeAuthBackend) getFieldValueStr(data *framework.FieldData, param stri

func (b *kubeAuthBackend) getAliasName(role *roleStorageEntry, serviceAccount *serviceAccount) (string, error) {
switch role.AliasNameSource {
case aliasNameSourceSAToken, aliasNameSourceUnset:
case aliasNameSourceSAUid, aliasNameSourceUnset:
uid, err := serviceAccount.uid()
if err != nil {
return "", err
}
return uid, nil
case aliasNameSourceSAPath:
case aliasNameSourceSAName:
return fmt.Sprintf("%s/%s", serviceAccount.Namespace, serviceAccount.Name), nil
default:
return "", fmt.Errorf("unknown alias_name_source %q", role.AliasNameSource)
Expand Down
8 changes: 4 additions & 4 deletions path_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,25 +610,25 @@ func TestAliasLookAhead(t *testing.T) {
config: defaultTestBackendConfig(),
wantErr: errors.New("missing jwt"),
},
"sa_token": {
"serviceaccount_uid": {
role: "plugin-test",
jwt: jwtData,
config: &testBackendConfig{
pems: testDefaultPEMs,
saName: testName,
saNamespace: testNamespace,
aliasNameSource: aliasNameSourceSAToken,
aliasNameSource: aliasNameSourceSAUid,
},
expectedAliasName: testUID,
},
"sa_path": {
"serviceaccount_name": {
role: "plugin-test",
jwt: jwtData,
config: &testBackendConfig{
pems: testDefaultPEMs,
saName: testName,
saNamespace: testNamespace,
aliasNameSource: aliasNameSourceSAPath,
aliasNameSource: aliasNameSourceSAName,
},
expectedAliasName: fmt.Sprintf("%s/%s", testNamespace, testName),
},
Expand Down
2 changes: 1 addition & 1 deletion path_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ valid choices:
%q : <token.uid> e.g. 474b11b5-0f20-4f9d-8ca5-65715ab325e0 (most secure choice)
%q : <namespace>/<serviceaccount> e.g. vault/vault-agent
default: %q
`, aliasNameSourceSAToken, aliasNameSourceSAPath, aliasNameSourceDefault),
`, aliasNameSourceSAUid, aliasNameSourceSAName, aliasNameSourceDefault),
Default: aliasNameSourceDefault,
},
"policies": {
Expand Down
6 changes: 3 additions & 3 deletions path_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestPath_Create(t *testing.T) {
AliasNameSource: aliasNameSourceDefault,
},
},
"alias_name_source_sa_path": {
"alias_name_source_serviceaccount_name": {
data: map[string]interface{}{
"bound_service_account_names": "name",
"bound_service_account_namespaces": "namespace",
Expand All @@ -82,7 +82,7 @@ func TestPath_Create(t *testing.T) {
"ttl": "1s",
"num_uses": 12,
"max_ttl": "5s",
"alias_name_source": aliasNameSourceSAPath,
"alias_name_source": aliasNameSourceSAName,
},
expected: &roleStorageEntry{
TokenParams: tokenutil.TokenParams{
Expand All @@ -101,7 +101,7 @@ func TestPath_Create(t *testing.T) {
MaxTTL: 5 * time.Second,
NumUses: 12,
BoundCIDRs: nil,
AliasNameSource: aliasNameSourceSAPath,
AliasNameSource: aliasNameSourceSAName,
},
},
"invalid_alias_name_source": {
Expand Down