Skip to content

feat(auth): export buildOpaBody for reuse by dependent gateways#55

Merged
shimoncohen merged 2 commits into
masterfrom
feat/export-opa-body
Jul 21, 2026
Merged

feat(auth): export buildOpaBody for reuse by dependent gateways#55
shimoncohen merged 2 commits into
masterfrom
feat/export-opa-body

Conversation

@shimoncohen

Copy link
Copy Markdown
Contributor

What

Extracts the OPA request-body construction out of opaAuth into an exported buildOpaBody(r) helper in auth.js.

Why

Gateways that build on top of this base image (e.g. nginx-s3-gateway, which reuses this image for shared OPA/JWT auth) run a combined OPA→credentials auth handler in a single njs call, so they can't just call opaAuth (which does its own subrequest + r.return). They were rebuilding the OPA input themselves — and had drifted to a stale explicit header whitelist, diverging from this image's current denylist filtering (filterHeaders: blocklist + 2KB size-redaction + prototype-pollution guard).

Exporting the builder lets those gateways produce an identical OPA input contract instead of maintaining a divergent copy.

Change

  • New buildOpaBody(r) — returns the { input: { method, headers: filterHeaders(r), query, domain } } body as a JSON string.
  • opaAuth now calls it (pure extraction — behavior unchanged).
  • Added to the default export: { opaAuth, jwtPayloadSub, buildOpaBody }.

Verification

  • njs/ES syntax check passes.
  • No behavioral change to opaAuth — same body, same flow.

Extract the OPA request-body construction out of opaAuth into a
buildOpaBody(r) helper and export it. Gateways that build on this base
image (nginx-s3-gateway) run a combined OPA+credentials auth handler and
were rebuilding the OPA input themselves — with a stale header whitelist
that diverged from this image's denylist filtering. Exporting the builder
lets them send OPA an identical input contract instead.

opaAuth behavior is unchanged (pure extraction).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
shimoncohen added a commit to MapColonies/nginx-s3-gateway that referenced this pull request Jul 21, 2026
Drop s3_auth.js's own OPA body builder (which used a stale explicit
header whitelist) and call the base image's exported base.buildOpaBody,
so the gateway sends OPA the same input contract as every other consumer
of the shared nginx base (denylist header filtering + size limits).

Requires the base export from MapColonies/nginx#55; bump NGINX_BASE_TAG
to v2.3.0 accordingly (confirm the exact cut version once #55 releases).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shimoncohen
shimoncohen requested a review from CptSchnitz July 21, 2026 08:06
@shimoncohen
shimoncohen merged commit 2c63219 into master Jul 21, 2026
1 check passed
@shimoncohen
shimoncohen deleted the feat/export-opa-body branch July 21, 2026 08:17
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.

2 participants