Skip to content

refactor(db): move the SigV4 core to src/lib/db/auth/aws - #2304

Merged
cevheri merged 2 commits into
mainfrom
refactor/db-auth-aws-sigv4
Nov 15, 2026
Merged

cevheri merged 2 commits into
mainfrom
refactor/db-auth-aws-sigv4

Conversation

@cevheri

@cevheri cevheri commented Nov 15, 2026

Copy link
Copy Markdown
Member

Moves the SigV4 core out of the S3 provider into src/lib/db/auth/aws/sigv4.ts, so the next AWS provider signs with the same tested code instead of a copy.
S3 keeps its signing policy (s3Signer) in its own directory, now over the shared core; every S3 signature is byte for byte what it was.

What changes

  • src/lib/db/auth/aws/sigv4.ts is new: signatureV4, amzDateOf, canonicalQueryOf, EMPTY_PAYLOAD_SHA256 and compareEncodedPairs, moved unchanged from s3/sigv4.ts and s3/encoding.ts.
    The key pair is typed AwsSigningKeys, structurally the same as S3Credentials.
    Its docblock states protocol facts only; what Garage and Silo require stays in S3's file.
  • src/lib/db/providers/objectstore/s3/sigv4.ts holds only s3Signer and keeps its name, so the client-wire bundle test and row 3.19 of docs/SECURITY.md still point at it.
    s3/encoding.ts imports compareEncodedPairs from the core.
  • The 24 AWS suite vectors, the smithy vector, the header-order case, the empty-hash case and the two helpers move to tests/unit/db/auth/aws/sigv4.test.ts.
    Each vector's canonical query is now built with the shared rfc3986Query and compareEncodedPairs, not S3's s3Query.
    The fixture stays at tests/fixtures/s3/sigv4-suite.json, which the pinned .gitleaksignore entry names.
    tests/unit/db/s3/sigv4.test.ts keeps the s3Signer contract cases.
  • The auth seam guard counts AWS4-HMAC-SHA256 and aws4_request as mechanism markers (AUTH6), with a planted proof, and lists aws/sigv4.ts among the layer's files; AUTH1 already admits node:crypto in that file alone.
  • The S3 seam guard now refuses node:crypto and crypto, imported or loaded with require(), in every file of the S3 directory.
  • The three live S3 scripts under tests/live/ import the core from its new path.
  • Docs: docs/DB_AUTH.md gains an AWS section and the SigV4 markers in its guard list; docs/providers/s3.md (section 2.4 and the sigv4.ts row of the module table) and the S3 line of docs/ARCHITECTURE.md say the core is the shared one.
    The auth/ line of docs/ARCHITECTURE.md lists aws/, the shared-mechanism list in docs/DB_AUTH.md names the SigV4 core, and tests/fixtures/s3/README.md names the shared test as the suite's reader.

User-visible change

None.
No error sentence, request or header changes.

Test plan

bun tests/run-tests.ts tests/unit/db/auth/aws/sigv4.test.ts
bun tests/run-tests.ts tests/unit/db/auth/seam-guard.test.ts
bun tests/run-tests.ts tests/unit/db/s3/sigv4.test.ts
bun tests/run-tests.ts tests/unit/db/s3/seam-guard.test.ts
bun tests/run-tests.ts tests/unit/db/s3/encoding.test.ts
bun tests/run-tests.ts tests/unit/db/s3/client-wire.test.ts
SEED_CONFIG_PATH= heavy bun tests/run-tests.ts tests/unit/db/s3 tests/unit/db/auth
(cd vscode-extension && npm ci --ignore-scripts) && bun run format && bun run lint && bun run typecheck && bun run knip && bun run chart:check && bun run channels:showcase:check && bun run readme:check && bun run security:check && bun run test && bun run build
bun run test:coverage && bun run coverage:check
bun run build:lib && bun run attw && bun run lib:closure
cd vscode-extension && npm run build

The shared test was run red against the missing module first, and the S3 seam guard red against the old s3/sigv4.ts.

@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The SigV4 core (signatureV4, amzDateOf, canonicalQueryOf, EMPTY_PAYLOAD_SHA256)
and compareEncodedPairs move from the S3 provider to src/lib/db/auth/aws/sigv4.ts,
with the key pair typed as AwsSigningKeys. S3 keeps s3Signer, its signing policy,
in s3/sigv4.ts over the shared core. Every S3 signature is unchanged: the AWS
suite vectors and the s3Signer contract tests pass as before.

The auth seam guard adds the SigV4 markers to AUTH6, and the S3 seam guard now
refuses node:crypto in every file of the S3 directory.
…3 crypto guard

List aws/ on the auth/ line of ARCHITECTURE.md and the SigV4 core among the shared mechanisms in DB_AUTH.md.
Say in the S3 fixtures README that the shared SigV4 test reads sigv4-suite.json and why the file stays under s3/.
The S3 seam guard now also refuses the bare crypto specifier and require() loads.
The shared core's own test covers compareEncodedPairs, so aws/sigv4.ts is fully covered without the S3 tests.
Reword the signatureV4 docblock, which still said the export was for the suite vectors.
@cevheri
cevheri force-pushed the refactor/db-auth-aws-sigv4 branch from 20690e1 to 014a969 Compare November 15, 2026 04:09
@sonarqubecloud

Copy link
Copy Markdown

@cevheri
cevheri merged commit d191e3e into main Nov 15, 2026
29 checks passed
@cevheri
cevheri deleted the refactor/db-auth-aws-sigv4 branch November 15, 2026 05:59
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.

1 participant