Skip to content

test(cmd): guardrail against new aws-sdk imports in cmd/ (#327) - #345

Merged
scttfrdmn merged 1 commit into
mainfrom
audit/327-cmd-sdk-guardrail
Jul 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
audit/327-cmd-sdk-guardrail

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #327. Final audit follow-up (#328), unblocked by the #326 store extraction. Test-only, no runtime change.

What

cmd/aws_imports_test.go — an AST-based go/parser test that walks every non-test cmd/*.go and fails if it imports an aws-sdk-go-v2/service/* package outside a per-file allowlist seeded with the current (post-#326) baseline. It also flags allowlist entries a file no longer imports, so the list tightens as more logic moves into pkg/* rather than rotting.

Why now

Before #326, cmd/ reached for DynamoDB directly all over. Now bot/team/pipeline/list-sweeps/collect go through pkg/* stores, so the remaining allowed SDK imports are legitimate and bounded:

  • store-client construction (dynamodb.NewFromConfig handed to a pkg store),
  • STS caller-identity,
  • the launch/queue EC2/S3 paths.

A new direct SDK import — or an existing file reaching for a new service — now fails with an actionable message pointing the author at the pkg/* pattern (or to justify it by extending the allowlist in the same PR).

Verification

  • Passes on the current baseline.
  • Negative-tested: injecting a service/kms import into cancel.go fails the test with the expected message; green again after removal.
  • go vet ./cmd, gofmt, full cmd suite green (excl. pre-existing TestCatalogValid / feat(plugin): permissions declaration block (#388) #392).

Adds cmd/aws_imports_test.go: an AST-based test that parses every
non-test cmd/*.go and fails if it imports an aws-sdk-go-v2/service/*
package outside a per-file allowlist seeded with the current (post-#326)
baseline. A new direct SDK import — or an existing file reaching for a
new service — fails the test, steering AWS work into a pkg/* store/client
instead. It also flags allowlist entries that a file no longer imports,
so the list tightens as more logic moves into pkg/*.

Now feasible because the #326 store extraction removed the raw DynamoDB
calls from bot/team/pipeline/list-sweeps/collect; the remaining allowed
imports are store-client construction (dynamodb.NewFromConfig), STS
caller-identity, and the launch/queue EC2/S3 paths.

Verified: passes on the baseline; negative-tested (injecting a
service/kms import into cancel.go fails with an actionable message,
green again after removal). Test-only; go vet + full cmd suite green.
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit b5a55f7 into main Jul 12, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the audit/327-cmd-sdk-guardrail branch July 12, 2026 18:47
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.

[audit] Guardrail: add a test forbidding NEW direct aws-sdk service imports in cmd/ (allowlist)

1 participant