Sanitize credentials from snapshot repository URLs#1174
Open
Conversation
f5f0306 to
8d5cbdb
Compare
8d5cbdb to
aff1e1d
Compare
REST backend repository URLs can contain credentials in the userinfo component (e.g. rest:https://user:pass@host/path). These were stored verbatim in Snapshot CRs and visible via kubectl get snapshot, exposing credentials to anyone with read access to the namespace. Add sanitizeRepositoryURL() that replaces userinfo with "redacted" before storing in the Snapshot spec. This only affects REST backends — S3/Azure/Swift/B2/GCS backends don't include credentials in the repository URL. Fixes #1077 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
aff1e1d to
498d8c5
Compare
bastjan
reviewed
Mar 25, 2026
Comment on lines
+26
to
+33
| if idx := strings.Index(repo, ":"); idx > 0 { | ||
| candidate := repo[:idx] | ||
| // Check if it looks like a restic scheme (not a Windows drive letter or URL scheme) | ||
| if candidate == "rest" || candidate == "s3" || candidate == "azure" || candidate == "swift" || candidate == "b2" || candidate == "gs" { | ||
| prefix = repo[:idx+1] | ||
| rest = repo[idx+1:] | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| if idx := strings.Index(repo, ":"); idx > 0 { | |
| candidate := repo[:idx] | |
| // Check if it looks like a restic scheme (not a Windows drive letter or URL scheme) | |
| if candidate == "rest" || candidate == "s3" || candidate == "azure" || candidate == "swift" || candidate == "b2" || candidate == "gs" { | |
| prefix = repo[:idx+1] | |
| rest = repo[idx+1:] | |
| } | |
| } | |
| if candidate, after, found := strings.Cut(repo, ":"); found { | |
| // Check if it looks like a restic scheme (not a Windows drive letter or URL scheme) | |
| if candidate == "rest" || candidate == "s3" || candidate == "azure" || candidate == "swift" || candidate == "b2" || candidate == "gs" { | |
| prefix = candidate + ":" | |
| rest = after | |
| } | |
| } |
Much easier to understand IMO.
| "local path": { | ||
| input: "/tmp/restic-repo", | ||
| expected: "/tmp/restic-repo", | ||
| }, |
Member
There was a problem hiding this comment.
Suggested change
| }, | |
| }, | |
| "scheme only": { | |
| input: "s3:", | |
| expected: "s3:", | |
| }, | |
| "windows drive letter": { | |
| input: "C:\\path\\to\\repo", | |
| expected: "C:\\path\\to\\repo", | |
| }, | |
| "url scheme": { | |
| input: "http://example.com/repo", | |
| expected: "http://example.com/repo", | |
| }, |
We probably should test what was written in the comment.
Kidswiss
requested changes
Mar 27, 2026
Contributor
Kidswiss
left a comment
There was a problem hiding this comment.
Please implement bastjan's suggestions.
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
REST backend repository URLs can contain credentials in the userinfo component (e.g.
rest:https://user:pass@host/path). These were stored verbatim in Snapshot CRs and visible viakubectl get snapshot, exposing credentials to anyone with read access to the namespace.Before
After
Only REST backends are affected — S3/Azure/Swift/B2/GCS backends don't include credentials in the repository URL.
Fixes #1077
Checklist
area:operatorcharts/directoryTest plan
🤖 Generated with Claude Code