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

Role option to set alias name to Service Account's "namespace/name" instead of uid #103

Closed
wants to merge 7 commits into from
Closed
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
7 changes: 6 additions & 1 deletion path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ func (b *kubeAuthBackend) pathLogin(ctx context.Context, req *logical.Request, d
return nil, logical.ErrPermissionDenied
}

var name = serviceAccount.uid()
if role.HumanReadableAlias {
name = fmt.Sprintf("%s/%s", serviceAccount.namespace(), serviceAccount.name())
}

auth := &logical.Auth{
Alias: &logical.Alias{
Name: serviceAccount.uid(),
Name: name,
Metadata: map[string]string{
"service_account_uid": serviceAccount.uid(),
"service_account_name": serviceAccount.name(),
Expand Down
13 changes: 13 additions & 0 deletions path_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ are allowed.`,
Type: framework.TypeString,
Description: "Optional Audience claim to verify in the jwt.",
},
"human_readable_alias": {
Type: framework.TypeBool,
Description: `Use "Kubernete's Namespace/Service Account Name" instead of the UID for the alias name.`,
},
"policies": {
Type: framework.TypeCommaStringSlice,
Description: tokenutil.DeprecationText("token_policies"),
Expand Down Expand Up @@ -152,6 +156,8 @@ func (b *kubeAuthBackend) pathRoleRead(ctx context.Context, req *logical.Request
d["audience"] = role.Audience
}

d["human_readable_alias"] = role.HumanReadableAlias

role.PopulateTokenData(d)

if len(role.Policies) > 0 {
Expand Down Expand Up @@ -302,6 +308,10 @@ func (b *kubeAuthBackend) pathRoleCreateUpdate(ctx context.Context, req *logical
role.Audience = audience.(string)
}

if humanReadableAlias, ok := data.GetOk("human_readable_alias"); ok {
role.HumanReadableAlias = humanReadableAlias.(bool)
}

// Store the entry.
entry, err := logical.StorageEntryJSON("role/"+strings.ToLower(roleName), role)
if err != nil {
Expand Down Expand Up @@ -332,6 +342,9 @@ type roleStorageEntry struct {
// Audience is an optional jwt claim to verify
Audience string `json:"audience" mapstructure:"audience" structs: "audience"`

// use the service accounts 'namespace/name' instead of uid for the alias name
HumanReadableAlias bool `json:"human_readable_alias" mapstructure:"human_readable_alias" structs:"human_readable_alias"`

// Deprecated by TokenParams
Policies []string `json:"policies" structs:"policies" mapstructure:"policies"`
NumUses int `json:"num_uses" mapstructure:"num_uses" structs:"num_uses"`
Expand Down