Repository navigation
fix: harden CLI flag precedence, positional arg validation, target-only bucket diffing, and temp SQLite URIs - #18
Merged
Conversation
…ly bucket diffing, and temp SQLite URIs - Reject unexpected positional arguments across root and all subcommands (`cobra.NoArgs`) so mistyped arguments like `migration run photos` cannot silently trigger all-bucket operations. - Respect `CLI > env > YAML > default` precedence in `loadConfig` via `config.LoadForCLI` so explicit CLI flags (`--bucket`, `--workers`, `--multipart-concurrency`, `--rate-limit`, `--source-frozen`) override invalid env or YAML values instead of failing before CLI flags are applied. - Detect and report target-only buckets during all-bucket `diff --extra` and `diff --strict` via `differ.RunExtraBucket`. - Construct encoded `file:` SQLite URIs for temporary diff databases so `TMPDIR` paths containing `?` or `#` are handled safely without leaking files. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
loverustfs
force-pushed
the
loverustfs-fix-audit-bugs
branch
from
November 4, 2026 15:55
828713e to
6e05eca
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Invalid YAML rate limits block valid CLI overrides, and empty source clusters prevent extra/strict diffing from reporting target-only buckets.
2 open issues
What changed in this PR
This PR hardens the migration CLI against unintended bucket selection, improves configuration precedence, and extends diff reporting to target-only buckets.
Changes:
- Reject unexpected positional arguments and apply explicit CLI overrides before configurable-value validation.
- Add target-only bucket reporting to all-bucket
diff --extraanddiff --strict. - Encode temporary SQLite file URIs safely and add regression tests.
| File | Description |
|---|---|
internal/differ/differ.go |
Adds target-only bucket reporting and encoded temporary SQLite URIs. |
internal/differ/audit_test.go |
Tests special-character temporary paths and target-only buckets. |
internal/config/config.go |
Introduces CLI-aware loading and selective environment overrides. |
cmd/root.go |
Rejects positional arguments and coordinates CLI precedence and expanded diffing. |
cmd/audit_test.go |
Tests argument rejection, configuration precedence, and target-only diff output. |
Review effort: Balanced
Comment on lines
+304
to
+307
| names, err := resolveBuckets(ctx, cfg, oldCli) | ||
| if err != nil { | ||
| return err | ||
| } |
| // corresponding CLI flag was explicitly set) and defaults, and validates fields | ||
| // that cannot be overridden by CLI flags. Callers must apply CLI overrides and | ||
| // then validate names, concurrency and rate limit. | ||
| func LoadForCLI(path string, opt CLIReadOptions) (*Config, error) { |
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
This PR resolves four correctness and safety issues identified during the codebase audit:
Reject unexpected positional arguments (
cmd/root.go)cobra.NoArgsonrootand all subcommands (list,run,scan,migrate,diff,status).migration run photos(omitting-b/--bucket) withbucket: ""inconfig.yamlsilently ignored the positionalphotosargument and migrated every bucket on the source cluster.Enforce
CLI > env > YAML > defaultprecedence before validation (internal/config/config.go,cmd/root.go)config.LoadForCLIwithCLIReadOptionssocmd.loadConfigapplies explicit CLI overrides (--bucket,--workers,--multipart-concurrency,--rate-limit,--source-frozen) before validating those settings.WORKERS=2048or an invalidBUCKETin YAML/env) causedconfig.Loadto fail before explicit CLI flags like--workers 16or--bucket photoscould override it.Detect target-only buckets in all-bucket
diff --extraanddiff --strict(cmd/root.go,internal/differ/differ.go)diffin all-bucket mode (bucket: "") with--extraor--strict, also list buckets on the target cluster and rundiffer.RunExtraBucketfor any bucket absent from the source cluster.--issues-jsonl, and fail the command under--strict.Use properly encoded
file:SQLite URIs for temporary diff databases (internal/differ/differ.go)net/url.URL(Scheme: "file") with explicit0600permissions rather than raw string concatenation (tmp + "?_pragma=...").TMPDIRpaths containing?or#from being misinterpreted as URI query/fragment delimiters and leaking uncleaned SQLite files outsideTMPDIR.Verification
go vet -tags real_s3 ./...go test -race -count=1 ./...