feat(credentials): add in-place credential rotation via upsert#2919
Merged
migmartri merged 4 commits intoMar 22, 2026
Merged
Conversation
Introduces WithSecretName functional option to SaveCredentials, allowing callers to provide an existing secret path for in-place upsert instead of always generating a new UUID-based path. Updates CAS backend Update() to pass the existing secret name on rotation, eliminating orphaned credentials in all supported secret managers (Vault, AWS, GCP, Azure Key Vault). Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
There was a problem hiding this comment.
2 issues found across 14 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="pkg/credentials/credentials.go">
<violation number="1" location="pkg/credentials/credentials.go:57">
P2: Guard against nil `SaveOption` entries before invoking them to avoid a runtime panic.</violation>
</file>
<file name="app/controlplane/pkg/biz/casbackend_test.go">
<violation number="1" location="app/controlplane/pkg/biz/casbackend_test.go:348">
P2: The empty-secret test case can miss regressions because it asserts an empty captured secret value instead of asserting that no `SaveOption` argument was passed.
(Based on your team's feedback about updating tests for new paths.) [FEEDBACK_USED]</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Change ApplySaveOptions signature from slice to variadic for idiomatic Go - Replace TOCTOU GetSecret→CreateSecret upsert in GCP with a single CreateSecret that tolerates AlreadyExists, eliminating the race condition - Add isAlreadyExistsErr helper alongside the removed isNotFoundErr - Update all call sites and tests accordingly Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="pkg/credentials/gcp/secretmanager.go">
<violation number="1" location="pkg/credentials/gcp/secretmanager.go:118">
P1: Upsert now always calls `CreateSecret`, which adds an unnecessary IAM requirement (`secretmanager.secrets.create`) for rotating existing secrets and can cause `PermissionDenied` in previously working setups.
(Based on your team's feedback about cross-component and version compatibility.) [FEEDBACK_USED]</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…ation test The SaveCredentials integration test expectation was registered with only 3 args. After the upsert change, Update() passes WithSecretName as a 4th variadic arg, causing the mock not to match. Add mock.Anything to cover the opts argument. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
migmartri
commented
Mar 22, 2026
- Rename WithSecretName to WithExistingSecret for clarity - Add nil guard in ApplySaveOptions to prevent runtime panic - GCP upsert: try AddSecretVersion first to avoid requiring secretmanager.secrets.create permission for existing secrets - Improve test assertion for empty-secret case to check opt presence - Add mockery v3 config for credentials package Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
There was a problem hiding this comment.
2 issues found across 11 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="pkg/credentials/azurekv/keyvault.go">
<violation number="1" location="pkg/credentials/azurekv/keyvault.go:123">
P3: The comment references `WithExistingSecret`, but the option introduced/used by this API is `WithSecretName`. Rename it to keep API naming and docs consistent.
(Based on your team's feedback about naming consistent, domain-specific API terms.) [FEEDBACK_USED]</violation>
</file>
<file name="pkg/credentials/gcp/secretmanager.go">
<violation number="1" location="pkg/credentials/gcp/secretmanager.go:130">
P2: The create-after-NotFound upsert path does not tolerate `AlreadyExists`, so concurrent rotations can fail spuriously instead of proceeding to add a new version.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
WithSecretNamefunctional option toSaveCredentialsacross all credential backends (Vault, AWS Secrets Manager, GCP Secret Manager, Azure Key Vault), enabling upsert at a known path instead of always generating a new UUID-based pathCASBackendUseCase.Update()to pass the existingSecretNamewhen rotating credentials, so rotations overwrite in-place and stop creating orphaned secret entriesPutSecretValueto the AWSSecretsManagerIfacewith fallback toCreateSecreton not-found, andGetSecret-based existence check for GCP before adding a new secret versionWriter/ReaderWritermocks to handle the variadicopts ...SaveOptionparameter; adds table-driven upsert tests for all four backends and acasbackendrotation test verifyingWithSecretNameis forwardedcloses #2918