Skip to content

fix: return clear error when --private-key-file path starts with '~'#5859

Open
rafaelperoco wants to merge 1 commit into
fluxcd:mainfrom
rafaelperoco:fix/tilde-expansion-private-key-file
Open

fix: return clear error when --private-key-file path starts with '~'#5859
rafaelperoco wants to merge 1 commit into
fluxcd:mainfrom
rafaelperoco:fix/tilde-expansion-private-key-file

Conversation

@rafaelperoco
Copy link
Copy Markdown
Contributor

Summary

The tilde character is expanded by the shell, not by the Flux CLI, so paths like ~/.ssh/id_ecdsa passed with =value syntax (e.g. --private-key-file=~/.ssh/id_ecdsa) were opened verbatim and failed with a confusing no such file or directory error.

This change detects a leading ~ up front in LoadKeyPairFromPath and in the getAuthOpts code path used by bootstrap git, and returns a clear error pointing users at absolute paths or \$HOME instead. Behavior for normal paths is unchanged.

Maintainers' position in #5591 was to not auto-expand ~ but to surface a better error message, which is what this PR implements.

Fixes #5591.

Test plan

  • New test case ssh key with tilde path in create_secret_git_test.go asserting the new error
  • go test ./cmd/flux/... ./pkg/manifestgen/sourcesecret/... passes
  • Manual repro: flux create secret git ... --private-key-file=~/.ssh/id_ecdsa now returns the clear message
  • Regression check: passing a regular relative path still works

The tilde character is expanded by the shell, not by the Flux CLI, so
paths like ~/.ssh/id_ecdsa passed with =value syntax were opened
verbatim and failed with a confusing "no such file or directory" error.
Detect the leading '~' up front and surface a message pointing users at
absolute paths or $HOME instead. Fixes fluxcd#5591.

Signed-off-by: Rafael Peroco <rafaelperoco@gmail.com>
@rafaelperoco rafaelperoco force-pushed the fix/tilde-expansion-private-key-file branch from 0ad391f to 566bbe6 Compare April 21, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flux CLI does not read key file from path with tilde character

1 participant