feat: add CLI with catalog pull command (fixes #4)#6
Open
jpower432 wants to merge 4 commits into
Open
Conversation
Add complypack CLI with `catalog pull` command to load Gemara control catalogs from OCI registries. Features: - Cobra-based CLI framework - OCI registry pull using ORAS v2 - Docker credential chain authentication - Gemara bundle unpacking via go-gemara - Output to stdout or file (--output) - Plain HTTP support (--plain-http) Changes: - Bump Go 1.23.0 -> 1.25.0 (required by go-gemara) - Add dependencies: spf13/cobra, gemaraproj/go-gemara - Update CI test matrix to Go 1.25 - Add cmd/complypack CLI entrypoint - Add internal/registry for OCI client helpers - Update README with CLI usage documentation Closes #4 Assisted-by: Claude (Anthropic, Claude 3.5 Sonnet 4.5) Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Refactor pkg/complypack tests to use testify/assert and testify/require
for cleaner, more readable test assertions.
Changes:
- Refactor pack_test.go to use assert/require
- Refactor config_test.go to use assert/require
- Replace verbose stdlib checks with testify helpers
- if err != nil { t.Fatalf(...) } → require.NoError(t, err)
- if got != want { t.Errorf(...) } → assert.Equal(t, want, got)
- errors.Is checks → assert.ErrorIs(t, err, sentinel)
Benefits:
- Cleaner, more readable test code
- Consistent with complyctl and go-gemara
- Better failure messages
- Less boilerplate
Remaining test files (errors, mediatype, options, integration, unpack,
sign, verify) can be refactored incrementally following this pattern.
Assisted-by: Claude (Anthropic, Claude 3.5 Sonnet 4.5)
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
4e8a976 to
4797467
Compare
Resolve all HIGH and MEDIUM severity security findings from the security audit: **HIGH Findings:** 1. Output file path validation (catalog_pull.go:106) - Add validateOutputPath() to prevent path traversal - Reject absolute paths and ".." sequences - Check for symlinks to prevent write-through attacks - Use os.OpenFile with explicit 0o644 permissions (SC-005) - Implements SC-004 requirement for path validation 2. HTTP timeout (client.go:38) - Replace http.DefaultClient with custom client - Set 60-second timeout to prevent indefinite hangs - Improves resilience for CI/automation usage **MEDIUM Findings:** 3. File close error handling (catalog_pull.go:110) - Explicitly check Close() error on output file - Catches write errors on buffered/networked filesystems - Prevents silent data corruption 4. Artifact size validation (catalog_pull.go:81) - Add validateArtifactSize() to check descriptor size - Enforce MaxContentSize limit (100MB) from library - Prevents memory exhaustion from malicious registries **LOW Findings:** 5. Reference output sanitization (catalog_pull.go:79) - Use %q format verb instead of %s - Prevents ANSI escape sequence injection in terminal **Tests:** - Add TestValidateOutputPath for path validation logic - Add TestValidateOutputPathSymlink for symlink detection - Add TestValidateArtifactSize for size limit enforcement - All tests pass with -race flag Assisted-by: Claude (Anthropic, Claude 3.5 Sonnet 4.5) Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
Resolve remaining security issues found in second Adversary review: **HIGH Finding:** 1. Artifact size validation timing (catalog_pull.go:87-99) - Moved size check BEFORE oras.Copy to prevent downloading oversized artifacts - Use repo.Resolve() to fetch manifest descriptor first - Check manifest size against MaxContentSize before pulling content - Prevents memory exhaustion from actually occurring **MEDIUM Findings:** 2. Output path sanitization (catalog_pull.go:133) - Changed format verb from %s to %q for output path - Consistent with reference sanitization on line 91 - Prevents terminal control character injection 3. Go version mismatch (release.yml:29) - Updated release workflow from Go 1.23 to 1.25 - Matches CI workflow and go.mod requirements - Prevents release pipeline breakage **LOW Finding:** 4. HTTP timeout consistency (client.go:37-46) - Always set HTTP timeout regardless of credFunc value - Moved timeout setup outside credFunc conditional - Ensures resilience even without authentication All tests pass with -race flag enabled. Assisted-by: Claude (Anthropic, Claude 3.5 Sonnet 4.5) Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.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.
Summary
Adds
complypack catalog pullCLI command to load Gemara control catalogs from OCI registries, addressing issue #4.Changes
CLI Implementation:
cmd/complypack/)catalog pull <reference>command for pulling Gemara catalogs--output)--plain-http)Registry Client:
internal/registry/package for OCI operationsDependencies:
github.com/spf13/cobrafor CLI frameworkgithub.com/gemaraproj/go-gemarafor bundle unpackingDocumentation:
Example Usage
Testing
go build ./...passesgo test -race ./...passesRelated
Closes #4