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

db: allow updates to self_managed_password #29283

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions builtin/logical/database/path_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,12 @@ func (b *databaseBackend) pathStaticRoleCreateUpdate(ctx context.Context, req *l
}

lastVaultRotation := role.StaticAccount.LastVaultRotation
updateAllowed := lastVaultRotation.IsZero()

if passwordRaw, ok := data.GetOk("password"); ok {
// We will allow users to update the password until the point where
// Vault assumes management of the account so that we don't break the
// promise of Vault being the source of truth.
updateAllowed := lastVaultRotation.IsZero()
if updateAllowed {
role.StaticAccount.Password = passwordRaw.(string)

Expand All @@ -663,21 +664,27 @@ func (b *databaseBackend) pathStaticRoleCreateUpdate(ctx context.Context, req *l
}

if connDetails != nil && connDetails.SelfManaged {
// Password and SelfManagedPassword should map to the same value
// SelfManagedPassword was deprecated in favor of Password, so they
// should map to the same value
role.StaticAccount.SelfManagedPassword = passwordRaw.(string)
}
} else {
return logical.ErrorResponse("%s: role=%s, lastVaultRotation=%s", errNoUpdateAfterRotation, name, lastVaultRotation), nil
}
}

if smPasswordRaw, ok := data.GetOk("self_managed_password"); ok && createRole {
if smPasswordRaw, ok := data.GetOk("self_managed_password"); ok {
if _, ok := data.GetOk("password"); ok {
return logical.ErrorResponse(errNoPasswordAndSelfManagedPassword), nil
}
// Password and SelfManagedPassword should map to the same value
role.StaticAccount.SelfManagedPassword = smPasswordRaw.(string)
role.StaticAccount.Password = smPasswordRaw.(string)
if updateAllowed {
// SelfManagedPassword was deprecated in favor of Password, so they
// should map to the same value
role.StaticAccount.SelfManagedPassword = smPasswordRaw.(string)
role.StaticAccount.Password = smPasswordRaw.(string)
} else {
return logical.ErrorResponse("%s: role=%s, lastVaultRotation=%s", errNoUpdateAfterRotation, name, lastVaultRotation), nil
}
}

if skipImportRotationRaw, ok := data.GetOk("skip_import_rotation"); ok {
Expand Down
Loading