: asapien/signet

commit 6c96811c207f885cb2843c28e7824fe9055ff4a6
parent 20b1d2a332bea3abbd01c2290fe1a2b1cc0982bb
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Thu, 12 Nov 2026 05:23:12 +0530

Keep forwarded identity fail closed and test configurable roles
7 files changed, 169 insertions(+), 31 deletions(-)
A
.scratch/roadmap/ticket-13.md
|
35
+++++++++++++++++++++++++++++++++++
M
README.md
|
25
++++++++++++++++++++-----
M
src/http.c
|
14
++++++++++----
M
test/dev-up.sh
|
16
+++-------------
M
test/e2e.sh
|
6
+++++-
A
test/identity-contract.sh
|
93
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M
test/lighttpd-dev.conf
|
11
+++--------
diff --git a/.scratch/roadmap/ticket-13.md b/.scratch/roadmap/ticket-13.md
@@ -0,0 +1,35 @@
+# Ticket 13 — fail-closed forwarded identity
+
+Implemented on isolated branch feat/signet-ticket13. No authentication server,
+production proxy integration or deployment is included. See spec.md §4.
+
+`ident_read()` accepts only a valid configured username header, clears groups
+for absent/invalid identity and grants no groups when its header is absent.
+Neither DEV_MODE nor DEV_REMOTE_* supplies credentials. Roles still come solely
+from signet.conf. The integration baseline already excluded the original
+checkout's uncommitted unconditional admin fallback; it is not restored here.
+The unrelated original checkout/auth experiments remain untouched.
+
+Provider-independent dev bootstrap removes automatic Authelia installation and
+startup. The old lighttpd socket conditional accidentally created a duplicate
+8080 listener; removing that unused provider/proxy stub allows a clean isolated
+stack to boot. Real production trusted-header overwrite/backend bypass remains
+ticket14, not something this header-trusting dev stack can prove.
+
+`test/identity-contract.sh` (also run by default e2e, or e2e identity-contract)
+tests both APIs: absent/invalid identity401; groups without identity401; absent
+or unknown groups give no roles and cannot write; authenticated PIM reads stay
+available; config-only role remapping; no environment fallback; configurable
+identity header names. It temporarily changes the isolated config and restarts
+APIs, restoring both on exit. Never run this test on production.
+
+Verification in Alpine development container:
+- /tmp/signet-ticket13-build.log: clean -Wall -Wextra build.
+- /tmp/signet-ticket13-e2e.log: identity contract and full API/worker e2e PASS.
+- /tmp/signet-ticket13-render.log: render recovery/queue/release contract PASS.
+- Shell syntax/diff checks pass. These are not native production acceptance.
+
+Owner's CONSIDERATIONS.md (2026-11-12) was read: customer signing remains
+unapproved future scope; native resource containment/coexistence and maa-1's
+mission-critical shared services remain deployment gates. No maa-1 access or
+shared service changes were made.
diff --git a/README.md b/README.md
@@ -6,8 +6,9 @@ No containers or language runtimes in production.
 
 **Development status:** sequential signing, worker-owned release and render-job
 recovery have fresh isolated-development tests; see
-`.scratch/roadmap/ticket-11.md`. Submit-time PIM/DAM snapshots and fail-closed
-identity remain open (`HANDOFF.md` §4). It is not ready for production deployment;
+`.scratch/roadmap/ticket-11.md`. Fail-closed identity is covered by
+`.scratch/roadmap/ticket-13.md`; submit-time PIM/DAM snapshots remain open.
+It is not ready for production deployment;
 these checks do not certify the native deployment or production trust boundary.
 
 ```

@@ -74,8 +75,9 @@ merged with `qpdf --overlay`.
 ## Install (Alpine)
 
 The following is an unverified deployment outline, not a production-ready
-runbook. Resolve the gaps in `HANDOFF.md` §4 first; in particular the current
-missing-header admin fallback must not be exposed to untrusted requests.
+runbook. Resolve the gaps in `HANDOFF.md` §4 first. Identity now fails closed,
+but the trusted proxy boundary, DAM writer policy and native resource safety
+still require deployment verification.
 
 ```sh
 apk add build-base pkgconf kcgi-dev hiredis-dev libpq-dev libpng-dev zlib-dev \

