#1148 - Fetch secret from cluster instead of cache on every api request - #1159
Open
kushnaidu wants to merge 2 commits into
Open
#1148 - Fetch secret from cluster instead of cache on every api request#1159kushnaidu wants to merge 2 commits into
kushnaidu wants to merge 2 commits into
Conversation
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
kushnaidu
requested review from
efiacor,
kispaljr,
liamfallon and
mozesl-nokia
as code owners
August 27, 2026 11:57
✅ Deploy Preview for kpt-porch ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates git repository authentication to always re-resolve credentials from the backing Kubernetes Secret for each git operation, ensuring Secret updates are picked up immediately across porch-server and porch-controller.
Changes:
- Removed indefinite in-memory credential caching in
gitRepository.getAuthMethod; credentials are now re-read on every call. - Simplified
doGitWithAuthby removing the inner “auth failed → force refresh → retry” logic. - Added unit tests covering “no secret”, “secret change is picked up”, resolver error propagation, and concurrent access behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/externalrepo/git/git.go | Always re-fetches credentials from the Secret per git operation and removes inner auth-refresh retry logic. |
| pkg/externalrepo/git/git_test.go | Adds focused tests validating the new credential re-resolution behavior and concurrency expectations. |
Suppressed comments (1)
pkg/externalrepo/git/git_test.go:2682
- Same as above: avoid a direct type assertion here so test failures are clearer and don’t panic if the auth method type changes.
basicAuth = auth.(*http.BasicAuth)
if basicAuth.Username != "user2" {
t.Fatalf("expected user2 after secret change, got %s", basicAuth.Username)
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
|
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.

Fetch secret from cluster instead of cache on every api request
Description
What changed:
getAuthMethod now re-reads the repository Secret from the Kubernetes API on every git operation instead of caching it indefinitely. The credential field, forceRefresh parameter, and inner auth-retry in doGitWithAuth were removed as they became redundant.
Why it’s needed:
Previously, when a user updated a repository Secret (e.g., switching from gitea_user1 to gitea_user2), neither porch-server nor porch-controller would pick up the change unless authentication failed first. If the old credentials still worked, the new ones were never used. For correctness and security, we need to always have the latest secret data.
How it works:
Each git operation calls ResolveCredential, which does a single client.Get on the Secret — a lightweight K8s API call (~5ms) that's negligible compared to the git network operation it precedes. The outer retry loops (fetchRemoteRepositoryWithRetry, pushAndCleanup) handle transient failures, and each retry gets fresh credentials automatically.
Related Issue(s)
Type of Change
Checklist
Testing Instructions (Optional)
Additional Notes (Optional)
AI Disclosure
Kiro