-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Update DB Static role rotation logic to generate new password if retried password fails #28989
Open
vinay-gopalan
wants to merge
3
commits into
main
Choose a base branch
from
VAULT-28992/oracle-static-rotation-failures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -421,6 +421,7 @@ func (b *databaseBackend) setStaticAccount(ctx context.Context, s logical.Storag | |
// Use credential from input if available. This happens if we're restoring from | ||
// a WAL item or processing the rotation queue with an item that has a WAL | ||
// associated with it | ||
var usedExistingCredential bool | ||
if output.WALID != "" { | ||
wal, err := b.findStaticWAL(ctx, s, output.WALID) | ||
if err != nil { | ||
|
@@ -448,6 +449,7 @@ func (b *databaseBackend) setStaticAccount(ctx context.Context, s logical.Storag | |
Statements: statements, | ||
} | ||
input.Role.StaticAccount.Password = wal.NewPassword | ||
usedExistingCredential = true | ||
case wal.CredentialType == v5.CredentialTypeRSAPrivateKey: | ||
// Roll forward by using the credential in the existing WAL entry | ||
updateReq.CredentialType = v5.CredentialTypeRSAPrivateKey | ||
|
@@ -456,6 +458,7 @@ func (b *databaseBackend) setStaticAccount(ctx context.Context, s logical.Storag | |
Statements: statements, | ||
} | ||
input.Role.StaticAccount.PrivateKey = wal.NewPrivateKey | ||
usedExistingCredential = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also generate a new Private Key credential if one fails? Or should the fix be focussed to password specific? |
||
} | ||
} | ||
|
||
|
@@ -530,6 +533,16 @@ func (b *databaseBackend) setStaticAccount(ctx context.Context, s logical.Storag | |
_, err = dbi.database.UpdateUser(ctx, updateReq, false) | ||
if err != nil { | ||
b.CloseIfShutdown(dbi, err) | ||
if usedExistingCredential { | ||
// A retried password has failed again. Delete WAL and try with fresh password | ||
b.Logger().Debug("credential stored in WAL failed, deleting WAL", "role", input.RoleName, "WAL ID", output.WALID) | ||
if err := framework.DeleteWAL(ctx, s, output.WALID); err != nil { | ||
b.Logger().Warn("failed to delete WAL", "error", err, "WAL ID", output.WALID) | ||
} | ||
|
||
// Generate a new WAL entry and credential for next attempt | ||
output.WALID = "" | ||
} | ||
return output, fmt.Errorf("error setting credentials: %w", err) | ||
} | ||
modified = true | ||
|
This file contains 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,3 @@ | ||
```release-note:bug | ||
secret/db: Update static role rotation to generate new password if retried password fails. | ||
``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love when new tests appear =)