@@ -111,9 +113,22 @@ podman build -t signet-dev .
 podman run --rm -d --name signet -p 8080:8080 signet-dev
 podman exec signet /src/test/e2e.sh     # API + worker end to end
 podman exec signet /src/test/e2e.sh render-contract  # failure/replay/queue regression
-open http://localhost:8080              # isolated dev only; may default to admin
+open http://localhost:8080              # isolated dev only; explicit identity required
 ```
 
+Development has no implicit admin identity or authentication-server dependency.
+For browser testing, set an explicit identity in the browser console and reload:
+
+```js
+localStorage.signetDevIdentity = JSON.stringify({ user: 'asha', groups: 'clerks' });
+location.reload();
+```
+
+`podman exec signet sh /src/test/e2e.sh identity-contract` checks both APIs and
+configurable identities/roles. It restarts test API processes and must run only
+in the isolated dev container. Production must overwrite forwarded headers and
+prevent direct backend access; the browser dev selector is not authentication.
+
 Optional browser regressions use externally installed Playwright Core and Chrome
 on the development machine only (no production or runtime JS dependency):
 
diff --git a/src/http.c b/src/http.c
@@ -20,12 +20,18 @@ http_header(struct kreq *r, const char *name)
 void
 ident_read(struct kreq *r, const struct conf *cf, struct ident *id)
 {
+	const char *groups;
+
 	id->user = http_header(r, conf_get(cf, "auth.user_header", "Remote-User"));
-	id->groups = http_header(r, conf_get(cf, "auth.groups_header", "Remote-Groups"));
-	if (id->user != NULL && !is_safe_name(id->user))
+	id->groups = "";
+	/* No development environment variable may manufacture an identity or role. */
+	if (id->user == NULL || !is_safe_name(id->user)) {
 		id->user = NULL;
-	if (id->groups == NULL)
-		id->groups = "";
+		return;
+	}
+	groups = http_header(r, conf_get(cf, "auth.groups_header", "Remote-Groups"));
+	if (groups != NULL)
+		id->groups = groups;
 }
 
 int
diff --git a/test/dev-up.sh b/test/dev-up.sh
@@ -43,19 +43,9 @@ kfcgi -n 2 -N 2 -s /run/signet/api.sock -u lighttpd -U signet -p / -- /usr/local
 kfcgi -n 1 -N 1 -s /run/signet/pim.sock -u lighttpd -U signet -p / -- /usr/local/libexec/pim-api
 su-exec signetd:signet /usr/local/sbin/signetd 2>>/tmp/signetd.log &
 
-# Install and start Authelia with YAML backend
-if ! command -v authelia >/dev/null 2>&1; then
-	apk add -q authelia
-fi
-mkdir -p /var/lib/authelia
-cp /src/etc/authelia.yml /etc/authelia.yml
-cp /src/etc/authelia-users.yml /etc/authelia-users.yml
-authelia 2>>/tmp/authelia.log &
-echo "Authelia started (listening on :9091)"
-
-echo "signet dev stack on http://localhost:8080"
+# Isolated development supplies explicit headers; no authentication server needed.
+echo "signet dev stack on http://localhost:8080 (explicit identity headers required)"
 echo "  Signet: http://localhost:8080/"
 echo "  PIM:    http://localhost:8080/pim/"
-echo "  Auth:   Authelia (admin/admin)"
-echo "  Note:   Enable proxy in lighttpd-dev.conf line ~16"
+echo "  Note:   Do not expose this header-trusting dev stack to untrusted clients"
 exec lighttpd -D -f /src/test/lighttpd-dev.conf
diff --git a/test/e2e.sh b/test/e2e.sh
@@ -4,6 +4,10 @@ set -eu
 if [ "${1-}" = render-contract ]; then
 	exec sh /src/test/render-contract.sh
 fi
+if [ "${1-}" = identity-contract ]; then
+	exec sh /src/test/identity-contract.sh
+fi
+sh /src/test/identity-contract.sh
 B=http://localhost:8080
 X='X-Requested-With: signet'
 as() { u=$1; g=$2; shift 2; curl -fsS -H "Remote-User: $u" -H "Remote-Groups: $g" "$@"; }

@@ -47,7 +51,7 @@ new_doc() {
 	[ ${#ID} = 36 ] || die create
 	save "$LAYOUT" >/dev/null
 }
-# Auth-provider setup and the pre-existing missing-header fallback are ticket 13,
+# Auth-provider setup is deployment-owned; explicit identities are tested above,
 # not prerequisites for these tests; every request supplies an explicit identity.
 check 'configured drafter role' "$(clerk "$B/api/me")" '.roles.drafter and (.roles.signer | not)'
 status 403 asha clerks -F code=DENIED -F 'pattern={seq}' "$B/api/series"
diff --git a/test/identity-contract.sh b/test/identity-contract.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+# Isolated dev container only: temporarily remaps roles/headers and restarts APIs.
+set -eu
+B=http://localhost:8080
+CF=/etc/signet/signet.conf
+BACKUP=$(mktemp /tmp/signet-identity.XXXXXX)
+cp "$CF" "$BACKUP"
+stop_apis() {
+	pkill -f '^kfcgi .* /run/signet/(api|pim).sock' 2>/dev/null || true
+	pkill -f '^/usr/local/libexec/(signet-api|pim-api)' 2>/dev/null || true
+	rm -f /run/signet/api.sock /run/signet/pim.sock
+}
+start_apis() {
+	kfcgi -n 2 -N 2 -s /run/signet/api.sock -u lighttpd -U signet -p / -- /usr/local/libexec/signet-api
+	kfcgi -n 1 -N 1 -s /run/signet/pim.sock -u lighttpd -U signet -p / -- /usr/local/libexec/pim-api
+}
+cleanup() {
+	cp "$BACKUP" "$CF"
+	stop_apis
+	start_apis
+	rm -f "$BACKUP"
+}
+trap cleanup EXIT
+fail() { echo "FAIL - $*"; exit 1; }
+status() {
+	want=$1; shift
+	got=$(curl -sS -o /tmp/identity-response -w '%{http_code}' "$@")
+	[ "$got" = "$want" ] || fail "HTTP $got expected $want: $*"
+}
+for endpoint in api/me pim-api/me; do
+	status 401 "$B/$endpoint"
+	status 401 -H 'Remote-Groups: signet-admins' "$B/$endpoint"
+	for user in '../admin' 'bad name' 'bad@user'; do
+		status 401 -H "Remote-User: $user" -H 'Remote-Groups: signet-admins' "$B/$endpoint"
+	done
+	status 200 -H 'Remote-User: unaffiliated' "$B/$endpoint"
+	jq -e '.user == "unaffiliated" and ([.roles[]] | all(. == false))' /tmp/identity-response >/dev/null || fail 'missing groups manufactured roles'
+	status 200 -H 'Remote-User: unaffiliated' -H 'Remote-Groups: xsignet-adminsx,not-a-role' "$B/$endpoint"
+	jq -e '[.roles[]] | all(. == false)' /tmp/identity-response >/dev/null || fail 'unknown group manufactured roles'
+done
+status 401 -H 'X-Requested-With: signet' -d '' "$B/api/docs"
+status 401 -H 'X-Requested-With: signet' -d '' "$B/pim-api/attrs"
+status 403 -H 'Remote-User: unaffiliated' -H 'X-Requested-With: signet' -d '' "$B/api/docs"
+status 403 -H 'Remote-User: unaffiliated' -H 'X-Requested-With: signet' -d '' "$B/pim-api/resync"
+status 200 -H 'Remote-User: unaffiliated' "$B/pim-api/attrs"
+status 200 -H 'Remote-User: asha' -H 'Remote-Groups: clerks' "$B/api/me"
+jq -e '.roles == {drafter:true,signer:false,admin:false}' /tmp/identity-response >/dev/null || fail 'configured drafter roles'
+echo 'ok   - absent/invalid identity fails closed in both APIs; absent/unknown groups grant no roles'
+
+# No hardcoded role names and no CGI/environment dev backdoor.
+awk '
+$1 == "role.drafter" { print "role.drafter = test-drafter-13"; next }
+$1 == "role.signer" { print "role.signer = test-signer-13"; next }
+$1 == "role.admin" { print "role.admin = test-admin-13"; next }
+$1 == "role.pim_admin" { print "role.pim_admin = test-pim-13"; next }
+{ print }
+' "$BACKUP" > "$CF"
+export DEV_MODE=1 DEV_REMOTE_USER=admin DEV_REMOTE_GROUPS=signet-admins
+stop_apis
+start_apis
+status 401 "$B/api/me"
+status 401 "$B/pim-api/me"
+status 200 -H 'Remote-User: root' -H 'Remote-Groups: signet-admins,clerks,management' "$B/api/me"
+jq -e '[.roles[]] | all(. == false)' /tmp/identity-response >/dev/null || fail 'old groups still privileged'
+status 200 -H 'Remote-User: asha' -H 'Remote-Groups: test-drafter-13,test-signer-13' "$B/api/me"
+jq -e '.roles == {drafter:true,signer:true,admin:false}' /tmp/identity-response >/dev/null || fail 'remapped roles not honored'
+status 200 -H 'Remote-User: root' -H 'Remote-Groups: test-admin-13' "$B/api/me"
+jq -e '.roles.admin' /tmp/identity-response >/dev/null || fail 'remapped admin not honored'
+status 403 -H 'Remote-User: root' -H 'Remote-Groups: signet-admins' -H 'X-Requested-With: signet' -d '' "$B/pim-api/resync"
+status 200 -H 'Remote-User: pim' -H 'Remote-Groups: test-pim-13' "$B/pim-api/me"
+jq -e '.roles.pim_admin' /tmp/identity-response >/dev/null || fail 'remapped PIM role not honored'
+status 200 -H 'Remote-User: pim' -H 'Remote-Groups: test-pim-13' -H 'X-Requested-With: signet' --form-string org=IDENTITY13 --form-string key=contract --form-string type=text --form-string value=explicit "$B/pim-api/attrs"
+echo 'ok   - roles are config-only; development environment variables cannot grant identity'
+
+awk '
+$1 == "auth.user_header" { print "auth.user_header = Signet-Test-User"; next }
+$1 == "auth.groups_header" { print "auth.groups_header = Signet-Test-Groups"; next }
+{ print }
+' "$CF" > "$CF.identity-tmp"
+mv "$CF.identity-tmp" "$CF"
+stop_apis
+start_apis
+for endpoint in api/me pim-api/me; do
+	status 401 -H 'Remote-User: root' -H 'Remote-Groups: test-admin-13,test-pim-13' "$B/$endpoint"
+	status 200 -H 'Signet-Test-User: explicit' "$B/$endpoint"
+	jq -e '[.roles[]] | all(. == false)' /tmp/identity-response >/dev/null || fail 'custom missing groups privileged'
+done
+status 200 -H 'Signet-Test-User: explicit' -H 'Signet-Test-Groups: test-admin-13' "$B/api/me"
+jq -e '.roles.admin' /tmp/identity-response >/dev/null || fail 'custom identity headers ignored'
+status 200 -H 'Signet-Test-User: explicit' -H 'Signet-Test-Groups: test-pim-13' "$B/pim-api/me"
+jq -e '.roles.pim_admin' /tmp/identity-response >/dev/null || fail 'custom PIM identity headers ignored'
+echo 'ok   - configurable header names honored by both APIs'
+echo 'identity contract: all passed'
diff --git a/test/lighttpd-dev.conf b/test/lighttpd-dev.conf
@@ -9,7 +9,7 @@ server.max-request-size = 34000
 index-file.names = ( "index.html" )
 mimetype.assign = ( ".html" => "text/html", ".js" => "text/javascript", ".css" => "text/css",
   ".png" => "image/png", ".jpg" => "image/jpeg", ".ttf" => "font/ttf", ".pdf" => "application/pdf" )
-server.modules = ( "mod_alias", "mod_fastcgi", "mod_webdav", "mod_proxy" )
+server.modules = ( "mod_alias", "mod_fastcgi", "mod_webdav" )
 alias.url = ( "/dam/" => "/var/www/dam/", "/pim/" => "/var/www/pim/" )
 
 # Route Signet & PIM APIs to FastCGI

@@ -18,12 +18,7 @@ fastcgi.server = (
   "/pim-api" => (( "socket" => "/run/signet/pim.sock", "check-local" => "disable" )),
 )
 
-# Route auth-protected paths through Authelia (if available on port 9091)
-# Authelia will set Remote-User and Remote-Groups headers
-$SERVER["socket"] == "127.0.0.1:8080" {
-  # Uncomment to enable Authelia auth proxy:
-  # proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 9091 )) )
-  # For dev mode without Authelia, client supplies Remote-User via localStorage
-}
+# Isolated dev only: tests/browser supply explicit identity headers.
+# Production must overwrite them at the trusted proxy and prevent backend bypass.
 
 $HTTP["url"] =~ "^/dam/" { webdav.activate = "enable" }