fix(cli): preserve password-only secret in flux create source git#5861
Open
SAY-5 wants to merge 1 commit intofluxcd:mainfrom
Open
fix(cli): preserve password-only secret in flux create source git#5861SAY-5 wants to merge 1 commit intofluxcd:mainfrom
flux create source git#5861SAY-5 wants to merge 1 commit intofluxcd:mainfrom
Conversation
`sourcesecret.buildGitSecret` previously wrote the Username and Password secret fields only when *both* were set. With the Azure DevOps PAT flow, `flux create source git --password=<pat>` has no username (the token is the credential), so both fields were silently dropped and the resulting secret was empty, breaking authentication. Write the two fields independently, so: - `--username` + `--password` -> username + password keys (unchanged); - `--password` alone -> password key only (fixes fluxcd#3892); - `--username` alone -> username key only. The SSH-passphrase case also becomes simpler: the duplicated `if options.Password != ""` inside the keypair branch collapses into the top-level write. Adds a `buildGitSecret` unit test covering all four credential shapes, including the Azure DevOps PAT scenario. Closes fluxcd#3892. Signed-off-by: SAY-5 <SAY-5@users.noreply.github.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.
Closes #3892.
Problem
sourcesecret.buildGitSecretwrote theusername/passwordsecret keys only when both fields were non-empty:```go
if options.Username != "" && options.Password != "" {
secret.StringData[UsernameSecretKey] = options.Username
secret.StringData[PasswordSecretKey] = options.Password
}
```
With an Azure DevOps PAT, the token is the credential and there is no username. Running
```
flux create source git podinfo --password=${PAT} --url=${repo} …
```
therefore produced a GitRepository backed by a secret with an empty
StringData, and the reconciler failed to authenticate. Manually editing the secret to add the password key made it work again — confirming the value was just being dropped on create.Fix
Write the two fields independently, so:
--username+--passwordusername+passwordkeys (unchanged)--passwordalonepasswordkey only (this PR)--usernamealoneusernamekey onlyThe SSH-passphrase case also becomes simpler: the duplicated
if options.Password != \"\"inside the keypair branch collapses into the top-level write, since Password is written exactly once regardless of whether a keypair is also present.Tests
Added
Test_buildGitSecret_BasicAuthFieldstosourcesecret_test.gocovering all four credential shapes (both, password-only, username-only, none). Existing tests still pass:```
$ go test ./pkg/manifestgen/sourcesecret/...
ok github.com/fluxcd/flux2/v2/pkg/manifestgen/sourcesecret 1.463s
```
Signed-off-by: SAY-5 SAY-5@users.noreply.github.com