Skip to content

feat(db): AWS typed credentials, regional endpoints and a request signer - #2307

Merged
cevheri merged 3 commits into
mainfrom
feat/db-auth-aws-signer
Nov 15, 2026
Merged

cevheri merged 3 commits into
mainfrom
feat/db-auth-aws-signer

Conversation

@cevheri

@cevheri cevheri commented Nov 15, 2026

Copy link
Copy Markdown
Member

Adds the AWS pieces a provider needs to call an AWS JSON or Query API (DynamoDB, Athena, Redshift's credential calls) under src/lib/db/auth/aws/, so the first AWS provider wires tested code instead of writing its own region, key and signing rules.
Nothing calls it yet: no provider, route or setting changes.

What changes

  • aws/endpoints.ts is new: parseAwsRegion admits a region of the commercial aws partition by AWS's own regionRegex (source pinned in the docblock), refuses a blank value, quotes a refused value only when it is shaped as a region name (cn-north-1, us-gov-west-1), and never quotes any other value, such as a secret pasted into the wrong field.
    awsServiceOrigin(service, region) gives https://<service>.<region>.amazonaws.com:443, refusing a malformed service name and a region parseAwsRegion did not return.
    AWS_SIGNING_REGION is the scope rule an emulator region must meet.
  • aws/credentials.ts is new: resolveAwsCredentials takes typed keys only, with an optional session token, and refuses an empty pair, a token without a pair, half a pair and every value outside its format rule, with sentences that quote no value.
    It reads no environment variable, file, profile or instance metadata.
    awsCredentialSecrets lists the secret, the token and the key ID for secretForms.
  • aws/signer.ts is new: createAwsSigner is a text-transport RequestSigner that signs host, content-type, every x-amz-* header, x-amz-date, the session token and the SHA-256 of the body, reads the credentials getter and the clock at send time, and refuses a path other than / and a query that is not already RFC 3986-encoded (a URLSearchParams query from endpointUrl is form-encoded, so its canonical form is not the one AWS computes).
  • aws/sigv4.ts gains AwsCredentials, payloadSha256 and sigV4Headers, which builds authorization, x-amz-date and x-amz-security-token.
    The existing functions and S3's signer are unchanged.
  • The auth seam guard lists the three new files.
  • docs/ARCHITECTURE.md describes aws/ as the SigV4 core, regions and endpoints, typed credentials and the request signer.
  • docs/DB_AUTH.md describes regions and endpoints, typed credentials, the request signer, and what is designed but not yet built (a refreshing source, AssumeRole, the server's own identity).
  • docs/SECURITY.md row 3.40, the shared auth layer's control, gains the AWS part: typed keys only with no ambient source, endpoints only for the commercial aws partition, a refused region quoted only when shaped as a region name, the signer's refusal of a path other than / and of a query that is not RFC 3986-encoded, and refusals that quote no key, secret or token.
    Its Enforced in and Verified by columns list the four aws/ files and their tests.

User-visible change

None.

Test plan

bun tests/run-tests.ts tests/unit/db/auth/aws/sigv4.test.ts
bun tests/run-tests.ts tests/unit/db/auth/aws/endpoints.test.ts
bun tests/run-tests.ts tests/unit/db/auth/aws/credentials.test.ts
bun tests/run-tests.ts tests/unit/db/auth/aws/signer.test.ts
bun tests/run-tests.ts tests/unit/db/auth/seam-guard.test.ts
SEED_CONFIG_PATH= heavy bun tests/run-tests.ts tests/unit/db/auth tests/unit/db/s3 tests/unit/lib/no-engine-branches.test.ts tests/unit/distribution-check.test.ts tests/unit/db/http/node-transport-text-signer.test.ts
heavy bun tests/run-tests.ts tests/unit/security-check.test.ts tests/integration/db/s3-provider.test.ts
heavy bun tests/run-tests.ts --coverage tests/unit/db/auth/aws
(cd vscode-extension && npm ci --ignore-scripts) && bun run format && bun run lint && bun run typecheck && bun run knip && bun run security:check && bun run readme:check

Each new test file was run red against the missing module first.
The signer test feeds the nine POST vectors of the AWS SigV4 suite whose signed set is the signer's policy to sign() directly and reproduces each Authorization; the three outside the policy are named with their reasons.
A loopback test sends JSON and form requests through a real text transport and checks the Authorization received against one recomputed with signatureV4 from what the listener received.
A signer test signs the suite's get-vanilla-query-unreserved vector from an RFC 3986 query, and a loopback test shows a query with ~, * and a space signs when built with rfc3986Query and is refused, with nothing sent, when built by endpointUrl from URLSearchParams.
The four new and changed aws/ files are fully line-covered by their own tests.
The full test, coverage, build, build:lib, attw and extension gates run in CI.

Add the AWS pieces a JSON or Query API provider needs, with no consumer yet:
parseAwsRegion and awsServiceOrigin for the commercial partition,
resolveAwsCredentials and awsCredentialSecrets for typed keys with an optional
session token, and createAwsSigner, the text-transport signing policy. The
SigV4 core gains payloadSha256 and sigV4Headers. The signer is held by the nine
in-policy POST vectors of the AWS SigV4 suite and by a loopback test through
the real text transport.
…e region docs

The signer signs the query as sent, so it now refuses one that is not RFC 3986-encoded instead of signing a canonical form AWS does not compute.
The endpoints docblock and DB_AUTH.md no longer claim the European Sovereign Cloud's region is quoted, the regionRegex provenance no longer points at a transitive bun.lock entry, and ARCHITECTURE.md describes the whole aws/ folder.
Tests pin the provider label on both region refusals, the region-quoting edges and the frozen pair-only credentials.
@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!

@sonarqubecloud

Copy link
Copy Markdown

@cevheri
cevheri merged commit bb29952 into main Nov 15, 2026
39 checks passed
@cevheri
cevheri deleted the feat/db-auth-aws-signer 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