feat(expressions): add repoCredentials() expression function - #6558
Draft
jsbroks wants to merge 2 commits into
Draft
feat(expressions): add repoCredentials() expression function#6558jsbroks wants to merge 2 commits into
jsbroks wants to merge 2 commits into
Conversation
✅ Deploy Preview for docs-kargo-io ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6558 +/- ##
==========================================
+ Coverage 58.68% 58.81% +0.12%
==========================================
Files 506 506
Lines 42846 42985 +139
==========================================
+ Hits 25146 25280 +134
- Misses 16157 16166 +9
+ Partials 1543 1539 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
krancour
reviewed
Jul 6, 2026
krancour
reviewed
Jul 6, 2026
Add a `repoCredentials()` expression function that resolves repository credentials by repo URL and credential type (`git`, `helm`, `image`) through the same credentials database used by built-in promotion steps. Unlike `secret()`, which returns the raw `Data` of a Secret selected by name, `repoCredentials()` returns the *resolved* credentials -- e.g. a minted, short-lived GitHub App installation token -- so custom and generic steps (such as `http`) can obtain usable credentials for repositories they need to access, instead of only the raw material stored in the Secret. The function is wired into the promotion StepEvaluator, which now carries the credentials database. When credentials are found it always returns a fixed, predictable set of keys (`username`, `password`, `sshPrivateKey`); when none are found it returns an empty map, mirroring `secret()`. Contexts that do not wire a credentials database (Stage verification argument evaluation, the Argo CD selector, and the indexer) register the function but return a clear error if it is invoked. Signed-off-by: Justin Brooks <justin.brooks@akuity.io> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Justin Brooks <justin.brooks@akuity.io>
…conciler Signed-off-by: Justin Brooks <justin.brooks@akuity.io>
jsbroks
force-pushed
the
feat/repo-credentials-expr-fn
branch
from
July 9, 2026 13:39
6303c0a to
6ecfff2
Compare
krancour
reviewed
Jul 27, 2026
Comment on lines
+500
to
+501
| If no matching credentials are found, an object with all fields empty is | ||
| returned. |
Member
There was a problem hiding this comment.
This might not be the optimal behavior. It's common to use optional chaining and nil-coalescing in expressions, so returning nil is probably a more useful signal when no credentials are found.
krancour
reviewed
Jul 27, 2026
| // authors can rely on a predictable shape regardless of credential type | ||
| // or provider. When no credentials are found, a zero-value struct (all | ||
| // fields empty) is returned. | ||
| var result credentials.Credentials |
Member
There was a problem hiding this comment.
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.
Description
Closes #6549
Adds a
repoCredentials()expression function that resolves repository credentials by repo URL and credential type (git,helm,image), returning them as amap[string]string. It is a thin entry point into the same credentials database used by built-in promotion steps likegit-clone.Unlike
secret(), which returns the rawDataof aSecretselected by name,repoCredentials()returns the resolved credentials — not the raw contents of the underlyingSecret. This means it transparently handles credential schemes that yield narrowly-scoped, short-lived credentials (e.g. a GitHub App installation token minted from an app ID + private key, or a cloud provider's ambient / Pod-identity credentials), which is exactly what custom and generic steps (e.g.httpcalling a provider API) need but previously had no way to obtain.Behavior
repoCredentials(repoURL, type)wheretypeis one ofgit,helm, orimage. The type is required because credentials are indexed bytype and the same URL may resolve differently per type (URL normalization also
differs per type).
username,password,sshPrivateKey(empty string when unset), soexpression authors can rely on a predictable shape regardless of provider.
API keys / personal access tokens / minted tokens are surfaced via
password.secret()).Implementation
RepoCredentials()option andgetRepoCredentials()implementation inpkg/expressions/function, wired intoDataOperations()(which now takes acredentials.Database).StepEvaluatornow carries the credentials database and threads it throughVars/ShouldSkip/Config;LocalOrchestratorpasses the DB it alreadyreceives.
secret()(per-step cache, distinctRepoCredentialskey prefix).
Reviewer notes
evaluation, the Argo CD selector, and the indexer — register the function but
return a clear "not available in this context" error if it is invoked. Fully
wiring a credentials DB into the Stage controller was intentionally left out to
limit blast radius; happy to follow up if we want it there too.
discussion on expression function for repo credential lookup by url #6549). This PR wires the function into the OSS
StepEvaluatorconfig-evaluation path; the Enterprise pod-based executor's config-evaluation
path should be confirmed to flow through the same wiring.
(possibly minted) token into the expression environment, that token can flow
into a step's
outputs, logs, or committed files. Worth deciding whether anyguardrails are wanted here.
Checklist
Eligibility
Quality
AI Use Disclosure
This PR was written:
Sign-Off
All commits:
git commit -s) (required)git commit -S) (encouraged)