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

fix: rename token alias source to sa_uid #112

Merged
merged 3 commits into from Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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"
benashz marked this conversation as resolved.
Show resolved Hide resolved
aliasNameSourceSAPath = "serviceaccount_path"
benashz marked this conversation as resolved.
Show resolved Hide resolved
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, aliasNameSourceSAPath}
errInvalidAliasNameSource = fmt.Errorf(`invalid alias_name_source, must be one of: %s`, strings.Join(aliasNameSources, ", "))
)

Expand Down
2 changes: 1 addition & 1 deletion path_login.go
Expand Up @@ -156,7 +156,7 @@ 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
Expand Down
6 changes: 3 additions & 3 deletions path_login_test.go
Expand Up @@ -610,18 +610,18 @@ 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_path": {
role: "plugin-test",
jwt: jwtData,
config: &testBackendConfig{
Expand Down
2 changes: 1 addition & 1 deletion path_role.go
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, aliasNameSourceSAPath, aliasNameSourceDefault),
Default: aliasNameSourceDefault,
},
"policies": {
Expand Down
2 changes: 1 addition & 1 deletion path_role_test.go
Expand Up @@ -73,7 +73,7 @@ func TestPath_Create(t *testing.T) {
AliasNameSource: aliasNameSourceDefault,
},
},
"alias_name_source_sa_path": {
"alias_name_source_serviceaccount_path": {
data: map[string]interface{}{
"bound_service_account_names": "name",
"bound_service_account_namespaces": "namespace",
Expand Down