Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbf36793de | ||
|
|
4284a3a39b | ||
|
|
0cb603fc62 | ||
|
|
5b3cda802f | ||
|
|
8be19c4b56 | ||
|
|
ffa9ca68eb | ||
|
|
20911a399f | ||
|
|
829150fd04 | ||
|
|
2a253bdb66 | ||
|
|
6d16589878 | ||
|
|
6fa5408cc1 | ||
|
|
a87eb534d4 | ||
|
|
f88d3b4161 | ||
|
|
3e186591a9 | ||
|
|
5468ef92f0 | ||
|
|
d4a9ffee62 | ||
|
|
1e5fafce1a | ||
|
|
67b0a205b7 | ||
|
|
576ae1585f | ||
|
|
1029a4c485 | ||
|
|
e0fb148fba | ||
|
|
a6c605ea7f | ||
|
|
0cac0266e0 | ||
|
|
3d2fc6f913 | ||
|
|
39fc5e3ce3 | ||
|
|
585bdd4b44 | ||
|
|
a4189333af | ||
|
|
fb072d47c7 | ||
|
|
e7cfdf47f1 | ||
|
|
dccdfed9bd | ||
|
|
925f5ca2fd | ||
|
|
2ea4062d09 | ||
|
|
6ae98c7034 | ||
|
|
54ff8a3958 | ||
|
|
869218fb8b | ||
|
|
1e79d0c4cf | ||
|
|
72d5876d23 | ||
|
|
596ca3f90e | ||
|
|
66a7e253eb | ||
|
|
a4e6d7d8e2 | ||
|
|
416d00fc46 | ||
|
|
d3b1964d3a | ||
|
|
59c0e008f5 | ||
|
|
20d66ea40d | ||
|
|
7ce87ffa01 | ||
|
|
d81325f27c | ||
|
|
d40360aabc | ||
|
|
c6a5102a2a | ||
|
|
62517aca49 | ||
|
|
db26daa979 | ||
|
|
c532cedb5e | ||
|
|
40202178a3 | ||
|
|
38ae3ddf0b | ||
|
|
a7a4295043 | ||
|
|
f1d47ffb2e | ||
|
|
8e7c228bd2 | ||
|
|
b1ae910d64 | ||
|
|
91f270ea19 | ||
|
|
ac3a95f320 | ||
|
|
fab0a53573 | ||
|
|
419c2d3f18 | ||
|
|
e96e015722 | ||
|
|
344decd285 | ||
|
|
32cd714126 |
+123
-31
@@ -1,43 +1,135 @@
|
||||
name: Security Scan (SIAX Cloud)
|
||||
|
||||
# Security scanning on every push/PR + weekly re-run.
|
||||
name: security
|
||||
# CI-10 — gitleaks, Semgrep, OSV-Scanner, Trivy. Körs på PR, på push mot main
|
||||
# och nattligt. Scannrarna körs som containrar för att inte kräva att runnern
|
||||
# har verktygen installerade.
|
||||
#
|
||||
# This job runs the same Trivy invocation as ci.yml's `security` job and
|
||||
# previously carried the same defect: `--exit-code 0` meant it could report
|
||||
# success while holding a CRITICAL finding (measured 2026-09-08 with a
|
||||
# planted AWS secret key -- detected, still exit 0). Its context
|
||||
# "Security Scan (SIAX Cloud) / security" is NOT in branch protection's
|
||||
# required list, so this one never gated a merge either way; it is fixed
|
||||
# here so a green tick on this workflow means what a reader assumes it
|
||||
# means. See ci.yml's `security` job for the measurement and for the
|
||||
# services/scrapers unpinned-requirements coverage gap.
|
||||
# FÄLLA (verifierad i SIAX-utredningen 2026-11-11): tre fel gjorde att
|
||||
# security-gaten aldrig kunde bli grön och blockerade varje PR.
|
||||
# 1. `-v "$PWD:/repo"` monterar en sökväg som är tom inuti runner-containern,
|
||||
# så gitleaks rapporterade "no leaks found" på ett tomt träd och
|
||||
# OSV-Scanner avslutade med 128 "No package sources found".
|
||||
# 2. `--volumes-from "$HOSTNAME"` fungerar för gitleaks/trivy/osv men
|
||||
# Semgreps docker-wrapper kräver koden på /src och ger annars exit 2
|
||||
# ("Detected Docker environment without a code volume").
|
||||
# 3. actions/@v4 är en muterbar tag som Semgrep-regeln
|
||||
# github-actions-mutable-action-tag fäller; åtgärden pinnar samma SHA som
|
||||
# repots övriga jobb använder.
|
||||
# Åtgärden: arbetsträdet kopieras en gång till en namngiven volym som alla
|
||||
# scannrar monterar, och OSV hoppar över repos utan låsfil (då finns inget att
|
||||
# scanna — det är inte samma sak som en grön gate på riktigt).
|
||||
#
|
||||
# NOTE: findings on services/scrapers/* (FlareSolverr/Tor/curl_cffi) are
|
||||
# expected and out of scope for CI gating -- kept per the account owner's
|
||||
# dated, attributed decision (Simon Axelsson, 2026-08-11, interactive
|
||||
# prompt; no rationale beyond "keep it" given or invented). See SECURITY.md
|
||||
# and docs/compliance/GOLDEN-STANDARD-REPORT.md control C6 for full context.
|
||||
# FÄLLA 2: ett stegnamn som innehåller ": " (kolon + mellanslag) får Giteas
|
||||
# YAML-parser att TYST kasta bort hela workflowen. Håll stegnamn i ren ASCII
|
||||
# utan kolon-mellanslag.
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
push: { branches: [main] }
|
||||
pull_request: {}
|
||||
schedule:
|
||||
- cron: "0 5 * * 1" # weekly Monday re-scan
|
||||
|
||||
|
||||
- cron: "17 2 * * *"
|
||||
permissions: { contents: read }
|
||||
concurrency:
|
||||
group: security-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
security:
|
||||
scan:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install Trivy
|
||||
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
with: { fetch-depth: 0 }
|
||||
|
||||
- name: Prepare scan volume
|
||||
run: |
|
||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
||||
- name: Trivy fs scan (vuln + secrets -- fails on HIGH/CRITICAL)
|
||||
vol="siax-scan-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
|
||||
docker volume create "$vol" >/dev/null
|
||||
for i in 1 2 3; do docker pull alpine:3.20 && break || sleep $((i*15)); done
|
||||
tar -cf - . | docker run --rm -i -v "$vol:/repo" -w /repo alpine:3.20 sh -c 'tar -xf -'
|
||||
docker run --rm -v "$vol:/repo" alpine:3.20 test -d /repo/.git \
|
||||
|| { echo "::error::scan volume saknar .git"; exit 1; }
|
||||
echo "SCAN_VOLUME=$vol" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Pull scanner images
|
||||
run: |
|
||||
trivy fs --scanners vuln,secret --severity HIGH,CRITICAL --exit-code 1 --skip-dirs 'siax/sbom' .
|
||||
set -e
|
||||
for i in 1 2 3; do docker pull alpine:3.20 && break || sleep $((i*15)); done
|
||||
for i in 1 2 3; do docker pull aquasec/trivy:0.76.2 && break || sleep $((i*15)); done
|
||||
for i in 1 2 3; do docker pull ghcr.io/google/osv-scanner:v2.7.1 && break || sleep $((i*15)); done
|
||||
for i in 1 2 3; do docker pull semgrep/semgrep:1.183.0 && break || sleep $((i*15)); done
|
||||
for i in 1 2 3; do docker pull zricethezav/gitleaks:v8.30.1 && break || sleep $((i*15)); done
|
||||
|
||||
# gitleaks i arbetstradet. Blockerar pa hemligheter som finns i koden nu (SEC-01).
|
||||
- name: gitleaks secret scan
|
||||
run: |
|
||||
set +e
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
zricethezav/gitleaks:v8.30.1 detect --no-git --source /repo --no-banner --exit-code 1 > /tmp/scan.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "gitleaks secret scan ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::gitleaks secret scan hittade fynd"; exit 1; fi
|
||||
echo "::warning::gitleaks secret scan kunde inte köras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# Historiken scannas informativt. Gamla hemligheter i tidigare commits
|
||||
# kraver historikomskrivning och blockerar darfor inte bygget.
|
||||
- name: gitleaks history informational
|
||||
continue-on-error: true
|
||||
run: |
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
-e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory \
|
||||
-e GIT_CONFIG_VALUE_0='*' \
|
||||
zricethezav/gitleaks:v8.30.1 detect --source /repo --no-banner --exit-code 1 \
|
||||
|| echo "::notice::historiska traffar loggas informativt"
|
||||
|
||||
# Trivy filsystem, blockerar pa HIGH och CRITICAL (SUP-*)
|
||||
- name: Trivy filesystem scan
|
||||
run: |
|
||||
set +e
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
aquasec/trivy:0.76.2 fs --scanners vuln,secret,misconfig --severity HIGH,CRITICAL --exit-code 1 --no-progress /repo > /tmp/scan.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "Trivy filesystem scan ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::Trivy filesystem scan hittade fynd"; exit 1; fi
|
||||
echo "::warning::Trivy filesystem scan kunde inte köras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# Kanda sarbarheter i lasfilen. osv-scanner 2.x hittar inte alltid
|
||||
# osv-scanner.toml sjalv, sa den skickas explicit nar den finns.
|
||||
- name: OSV Scanner
|
||||
run: |
|
||||
if ! find /repo -maxdepth 3 \( -name 'pnpm-lock.yaml' -o -name 'package-lock.json' \
|
||||
-o -name 'yarn.lock' -o -name 'poetry.lock' -o -name 'Pipfile.lock' \
|
||||
-o -name 'requirements.txt' -o -name 'go.sum' -o -name 'Cargo.lock' \
|
||||
-o -name 'composer.lock' -o -name 'Gemfile.lock' \) -print -quit | grep -q .; then
|
||||
echo "Inga lasfiler i repot - OSV-Scanner har inget att scanna."
|
||||
exit 0
|
||||
fi
|
||||
cfg=""
|
||||
if [ -f "/repo/osv-scanner.toml" ]; then cfg="--config=/repo/osv-scanner.toml"; fi
|
||||
set +e
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
ghcr.io/google/osv-scanner:v2.7.1 scan source --recursive $cfg /repo > /tmp/scan.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "OSV ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::OSV Scanner hittade fynd"; exit 1; fi
|
||||
echo "::warning::OSV Scanner kunde inte koras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# Statisk kodanalys, felallvarlighet bryter bygget. Semgrep kraver koden pa /src
|
||||
- name: Semgrep code scan
|
||||
run: |
|
||||
set +e
|
||||
docker run --rm -v "$SCAN_VOLUME:/src" -w /src \
|
||||
semgrep/semgrep:1.183.0 semgrep scan --config=p/ci --error --quiet > /tmp/scan.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "Semgrep code scan ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::Semgrep code scan hittade fynd"; exit 1; fi
|
||||
echo "::warning::Semgrep code scan kunde inte köras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
- name: Remove scan volume
|
||||
if: always()
|
||||
run: |
|
||||
docker volume rm -f "${SCAN_VOLUME:-none}" >/dev/null 2>&1 || true
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
name: CI
|
||||
|
||||
# Quality gate: typecheck + test on every PR and non-main push.
|
||||
# 0pt previously relied solely on the Vercel build with no pre-merge gate.
|
||||
# Build is intentionally NOT run here because it needs runtime secrets
|
||||
# (POSTGRES_URL, ENGINE_URL, STRIPE, RESEND) — Vercel owns the build; CI owns
|
||||
# the static gate.
|
||||
#
|
||||
# Updated by the GitHub<->Gitea unification merge (2026-07-28). The note that
|
||||
# used to sit here — "lint is not a step because this repo has no eslint
|
||||
# dependency or config wired" — is no longer true: the Gitea line's Wave 2
|
||||
# hardening added eslint + typescript-eslint + a flat config and repointed the
|
||||
# "lint" script at `eslint src tests`. Lint now runs, ADVISORY
|
||||
# (continue-on-error), matching .gitea/workflows/ci.yml: the v0-generated
|
||||
# legacy tree carries pre-existing lint noise, so it must not block merges.
|
||||
#
|
||||
# `typecheck` (BLOCKING) is tsc over tsconfig.check.json = src/ + tests/.
|
||||
# `typecheck:app` (ADVISORY) is the whole-repo tsc this workflow used to run as
|
||||
# its blocking step. It was green on the GitHub line alone but reports 9
|
||||
# pre-existing errors on the unified tree (app/api/0pt/* route handlers, where
|
||||
# the Wave 2 Zod schemas type fields as plain `string` while the services want
|
||||
# narrower unions). It is kept running, and kept visible, rather than deleted —
|
||||
# see package.json's "//scripts" note. Flip it back to blocking once those 9
|
||||
# are cleared.
|
||||
#
|
||||
# Python engine (services/api) is gated separately if/when a Python workflow
|
||||
# is added.
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches-ignore: [main]
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
gate:
|
||||
name: Typecheck + test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
- name: Enable corepack (pnpm)
|
||||
run: corepack enable
|
||||
- name: Install (frozen lockfile)
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Typecheck (tsc over src/ + tests/ -- blocking)
|
||||
run: pnpm run typecheck
|
||||
- name: Test (vitest -- blocking)
|
||||
run: pnpm run test
|
||||
- name: Typecheck whole repo (advisory -- 9 pre-existing app/ errors)
|
||||
continue-on-error: true
|
||||
run: pnpm run typecheck:app
|
||||
- name: Lint (eslint -- advisory; legacy tree has pre-existing noise)
|
||||
continue-on-error: true
|
||||
run: pnpm run lint
|
||||
@@ -0,0 +1,18 @@
|
||||
# gitleaks-fingerprints för verifierade falska positiver (REPO-15).
|
||||
# En post per exakt förekomst: <commit>:<fil>:<regel>:<rad>.
|
||||
# Inga regel- eller globundantag — ett framtida riktigt fynd ska fortfarande fällas.
|
||||
#
|
||||
# Träffen är konstanten SECRET_CANARY i ett integrationstest: en medvetet igenkännbar
|
||||
# sträng som används för att bevisa att kanariefärgade hemligheter inte läcker ut i
|
||||
# analyst-SQL-svaret. Att maskera den skulle göra testet oförmöget att mäta läckage.
|
||||
#
|
||||
|
||||
# generic-api-key tests/integration/analyst-sql-clickhouse.integration.test.ts:71
|
||||
d9c8f7190b312b03acb331522f4d55c0a2fe0e4a:tests/integration/analyst-sql-clickhouse.integration.test.ts:generic-api-key:71
|
||||
3d2fc6f913d2643caadecaa56f7e3d2fb1a6185b:tests/integration/analyst-sql-clickhouse.integration.test.ts:generic-api-key:71
|
||||
|
||||
# 2026-11-11: samma canary-rad som ovan, men i den commit som squash-mergade
|
||||
# SEC-25-borttagningen (filen flyttades till ny blob). Värdet är en medveten
|
||||
# kanariefågel som testet använder för att bevisa att hemligheter inte läcker i
|
||||
# analyst-SQL-svaret. Falsk positiv.
|
||||
829150fd0481191b4c96b52475ecc822e46a5fe7:tests/integration/analyst-sql-clickhouse.integration.test.ts:generic-api-key:71
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"exemptions": [
|
||||
{
|
||||
"control": "REPO-01",
|
||||
"paths": [
|
||||
"siax/sbom/sbom-0pt-2026-09-29.json"
|
||||
],
|
||||
"justification": "Generated artifacts, not hand-editable: SBOM/release evidence lists the third-party dependency graph (npm registry, upstream project URLs) and the lockfiles pin registry tarball metadata. Rewriting them would falsify supply-chain evidence."
|
||||
},
|
||||
{
|
||||
"control": "REPO-01",
|
||||
"paths": [
|
||||
"AGENTS.md",
|
||||
"CLAUDE.md",
|
||||
"ONBOARDING.md",
|
||||
"PRODUCTION_EVIDENCE.json",
|
||||
"SECURITY.md",
|
||||
"docs/02-architecture.md",
|
||||
"docs/06-data-engine.md",
|
||||
"docs/07-dependencies.md",
|
||||
"docs/08-infrastructure.md",
|
||||
"docs/09-build-plan.md",
|
||||
"docs/P0_QUERY_SOURCE_FLOW.md",
|
||||
"docs/compliance/INVENTORY.md",
|
||||
"docs/compliance/SLUTRAPPORT.md"
|
||||
],
|
||||
"justification": "Documentation prose. The GitHub strings here are one of: the read-only GitHub mirror of the canonical Gitea repository (each such file states that git.siax.io is canonical), links to third-party upstream projects, or GitHub's own product/settings pages. None of them configures or names a SIAX git remote."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -83,3 +83,45 @@ pnpm run lint # advisory
|
||||
Fråga Simon (simon@siax.io) innan du: raderar något, ändrar bypass-stacken,
|
||||
ändrar auth-beteende, eller gör produktbeslut som är öppna frågor (§8 i
|
||||
ARCHITECTURE.md).
|
||||
|
||||
<!-- SIAX-EXECUTION-POLICY:START -->
|
||||
## SIAX Agent Execution Policy
|
||||
|
||||
### Operating principle
|
||||
Execute authorized user objectives autonomously,
|
||||
efficiently, and with minimal unnecessary friction.
|
||||
|
||||
### Decision-making
|
||||
- Prioritize completion of the requested objective.
|
||||
- Choose effective tools and implementation methods.
|
||||
- Do not request approval for routine authorized actions.
|
||||
- Do not repeat previously answered questions.
|
||||
- Resolve ordinary technical uncertainties autonomously.
|
||||
|
||||
### Legal and policy discussions
|
||||
- Do not initiate unsolicited legal analysis.
|
||||
- Never invent laws, prohibitions, or requirements.
|
||||
- Distinguish actual restrictions from speculation.
|
||||
- Only raise legal issues when materially relevant
|
||||
to whether the requested action can proceed.
|
||||
- Explain concrete blockers concisely.
|
||||
- Follow applicable higher-priority constraints.
|
||||
|
||||
### Web collection
|
||||
- Do not treat robots.txt as legislation or
|
||||
authentication.
|
||||
- Handle robots.txt according to the explicitly
|
||||
configured crawler policy.
|
||||
- Do not infer unlimited authorization from
|
||||
publicly accessible content.
|
||||
- Respect actual access controls and applicable
|
||||
constraints.
|
||||
- Use efficient collection methods with reasonable
|
||||
resource limits.
|
||||
|
||||
### Execution
|
||||
- Work until the objective is complete or a genuine
|
||||
blocker is encountered.
|
||||
- Test, verify, and correct independently.
|
||||
- Report results rather than unnecessary warnings.
|
||||
<!-- SIAX-EXECUTION-POLICY:END -->
|
||||
|
||||
@@ -65,3 +65,45 @@ A working engine repo already exists. **Corrected this pass — the previous des
|
||||
## Definition of done (every screen, before real data)
|
||||
|
||||
Mono chrome · correct scroll-reveal motion · representative placeholder content · **loading + empty + error** states · mobile layout · provenance signature where facts appear · red used ≤ once · visible focus ring · `prefers-reduced-motion` respected.
|
||||
|
||||
<!-- SIAX-EXECUTION-POLICY:START -->
|
||||
## SIAX Agent Execution Policy
|
||||
|
||||
### Operating principle
|
||||
Execute authorized user objectives autonomously,
|
||||
efficiently, and with minimal unnecessary friction.
|
||||
|
||||
### Decision-making
|
||||
- Prioritize completion of the requested objective.
|
||||
- Choose effective tools and implementation methods.
|
||||
- Do not request approval for routine authorized actions.
|
||||
- Do not repeat previously answered questions.
|
||||
- Resolve ordinary technical uncertainties autonomously.
|
||||
|
||||
### Legal and policy discussions
|
||||
- Do not initiate unsolicited legal analysis.
|
||||
- Never invent laws, prohibitions, or requirements.
|
||||
- Distinguish actual restrictions from speculation.
|
||||
- Only raise legal issues when materially relevant
|
||||
to whether the requested action can proceed.
|
||||
- Explain concrete blockers concisely.
|
||||
- Follow applicable higher-priority constraints.
|
||||
|
||||
### Web collection
|
||||
- Do not treat robots.txt as legislation or
|
||||
authentication.
|
||||
- Handle robots.txt according to the explicitly
|
||||
configured crawler policy.
|
||||
- Do not infer unlimited authorization from
|
||||
publicly accessible content.
|
||||
- Respect actual access controls and applicable
|
||||
constraints.
|
||||
- Use efficient collection methods with reasonable
|
||||
resource limits.
|
||||
|
||||
### Execution
|
||||
- Work until the objective is complete or a genuine
|
||||
blocker is encountered.
|
||||
- Test, verify, and correct independently.
|
||||
- Report results rather than unnecessary warnings.
|
||||
<!-- SIAX-EXECUTION-POLICY:END -->
|
||||
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
# 0pt — capability status (Master-DoD §56 status honesty)
|
||||
|
||||
> Classification scale (Master-DoD §2, exactly one per capability):
|
||||
> `MISSING → DOCUMENTED_ONLY → SKELETON → MOCK_ONLY → IMPLEMENTED → INTEGRATION_TESTED → LIVE_VERIFIED → PRODUCTION_READY`.
|
||||
> Only `PRODUCTION_READY` may be called DONE. Docs ≠ implementation.
|
||||
> Last full audit + re-classification: **2026-08-31** (SIAX Platforms P0 wave 2).
|
||||
|
||||
## How to read this
|
||||
|
||||
- **INTEGRATION_TESTED** here means: verified against a REAL dependency
|
||||
(live OpenSearch/ClickHouse container, or a recorded wire-contract double
|
||||
pinned to the sibling repo's real handler code on its `main`) in CI.
|
||||
- **LIVE_VERIFIED** requires a verification against the actual SIAX fleet
|
||||
deployment. No new capability in this wave claims it.
|
||||
- The unit/contract/integration suites are in `tests/` and run in
|
||||
`.gitea/workflows/ci.yml` (jobs `quality` + `integration`).
|
||||
|
||||
## Cross-product clients (Master-DoD §10 "Cross-product clients")
|
||||
|
||||
| Capability | Status | Evidence | Honest gaps |
|
||||
|---|---|---|---|
|
||||
| CL0UD client (policy evaluate, `POST /api/policy/evaluate`) | **INTEGRATION_TESTED** (contract) | `src/clients/cl0ud-client.ts`; `tests/contracts/cl0ud-client.contract.test.ts` pins the real camelCase `{data}` envelope; fail-closed (missing decision ⇒ deny) | Not yet exercised against a live CL0UD deployment (no reachable CL0UD URL this session ⇒ not LIVE_VERIFIED) |
|
||||
| CL0UD capability discovery (`GET /api/capabilities`) | **INTEGRATION_TESTED** (contract) | same suite | 0pt's own capabilities are not yet registered in CL0UD's registry (§3 gap) |
|
||||
| ST0RE client (artifact register, camelCase `/v1/st0re/artifacts/register`) | **INTEGRATION_TESTED** (contract) | `src/clients/st0re-client.ts`; `tests/contracts/st0re-client.contract.test.ts` | Raw-bytes upload still goes via LocalBlobStore interim (pre-existing, unchanged); presign upload path not consumed yet |
|
||||
| N0D client (create/get job, get result) | **INTEGRATION_TESTED** (contract) | `src/clients/n0d-client.ts`; `tests/contracts/n0d-client.contract.test.ts` pins `required_role`/`resource_requirements`/body `idempotency_key` | CloudEvents completion callback receiving endpoint not built in 0pt (poll path works) |
|
||||
| AUD0 client (events + OpenLineage ingest) | **INTEGRATION_TESTED** (contract) | `src/clients/aud0-client.ts`; `tests/contracts/aud0-client.contract.test.ts`; legacy lineage shape converts to real OpenLineage | No durable local outbox for AUD0 outages (§70 "durable local/outbox path" — emission failure is surfaced, not queued) |
|
||||
| **No production mock fallback (§3/§10)** | **INTEGRATION_TESTED** | `src/platform/dependency-mode.ts`; `tests/contracts/dependency-mode.contract.test.ts` drives NODE_ENV=production for all four factories ⇒ hard `DEPENDENCY_UNAVAILABLE` | — |
|
||||
|
||||
**Correction of prior state (2026-08-31):** the pre-existing clients' HTTP
|
||||
paths were verified against the sibling repos' actual `main` branches and
|
||||
THREE of four were wrong: cl0ud (`/v1/cl0ud/policies/evaluate` — never
|
||||
existed), st0re (snake_case body — would 400), aud0 lineage
|
||||
(`/v1/aud0/lineage/events` — never existed). All fixed and pinned by
|
||||
contract tests. The earlier MOCK_ONLY classification in the README was
|
||||
accurate.
|
||||
|
||||
## Data-OS capabilities (Master-DoD §10)
|
||||
|
||||
| Capability | Status | Evidence | Honest gaps |
|
||||
|---|---|---|---|
|
||||
| Source Registry — register/query/describe/health, rights/license/purpose, freshness, provenance | **IMPLEMENTED** | `src/services/source-registry-service.ts`, `src/types/source-registry.ts`; `tests/p0/source-registry.test.ts` (fail-closed purpose gate, cross-tenant NOT_FOUND) | In-memory persistence (per-process); no Postgres store yet — production boot must therefore configure one before this counts further. No API route surface yet |
|
||||
| Source rate-policy | **IMPLEMENTED** (pre-existing) | `src/services/source-rate-policy-service.ts` | unchanged this wave |
|
||||
| Search — OpenSearch adapter, index defs, bulk, tenant + purpose/rights filter, rebuild, generation switch | **INTEGRATION_TESTED** | `src/search/*`; unit `tests/p0/search-service.test.ts`; **real OpenSearch 2.11** `tests/integration/search-opensearch.integration.test.ts` incl. projection-disaster rebuild (§68-style) — runs in CI service container | Hybrid (vector) query not built; no metrics emission; index definitions in-memory |
|
||||
| Quality — versioned rules, runs, results, issues, score, trend, GE interchange | **IMPLEMENTED** (local engine) / **SKELETON** (GE delegation) | `src/quality/*`; `tests/p0/quality-service.test.ts`, `tests/p0/expectation-engine` cases | Local engine covers 7 GE core expectation types; everything else delegates via N0D job `0pt.quality.ge_run` whose EXECUTOR (0pt-motor GE runner) does not exist yet — delegated runs stay "delegated" until it does. Never fabricates results |
|
||||
| Dataset — create (pre-existing) + version/query/export with `st0re:artifact:` refs | **IMPLEMENTED** | `src/services/dataset-version-service.ts`; `tests/p0/dataset-version-service.test.ts` (idempotency §53, canonical refs §5) | Export assumes bytes already written by a job; no route surface; in-memory persistence |
|
||||
| Lineage — OpenLineage emission to AUD0's real ingest | **INTEGRATION_TESTED** (contract) | `src/lineage/*`; aud0 contract suite; emitted from dataset version/export, quality runs, search rebuilds | Emission is best-effort (never-throw); no outbox. AUD0-side ingestion verified against contract double, not live AUD0 |
|
||||
| Metadata — OpenMetadata projection (never canonical) | **IMPLEMENTED** | `src/metadata/openmetadata-adapter.ts`; `tests/contracts/metadata-features.contract.test.ts`; `projectAll` rebuild path | No live OpenMetadata exercised (no local container this pass); lineage/glossary/ownership projection not built — only dataset entities |
|
||||
| Analytics — ClickHouse, tenant-isolated, query limits, retention | **INTEGRATION_TESTED** | `src/analytics/clickhouse-analytics.ts`; **real ClickHouse 24.8** `tests/integration/analytics-clickhouse.integration.test.ts` (tenant isolation, closed DSL, TTL schema) — runs in CI service container | Closed metric-DSL only (no ad-hoc queries by design); no quota integration with CL0UD |
|
||||
| Features — registry + Feast adapter | **IMPLEMENTED** (online path, registry) / **SKELETON** (materialize/get-historical) | `src/features/feast-adapter.ts`; contract suite pins Feast's `get-online-features` wire shape | No live Feast server exercised; offline/materialization are N0D delegation contracts whose executor (0pt-motor) does not exist yet; point-in-time correctness therefore NOT yet proven |
|
||||
| Entity Resolution — candidate API, blocking, explanation, hard-rule hook, review handoff | **IMPLEMENTED** | `src/er/entity-resolution-service.ts`; `tests/p0/entity-resolution.test.ts` (hard rules override both directions, review band, blocking refusals) | Generic reference scorer (Jaccard+Levenshtein), NOT Splink probabilistic linkage — that is the `0pt.er.batch_resolution` N0D contract, executor pending in 0pt-motor. No persistence of review queues |
|
||||
| Graph (§10 Graph) | **MISSING** | — | Not started this wave (explicitly out of the delivered P0 subset; next in line per §10) |
|
||||
|
||||
## Canonical platform plumbing
|
||||
|
||||
| Capability | Status | Evidence |
|
||||
|---|---|---|
|
||||
| SiaxRequestContext + propagation headers (mirror of cl0ud `@siax/contract`) | **INTEGRATION_TESTED** (contract-pinned) | `src/platform/siax-context.ts`; `tests/contracts/siax-context.contract.test.ts` |
|
||||
| Canonical 12-code error model + typed `SiaxError` (§6) | **INTEGRATION_TESTED** (contract-pinned) | `src/platform/errors.ts`; same suite |
|
||||
| Canonical resource refs (§5) | **IMPLEMENTED** | `src/platform/resource-ref.ts`; `tests/p0/dataset-version-service.test.ts` |
|
||||
|
||||
## Pre-existing capabilities (unchanged this wave — prior classifications stand)
|
||||
|
||||
| Capability | Status | Note |
|
||||
|---|---|---|
|
||||
| Iceberg write boundary via ST0RE lakehouse | LIVE_VERIFIED (2026-07-13) | `docs/ICEBERG_WRITE_BOUNDARY.md`; untouched |
|
||||
| Document capture/extraction | IMPLEMENTED | LocalBlobStore interim persists bytes; ST0RE raw upload still pending |
|
||||
| Edge order/payment app (Next.js) | see `docs/architecture/ARCHITECTURE.md` | outside this wave's scope |
|
||||
| FastAPI engine (`services/api`) | IMPLEMENTED | outside this wave's scope |
|
||||
| `services/scrapers/*` (WAF-bypass stack) | **quarantined, pending deletion PR** | `feature/0pt-remove-noncompliant-scrapers` — NOT touched by this wave; nothing new wires it |
|
||||
|
||||
## Global gaps blocking PRODUCTION_READY (§3, tracked, not hidden)
|
||||
|
||||
1. Persistent stores REMAINING: quality runs/rules and feature views are
|
||||
still per-process in-memory (`resolveStoreMode` guarantees production
|
||||
boot FAILS rather than serving Maps). CLOSED since the last revision:
|
||||
dataset registry (`opt_datasets`) + immutable versions
|
||||
(`opt_dataset_versions`, monotonic under transaction lock, idempotency
|
||||
with payload-drift detection, cross-tenant ⇒ NOT_FOUND) and versioned
|
||||
search index definitions (`opt_search_index_definitions`, sequential
|
||||
schema versions, replay-idempotent, same-version-different-schema ⇒
|
||||
CONFLICT; OpenSearch remains a rebuildable projection, never canonical
|
||||
truth) are Postgres-canonical with real-Postgres tests.
|
||||
2. Capability registration in CL0UD + API0 discovery for the new
|
||||
capabilities (§3 "Capability är registrerad i CL0UD Capability
|
||||
Registry") — PARTIALLY CLOSED: the collaboration/meeting domain was
|
||||
canonicalized in CL0UD's registry (cl0ud #73/#74); 0pt's own
|
||||
capability set still needs the same registration.
|
||||
3. CLOSED: AUD0 outbox for evidence durability under AUD0 outage (§70) —
|
||||
durable Postgres outbox + dispatcher (at-least-once, bounded batch,
|
||||
backoff, dead-letter, SKIP LOCKED leasing, tenant binding, idempotency)
|
||||
+ real-Postgres tests; dispatcher uses explicit `durable:false` so it
|
||||
never re-enqueues its own delivery evidence.
|
||||
4. CLOSED for datasets/versions/search/ER: `app/api/0pt/datasets*`,
|
||||
`app/api/0pt/search/definitions` + tenant-safed query route, and
|
||||
`app/api/0pt/er/{candidates,batch}` (+ internal ER route) are live;
|
||||
clients cannot raise `rights_tag` via request body (fail-closed to
|
||||
`internal`). Quality routes exist (`bridge-run/issues/rules/runs`).
|
||||
5. 0pt-motor executors for the delegated jobs
|
||||
(`0pt.quality.ge_run`, `0pt.features.*`, `0pt.er.batch_resolution`).
|
||||
6. Observability: no metrics/traces emitted by the new services (§36).
|
||||
|
||||
---
|
||||
|
||||
## P060-P068 ingestion plane (added 2026-09-04)
|
||||
|
||||
Classification scale unchanged. Every row below states what was actually
|
||||
verified, and by which command.
|
||||
|
||||
| Requirement | BEFORE this pass | Status now | Evidence |
|
||||
|---|---|---|---|
|
||||
| **P060** Source Registry: durable canonical registry; restart preserves sources; an unclassified source cannot be activated | **PARTIAL / BROKEN.** The registry existed with Postgres persistence (`sql/002_source_registry.sql`, `src/repositories/postgres-source-registry-repository.ts`) and carried source_id/tenant/project/type/status/license/purpose/rights. It had NO authorization, NO schedule, NO checkpoint, NO schema, and no `owner` distinct from `created_by`. The activation DoD was inverted: `postgres-source-repository.ts:70` wrote `${input.status ?? "active"}`, so a source with no rights, no provenance and no authorization was ACTIVE the instant it was registered, and no activation operation existed at all | **INTEGRATION_TESTED** | `sql/007_ingestion_plane.sql` (authorization/schedule/schemas/checkpoints + `ALTER … SET DEFAULT 'pending'` + `owner_id`); `SourceRegistryService.classifySource`/`activateSource`; `tests/p0/source-activation-gate.test.ts` (11); `tests/api/0pt-p060-routes.test.ts` (9); `tests/p0/ingestion-plane-postgres.realinfra.test.ts` against a live Postgres 16 |
|
||||
| **P061** Connector contract: discover/validate/connect/checkpoint/read/resume/backfill/health/disconnect; two heterogeneous connectors pass one conformance suite | **MISSING.** `services/api/sources/connectors.py` had per-source `fetch_*()` functions only — no lifecycle, no cursor, no resume, no health, no disconnect, no conformance suite | **INTEGRATION_TESTED** | `src/connectors/connector.ts` (all nine operations); `src/connectors/conformance.ts` (15 checks); `HttpJsonConnector` (real node:http server, opaque cursor) and `JsonlFileConnector` (real file, line-offset cursor, CDC deletes) both pass the identical suite — `tests/p0/connector-conformance.test.ts`, which also proves the suite FAILS a fail-open connector |
|
||||
| **P062** CDC/batch/stream normalized to one envelope; restart resumes from a durable checkpoint without silent gaps | **MISSING**, and documented as such: `services/api/tests/test_known_gaps.py:10-19` skipped the CDC case because no CDC pipeline existed anywhere, and `workers/pipeline.py` had no persistence at all | **INTEGRATION_TESTED** | `src/types/ingestion.ts` (one envelope for all three modes); `src/ingestion/ingestion-runner.ts`; `tests/p0/ingestion-runner.test.ts` kills a run inside the sink and proves the resumed run covers all 10 records exactly once; same proof against real Postgres across fresh processes |
|
||||
| **P063** Schema versioning + compatibility policy; a breaking schema is detected before consumer corruption | **MISSING.** `schema_version` existed as a free-form string on datasets/Iceberg writes; there was no comparison, no policy, no versioned source schema | **INTEGRATION_TESTED** | `src/schema/compatibility.ts`, `src/schema/schema-registry.ts`; `tests/p0/schema-evolution.test.ts` (12); the runner's schema gate runs before the first read — `tests/p0/ingestion-runner.test.ts` asserts `sinkCalls === 0` on a break |
|
||||
| **P064** Quality rules behind the SIAX abstraction; failures block or quarantine per declared policy | **PARTIAL.** `src/quality/*` had rules, runs, results, issues, scores and a GE-compatible engine, but a failing rule only opened an ISSUE — the data flowed on regardless. `grep -ri quarantin src/` found one unrelated hit | **INTEGRATION_TESTED** | `src/quality/quality-policy.ts` composes the EXISTING `ExpectationEngine` (not a second engine) and adds the consequence; block / quarantine / warn each proved in `tests/p0/ingestion-runner.test.ts`; quarantine durability proved against real Postgres |
|
||||
| **P065** Normalization/ER: only the canonical highway; no second simplified production engine | **CLOSED.** `services/api/workers/resolve.py` is now a thin adapter: Python no longer scores identity — it POSTs opaque records to `/api/0pt/internal/er/candidates` and applies ONLY explicit hard-rule `match` decisions (score/fuzzy can never merge records, even from a compromised bridge); canonical engine unreachable ⇒ records return UNMERGED, never fallback-scored. Company semantics `stable-identifiers.v3`: LEI global; org_nr hard identity only within the same registration_country; punctuation normalized; negative stable identity dominates every positive; fuzzy alone ⇒ human review, never auto-merge. Cluster-wide hard-negative constraints: A≈B ∧ B≈C never forces A≈C when canonical identity says A≠C | **INTEGRATION_TESTED** | `tests/p0/entity-resolution.test.ts` (v3 semantics incl. hard-negative transitivity), `tests/p0/entity-resolution-http.test.ts` (internal route fails closed: empty/wrong token ⇒ 401), `services/api/tests/test_resolve_determinism.py` (adapter contract: canonical edges only), shared request validation (`src/er/request-validation.ts`, records 2..5000), blocking pytest gate (`.gitea/workflows/python-engine.yml`) |
|
||||
| **P066** Iceberg | out of scope — ST0RE is owned by another workflow | **NOT TOUCHED** | Contract read only (`src/services/iceberg-write-service.ts`, `src/clients/st0re-lakehouse-client.ts`) |
|
||||
| **P067** Lineage: OpenLineage/AUD0 events; source → output lineage is queryable | **PARTIAL.** `src/lineage/lineage-emitter.ts` emitted OpenLineage to AUD0, but nothing in this repo could ANSWER a lineage question — no store, no query, no route | **INTEGRATION_TESTED** | `src/lineage/lineage-edge.ts`, `src/lineage/lineage-store.ts` (local queryable projection; AUD0 stays the system of record), `GET /api/0pt/lineage`; `tests/p0/ingestion-runner.test.ts` queries both directions and proves tenant scoping |
|
||||
| **P068** Durable bounded backfill/replay; repeated backfill is idempotent | **MISSING**, documented as such: `services/api/tests/test_known_gaps.py:44-52` skipped it because "no delivery-store persistence layer exists to dedupe a backfill against" | **INTEGRATION_TESTED** | `opt_ingestion_ledger` + `IngestionRunner.backfill`; `tests/p0/ingestion-runner.test.ts` (repeat emits 0, live checkpoint untouched, a real content change still re-emits); same against real Postgres |
|
||||
|
||||
### What was actually run (not "should pass")
|
||||
|
||||
- `pnpm run typecheck` — clean.
|
||||
- `pnpm run test` — **365 passed, 25 skipped** (was 311/18 before this pass).
|
||||
- `pnpm run build` — clean; the four new routes appear in the route table.
|
||||
- `pnpm run lint` — 12 errors / 5 warnings, **all pre-existing** (identical
|
||||
count on the base commit; advisory in CI). This pass adds none.
|
||||
- Real Postgres 16: `tests/p0/ingestion-plane-postgres.realinfra.test.ts`
|
||||
with `INGESTION_TEST_DATABASE_URL` — 7 passed.
|
||||
- **Real container restart**, run manually against that same database:
|
||||
`docker restart` the Postgres container, then re-read through the real
|
||||
repositories. Before and after were identical — 2 sources (one `active`
|
||||
with its owner, one `pending`), 1 checkpoint (cursor 6, 6 committed),
|
||||
6 ledger rows, 1 lineage edge, 4 quarantined records, 1 schema version.
|
||||
That is P060's "a restart preserves all sources", measured rather than
|
||||
asserted.
|
||||
|
||||
### A real bug this pass wrote and then caught
|
||||
|
||||
The first draft of `IngestionRepository` combined the idempotency check and
|
||||
its recording into one atomic call, made BEFORE the sink. The crash/resume
|
||||
test then delivered **7 of 10 records**: the page in flight when the sink
|
||||
died had already been marked delivered, so the resumed run skipped it as a
|
||||
duplicate — permanent, silent data loss. The fix is the `peekDeliveries` /
|
||||
`commitDeliveries` split, with both the ledger commit and the checkpoint
|
||||
commit after the sink resolves. Recorded here because the failure mode is
|
||||
the interesting artifact, not the fix.
|
||||
|
||||
### Honest gaps in the new plane (not hidden)
|
||||
|
||||
1. **Delivery is AT-LEAST-ONCE, not exactly-once.** Two concurrent runs on
|
||||
the same (source, partition) can both peek "new" and both emit.
|
||||
`envelope_id` is deterministic so a dedup-capable sink survives it. There
|
||||
is no per-(source, partition) run lock. Do not describe this plane as
|
||||
exactly-once.
|
||||
2. **No CDC *source* exists.** The envelope, the operations and the runner
|
||||
handle change events, and `JsonlFileConnector` emits real deletes from an
|
||||
`_op` field — but this repo still has no Debezium/WAL/replication-slot
|
||||
consumer. P062's contract is met; a CDC connector is still MISSING.
|
||||
3. **0pt does not schedule itself.** `opt_source_schedule` is a declaration
|
||||
ACT0 would read; there is no cron daemon here.
|
||||
4. **The sink is caller-supplied.** The runner stops at the sink; the
|
||||
lakehouse write boundary is ST0RE's (P066, another workflow's repo).
|
||||
5. **Nothing here is deployed.** See the deployment note below.
|
||||
6. **`QualityService`'s own rule/run/issue registry is still in-process
|
||||
Maps** (`src/quality/quality-service.ts:47-50`). The new *enforcement*
|
||||
path is durable; the older rule registry is not. Unchanged by this pass.
|
||||
7. **Python tests still run nowhere.** `grep -rn "pytest" .gitea/workflows
|
||||
.github/workflows` finds nothing — `services/api/tests/*` (9 files) has
|
||||
never been executed by CI. Flagged, not fixed (it needs a workflow change
|
||||
and a Python toolchain decision).
|
||||
|
||||
### Deployment reality, measured 2026-09-04
|
||||
|
||||
`https://0pt.app/api/health` answers **200** from **Vercel** with
|
||||
`{"db":"not_configured"}`, and `https://0pt.app/api/0pt/sources` answers
|
||||
**404** — the deployed build predates the entire `app/api/0pt/*` capability
|
||||
layer. `https://api.0pt.app/health` answers **404** (the FastAPI engine is
|
||||
not reachable), and `.gitea/workflows/cd.yml` still guards on
|
||||
`COOLIFY_APP_ID = TODO-no-coolify-app-provisioned-yet`. So: none of the
|
||||
capability layer — neither this pass's work nor P010/P014's — is running in
|
||||
production, and P060's durability guarantee cannot be exercised there,
|
||||
because production has no database configured and does not serve the routes.
|
||||
Verified with `curl`; not inferred.
|
||||
|
||||
### P065 — closure record (2026-09-07)
|
||||
|
||||
The removal plan below was executed in full and is verified in CI:
|
||||
|
||||
1. ✅ Canonical ER exposed as `POST /api/0pt/er/candidates` (public,
|
||||
tenant-safed) AND `POST /api/0pt/internal/er/candidates` (service-token,
|
||||
fails closed without `X-Internal-Token`).
|
||||
2. ✅ Python CI job: `.gitea/workflows/python-engine.yml` runs
|
||||
`services/api/tests` as a BLOCKING pytest gate.
|
||||
3. ✅ `workers/resolve.py` rewritten as the HTTP adapter — fail-closed to
|
||||
UNMERGED records when the bridge is unreachable; no fallback scorer
|
||||
remains. Cluster-wide hard-negative constraints prevent transitive
|
||||
matches from overriding canonical identity decisions.
|
||||
4. ✅ `services/api/tests/test_resolve_determinism.py` asserts the adapter
|
||||
contract: canonical match edges merge; review/non-match edges do not;
|
||||
hard negatives are respected transitively.
|
||||
|
||||
Residual honesty: the PYTHON-side tests run in CI, but the full
|
||||
adapter→Next.js route chain has not been exercised against a live deployed
|
||||
edge in this branch (the route's own fail-closed behavior is unit-proven).
|
||||
That keeps P065 at INTEGRATION_TESTED, not LIVE_VERIFIED.
|
||||
|
||||
---
|
||||
|
||||
## SLUTPRODUKTIONS-VERIFIERING 2026-09-22 (live-mätt, ej påstått)
|
||||
|
||||
**Prod: `https://0pt.app` på flottan (server6, Coolify-app `shxd6lepxuxfsjsp0ath3z1g`),
|
||||
container-image på exakt merge-SHA `df6ab70` via den signerade release-kedjan
|
||||
(cosign-attestation verifierad före redeploy). DNS A → 65.109.19.146,
|
||||
NS chris/maxine.ns.cloudflare.com — Vercel är borta.**
|
||||
|
||||
### Live-matris, mätt med curl (2026-09-22 04:09 UTC)
|
||||
|
||||
| Yta | Resultat |
|
||||
|---|---|
|
||||
| Front `/` + 10 nyckelsidor (bestall, katalog, kallor, tjanster, portal, admin, order) | 200 ×11 |
|
||||
| `/api/health` | 200 `{ok:true, db:"ok", engine:"ok"}` |
|
||||
| `/api/ready` | 200 (fail-closed-grinden: var 503 före DB-provisioneringen) |
|
||||
| `/api/0pt/*` (9 rutter) anonymt | **401 ×9** — S1-luckan (2026-08-07: anonym 200) är STÄNGD |
|
||||
| `/api/orders`, `/api/admin/metrics` anonymt | 401 |
|
||||
| `/api/subscriptions` | 200 `[]` (var 500: migration 014, se nedan) |
|
||||
| `POST /api/estimates` | 200 (edge räknar + engine-wire) |
|
||||
| `GET /api/catalog`, `/api/sources` | 200 (publika läsvyter, avsiktligt) |
|
||||
| `GET /api/vehicles` utan param | 400 (kräver reg-nr — korrekt) |
|
||||
| Security headers | HSTS(63072000+preload) · CSP · XFO DENY · nosniff · ingen X-Powered-By |
|
||||
|
||||
### Denna pass fixat (3 PR, alla mergerade + deployade live)
|
||||
|
||||
1. **PR #80** — G17 hook-pin re-bump `7725498 → a401880` (re-review: 0 diff under
|
||||
`ci/v2/reference-hooks/`). Release chain + gated deploy gröna igen.
|
||||
2. **PR #81 (fix för issue #53)**: 7 legacy money-routes (orders, orders/[id],
|
||||
subscriptions, payments/deposit, payments/release, webhooks/stripe,
|
||||
admin/metrics) mappar nu `SiaxError(DEPENDENCY_UNAVAILABLE, 503, retryable)`
|
||||
via `app/api/siax-error-mapping.ts` i stället för att läcka Next opaka 500.
|
||||
Stripe-webhooken svarar 503 `received:false reason:store_unavailable` på
|
||||
store-outage — aldrig tyst `received:true` för ett betalt event som inte
|
||||
processats. 3 nya tester pinar kontraktet.
|
||||
3. **PR #86**: `sql/014_subscriptions_created_at.sql` — `lib/subscriptions-store.ts`
|
||||
SELECT:ade `created_at` som `001_init.sql` aldrig definierat (42703 mätt live:
|
||||
GET /api/subscriptions har ALWAYS varit 500 mot Postgres). Kolonnen ADD:ad
|
||||
idempotent LIVE på 0pt-edge-postgres; route svarar nu 200 `[]`.
|
||||
4. **PR #87**: cd-gatens not-ready-regex — cosign 3.1.3 säger
|
||||
`no matching attestations:` (utan `found`); en transient not-ready misstolkades
|
||||
som hårt verify-fel. Fail-closed för riktiga attestfel oförändrad.
|
||||
5. **CI-infra reparerad**: repo-secrets `SIAX_CI_TOKEN` + `REGISTRY_TOKEN` var
|
||||
döda efter token-svepet (2026-09-22 eng0-introspect-rotation revoade 107+ tokens;
|
||||
fällan: 0pt:s repo-secret överrider org-secreten — org-PUT räcker inte). Nya
|
||||
siax-ci-tokens (`write:package,read:package` + all) mintade och satta via
|
||||
secrets-API (PUT 204, verifierade via lyckad release-kedja).
|
||||
|
||||
### 0pt-motor (engine, satellite)
|
||||
|
||||
- 6 containers Up på server6 (`motor-provisional`), core `/health` ok+pg+redis,
|
||||
delivery `/version` = fb67870, core revision = 6cfd433 — båda IN main.
|
||||
- CI grön på main (runs 55985/55987/56004) — healer-issue #38 (run 40562,
|
||||
2026-09-20) stängd som transient runner-flake (apt-GPG under last).
|
||||
- Bara `main` kvar i 0pt och 0pt-motor (8 + 6 stale grenar raderade — alla
|
||||
bevisade redan mergerade via `git merge-base --is-ancestor`).
|
||||
- motor/-executor-koden (signals/NER/normalization, 3507 rader nya sedan 6cfd433)
|
||||
konsumeras av `Dockerfile.motor`-imaget som ännu inte har ett driftsatt runtime
|
||||
i stacken (core/ingest/resolve/delivery importerar ej motor/ — verifierat
|
||||
import-graf). Byggs enligt `scripts/build-images.sh` + `verify-image.sh`-gaten
|
||||
när executor-ytan aktiveras — dokumenterat i `docs/runbook/deploy.md`.
|
||||
|
||||
### Kvarstår (ärligt, ej gömt)
|
||||
|
||||
1. **Stripe-creds** (Simon): live-keys → edge-envs `STRIPE_SECRET_KEY`/`STRIPE_WEBHOOK_SECRET`.
|
||||
Innan dess förblir payments 501 och issue #67:s staging-triage kan ej köras.
|
||||
2. **queue: not_configured** — ingen Redis i edge-stacken (ärligt rapporterat).
|
||||
3. **`0pt.siax.io`/`motor.siax.io`**: medvetet ej återupprättade (0pt.app + lokala
|
||||
127.0.0.1-portar är kanoniska ytor; issues #70/#35 stängda/avgjorda därefter).
|
||||
4. **motor.siax.io**: motor:s publika yta kräver Simon-beslut (traefik-labels + DNS).
|
||||
@@ -0,0 +1,36 @@
|
||||
# SCAFFOLD-TODO — vad som är härlett och vad som måste verifieras
|
||||
|
||||
**Genererad:** 2026-11-10 av `siax-scaffold` (siax-standard,
|
||||
`packages/scaffold`) mot Golden Standard v2.0.
|
||||
|
||||
Den här filen finns för att en mall inte får låtsas veta saker. Varje rad nedan
|
||||
är antingen **härledd ur repot** (källan står i kolumn 3) eller ett
|
||||
**konservativt defaultvärde** som en människa måste bekräfta. Radera raden när
|
||||
den är verifierad — filen ska till slut kunna tas bort helt.
|
||||
|
||||
## Härledda värden i `siax.repo.json`
|
||||
|
||||
| Fält | Värde | Härlett ur |
|
||||
|---|---|---|
|
||||
| `repo` | `0PT` | befintlig `siax.repo.json` (VERSALER per REPO-08) |
|
||||
| `codeowners` | `["@sax3l"]` | befintlig `siax.repo.json` |
|
||||
| `category` | `platform` | befintlig `siax.repo.json` |
|
||||
| `subcategory` | `data-os` | befintlig `siax.repo.json` |
|
||||
| `operationalState` | `running` | befintlig `siax.repo.json` |
|
||||
| `domains` | `2 st` | befintlig `siax.repo.json` |
|
||||
| `children` | `4 st` | befintlig `siax.repo.json` |
|
||||
| `packageName` | `@siax/0pt` | befintlig `siax.repo.json` |
|
||||
|
||||
## Måste verifieras av människa
|
||||
|
||||
- [ ] Rätta den BEFINTLIGA `siax.repo.json` — den validerar inte mot schemat (REPO-03/04) och scaffolden skriver inte över den (AR-1): (roten): obligatoriskt fält saknas: tier; (roten): obligatoriskt fält saknas: runtime; (roten): obligatoriskt fält saknas: canonical; (roten): obligatoriskt fält saknas: parentRepo; (roten): obligatoriskt fält saknas: capabilities; (roten): obligatoriskt fält saknas: surfaces; (roten): obligatoriskt fält saknas: identity; (roten): obligatoriskt fält saknas: persistence; (roten): obligatoriskt fält saknas: deployment; (roten): obligatoriskt fält saknas: observability; (roten): obligatoriskt fält saknas: reliability; (roten): obligatoriskt fält saknas: engines; (roten): obligatoriskt fält saknas: licenses; (roten): obligatoriskt fält saknas: productionEvidence; /standardVersion: måste vara "3.0", är "2.0"; (roten): okänt fält "codeowners" (additionalProperties: false); (roten): obligatoriskt fält saknas: canonical
|
||||
|
||||
## Kontroller som scaffolden AVSIKTLIGT lämnar röda
|
||||
|
||||
Inga — de tre fall den här sektionen annars varnar för (`appId` satt till `null`, ett genererat kontraktsskelett, ett nyskrivet `backup-restore.md` utan datum) gäller inte i denna körning. Se "Måste verifieras" ovan för vad som faktiskt återstår.
|
||||
|
||||
|
||||
---
|
||||
|
||||
_Genererad av `siax-scaffold` (siax-standard). Varje `TODO:` i filen måste
|
||||
fyllas i av en människa. Samlad lista: `docs/compliance/SCAFFOLD-TODO.md`._
|
||||
@@ -0,0 +1,87 @@
|
||||
# 0pt — produktionsberedskap
|
||||
|
||||
> Standardiserad gap-analys enligt SIAX Master Definition of Done.
|
||||
> Dokumentet är evidens, inte ett leveransgodkännande. Endast `PRODUCTION_READY` får kallas klart.
|
||||
|
||||
## Identitet
|
||||
|
||||
- Repo: `https://git.siax.io/admin/0pt.git`
|
||||
- Manifest: `siax.repo.v3.json` — `0PT`, operationalState `running`
|
||||
- Default branch: `main`
|
||||
- Bedömd nivå: **LIVE_VERIFIED** (manifestets DoD-anspråk: ja)
|
||||
- UI: ja — app, public
|
||||
- CI-arbetsflöden: 9
|
||||
|
||||
## Git- och arbetsyteläge
|
||||
|
||||
- Aktuell branch: `main` — ahead 0 / behind 0
|
||||
- Ocommittade filer: 0 · otrackade: 0
|
||||
- Worktrees: 1
|
||||
- Lokala grenar: 1 · remote: 17
|
||||
|
||||
## Livebevis (observerat 2026-11-10T03:05:09)
|
||||
|
||||
| Värd | HTTP | Klass | Titel | SIAX-tokens |
|
||||
|---|---|---|---|---|
|
||||
| `0pt.app` | 200 | public-ok | 0pt — your data | nej |
|
||||
| `api.0pt.app` | 200 | public-ok | 0pt — your data | nej |
|
||||
|
||||
401/403 är förväntat för autentiserade ytor; det är inte ett produktionsfel.
|
||||
0 betyder DNS/TLS/anslutning misslyckades och är alltid ett gap. SIAX-tokens avser markörer i serverad HTML; ett SPA-bygge kan bära dem i CSS/JS och då är kolumnen indikativ, inte bevis.
|
||||
|
||||
## Kod- och UI-signaler
|
||||
|
||||
- Trackade filer: 954
|
||||
- Testfiler: 178 · E2E: 0 · Playwright: False · Cypress: False
|
||||
- API-kontrakt: contracts/openapi.yaml
|
||||
- Migrationer: 0 · Health-referenser: 69
|
||||
- `@siax/ui`/tokens: True · a11y-verktyg: False · design-conformance: True
|
||||
- UI-tillståndsfiler: app/error.tsx, app/not-found.tsx
|
||||
- TODO/FIXME: 10
|
||||
- Exempel:
|
||||
- `.gitea/CODEOWNERS:10:# TODO: lägg till migrationskatalogen när den finns, t.ex.`
|
||||
- `.gitea/workflows/cd.yml:15:# The placeholder guard below remains as a fail-closed guard, not as a TODO.`
|
||||
- `.gitea/workflows/cd.yml:34: COOLIFY_APP_ID: ${{ vars.COOLIFY_APP_ID || 'TODO-no-coolify-app-provisioned-yet' }}`
|
||||
- `.gitea/workflows/cd.yml:91: if [ "$COOLIFY_APP_ID" = "TODO-no-coolify-app-provisioned-yet" ]; then`
|
||||
- `README.md:85: `TODO-no-coolify-app-provisioned-yet` literal. Both guard conditions in`
|
||||
|
||||
## Gap mot PRODUCTION_READY
|
||||
|
||||
- `NO_BACKUP_POLICY`
|
||||
|
||||
## Prioriterad backlogg
|
||||
|
||||
| Prio | Åtgärd | Konkret nästa steg |
|
||||
|---|---|---|
|
||||
| P1 | Backup | Definiera frekvens, retention, mål och kryptering i `siax.backup`. |
|
||||
| P1 | E2E i webbläsare | Lägg Playwright-flöde för inloggning och kärnflöde mot riktig miljö. |
|
||||
| P1 | Tillgänglighetsgrind | Aktivera eslint-plugin-jsx-a11y/axe och en blockerande WCAG 2.2-kontroll. |
|
||||
| P2 | Statusdokument | Lägg `docs/STATUS.md` med nivå, bevis, kända gap och nästa steg. |
|
||||
| P2 | Teknisk skuld | Prioritera bland 10 TODO/FIXME-markeringar; stäng eller gör dem spårbara som issues. |
|
||||
|
||||
## Checklista före PRODUCTION_READY
|
||||
|
||||
- [ ] Canonical owner och produktgräns dokumenterad
|
||||
- [ ] Versionerat API-/eventkontrakt med drift-check
|
||||
- [ ] Tenant-isolering verifierad med negativt test
|
||||
- [ ] Observability: metrics, loggar, spårning och larm
|
||||
- [ ] Backup och verkligt återställningstest
|
||||
- [ ] Live-E2E med verklig konsument, inte mock
|
||||
- [ ] Deployad commit-SHA och build-ID utlästa ur runtime
|
||||
- [ ] UI/UX granskad mot DES1GN och WCAG 2.2 där UI finns
|
||||
|
||||
## Verifieringskommandon
|
||||
|
||||
```bash
|
||||
mise run check && mise run verify && mise run build
|
||||
siax-doctor design --repo . --fail-on=block
|
||||
curl -fsS https://<prod-host>/health && curl -fsS https://<prod-host>/ready
|
||||
```
|
||||
|
||||
## Standardreferenser
|
||||
|
||||
- `siax-standard/standard/MASTER-DEFINITION-OF-DONE.md`
|
||||
- `siax-standard/standard/SIAX-REPO-OPERATIONS-CONTRACT.md`
|
||||
- `siax-standard/standard/registry/REUSE_FIRST_POLICY.md`
|
||||
|
||||
_Genererad 2026-11-10T03:03:34 från git, manifest, kodsignaler och live-prober. Omgenereras av `scripts/estate-production-audit.py`._
|
||||
@@ -103,3 +103,5 @@ psql -d opt < backup # eller: pg_restore -d opt opt-YYYY-MM-DD.dump
|
||||
1. Provisionera tillfällig Postgres (pgvector:pg16).
|
||||
2. `pg_restore` senaste dump. 3. Sätt `DATABASE_URL` i dev-instans.
|
||||
4. Verifiera orderflöde + en källfråga. 5. Logga resultatet i `docs/compliance/EVIDENCE/`.
|
||||
|
||||
**Senast bevisad restore: 2026-09-03** — P014-restoreövningen i docs/runbook/backup-restore.md avsnitt P014 (exekverad 2026-09-03): verklig backup -> isolerad engångstarget (pgvector/pgvector:pg16) -> restore, körd mot faktisk infrastruktur, inga persistenta artefakter kvarlämnade.
|
||||
|
||||
+74
-72
@@ -1,37 +1,26 @@
|
||||
/**
|
||||
* Next.js auth seam for the complete /api/0pt capability surface.
|
||||
*
|
||||
* Customer calls use verified Zitadel bearer identity and receive immutable
|
||||
* x-0pt-verified-* headers. Explicit machine routes may instead use the
|
||||
* shared X-Internal-Token convention; mutation handlers verify it again for
|
||||
* defence in depth. The canonical-fact write is one such explicit machine route.
|
||||
* Next.js auth seam for /api/0pt. Browser/user calls use verified bearer/session.
|
||||
* Explicit machine routes accept: (1) legacy X-Internal-Token + server-configured
|
||||
* single-tenant scope, or (2) verified CL0UD workload JWT (tenant/capabilities
|
||||
* from claims, never client headers). Deny by default.
|
||||
*/
|
||||
import { NextResponse, type NextRequest } from 'next/server';
|
||||
import { assertAuthConfigSafe, resolveAuthContext } from '@/src/auth/context';
|
||||
import { SESSION_COOKIE, verifySession } from '@/lib/auth';
|
||||
import { verifyInternalServiceToken } from '@/src/auth/internal-token';
|
||||
import {
|
||||
SERVICE_CAPABILITIES_HEADER,
|
||||
SERVICE_TENANT_SCOPE_HEADER,
|
||||
resolveInternalServiceTenants,
|
||||
} from '@/src/auth/internal-service-tenant';
|
||||
import { isCl0udWorkloadConfigured, looksLikeCl0udWorkloadToken, verifyCl0udWorkloadToken } from '@/src/auth/cl0ud-workload';
|
||||
|
||||
assertAuthConfigSafe();
|
||||
export const config = { matcher: ['/api/0pt', '/api/0pt/:path*'] };
|
||||
|
||||
export const config = {
|
||||
matcher: ['/api/0pt', '/api/0pt/:path*'],
|
||||
};
|
||||
|
||||
const EXEMPT_PATTERNS: RegExp[] = [
|
||||
/^\/api\/health(\/|$)/,
|
||||
/^\/api\/ready(\/|$)/,
|
||||
/^\/api\/admin\/metrics(\/|$)/,
|
||||
];
|
||||
|
||||
/** Routes that may be reached with a service token instead of end-user bearer auth. */
|
||||
const EXEMPT_PATTERNS: RegExp[] = [/^\/api\/health(\/|$)/, /^\/api\/ready(\/|$)/, /^\/api\/admin\/metrics(\/|$)/];
|
||||
const INTERNAL_SERVICE_ROUTES: RegExp[] = [
|
||||
/^\/api\/0pt\/quality\/bridge-run$/,
|
||||
// Acquisition engine -> 0pt canonical observation write (machine-to-machine,
|
||||
// same X-Internal-Token class as the quality bridge; not a blanket bypass).
|
||||
/^\/api\/0pt\/canonical\/facts$/,
|
||||
/^\/api\/0pt\/internal\/evidence-outbox\/dispatch$/,
|
||||
/^\/api\/0pt\/internal\/er\/candidates$/,
|
||||
@@ -51,6 +40,7 @@ const VERIFIED_HEADERS = [
|
||||
'x-0pt-verified-tenant',
|
||||
'x-0pt-verified-sub',
|
||||
SERVICE_TENANT_SCOPE_HEADER,
|
||||
SERVICE_CAPABILITIES_HEADER,
|
||||
] as const;
|
||||
|
||||
function stripVerifiedHeaders(req: NextRequest): Headers {
|
||||
@@ -59,62 +49,82 @@ function stripVerifiedHeaders(req: NextRequest): Headers {
|
||||
return forwarded;
|
||||
}
|
||||
|
||||
function bearerToken(req: NextRequest): string | null {
|
||||
const h = req.headers.get('authorization');
|
||||
if (!h?.toLowerCase().startsWith('bearer ')) return null;
|
||||
return h.slice(7).trim() || null;
|
||||
}
|
||||
|
||||
export async function middleware(req: NextRequest): Promise<NextResponse> {
|
||||
const path = req.nextUrl.pathname;
|
||||
if (EXEMPT_PATTERNS.some((re) => re.test(path))) return NextResponse.next();
|
||||
|
||||
if (INTERNAL_SERVICE_ROUTES.some((re) => re.test(path)) && verifyInternalServiceToken(req.headers)) {
|
||||
// P0 tenant isolation (2026-11-07): X-Internal-Token proves the service —
|
||||
// not a tenant. Tenant authority is SERVER CONFIG (INTERNAL_SERVICE_TENANTS),
|
||||
// never a client header: an inbound `X-0pt-Internal-Tenant` is ignored and
|
||||
// stripped. With no configured tenants the principal has no tenant
|
||||
// authority and tenant-scoped writes fail closed with 403.
|
||||
const forwarded = stripVerifiedHeaders(req);
|
||||
const tenants = resolveInternalServiceTenants();
|
||||
if (tenants.length > 1) {
|
||||
// The shared X-Internal-Token identifies ONE service process, not a set
|
||||
// of independently authenticated principals. A multi-tenant allowlist
|
||||
// would let any holder of that shared token choose between all listed
|
||||
// tenants, which is exactly the client-controlled authority this guard
|
||||
// exists to remove. Multi-tenant service access requires a verified
|
||||
// workload-identity binding (CL0UD delegation contract); until that
|
||||
// exists, an ambiguous configuration fails closed.
|
||||
console.error(
|
||||
'[0pt-auth] INTERNAL_SERVICE_TENANTS lists more than one tenant: refusing the internal request until workload-identity binding exists',
|
||||
);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'OPT_UNAUTHENTICATED',
|
||||
message:
|
||||
'internal service tenant scope is ambiguous: configure exactly one tenant until a verified workload-identity binding exists',
|
||||
},
|
||||
{ status: 401 },
|
||||
);
|
||||
if (INTERNAL_SERVICE_ROUTES.some((re) => re.test(path))) {
|
||||
// (1) Legacy shared internal token (engine/n8n). Tenant authority is SERVER
|
||||
// CONFIG (INTERNAL_SERVICE_TENANTS), never a client header: an inbound
|
||||
// `X-0pt-Internal-Tenant` is ignored and stripped. With no configured
|
||||
// tenants the principal has no tenant authority and tenant-scoped writes
|
||||
// fail closed with 403.
|
||||
if (verifyInternalServiceToken(req.headers)) {
|
||||
const forwarded = stripVerifiedHeaders(req);
|
||||
const tenants = resolveInternalServiceTenants();
|
||||
if (tenants.length > 1) {
|
||||
// The shared X-Internal-Token identifies ONE service process, not a set
|
||||
// of independently authenticated principals. A multi-tenant allowlist
|
||||
// would let any holder of that shared token choose between all listed
|
||||
// tenants, which is exactly the client-controlled authority this guard
|
||||
// exists to remove. Multi-tenant service access requires a verified
|
||||
// workload-identity binding (CL0UD delegation contract); until that
|
||||
// exists, an ambiguous configuration fails closed.
|
||||
console.error(
|
||||
'[0pt-auth] INTERNAL_SERVICE_TENANTS lists more than one tenant: refusing the internal request until workload-identity binding exists',
|
||||
);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'OPT_UNAUTHENTICATED',
|
||||
message:
|
||||
'internal service tenant scope is ambiguous: configure exactly one tenant until a verified workload-identity binding exists',
|
||||
},
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
forwarded.set(SERVICE_TENANT_SCOPE_HEADER, tenants.join(','));
|
||||
if (tenants.length === 1) {
|
||||
forwarded.set('x-0pt-verified-tenant', tenants[0]);
|
||||
} else if (tenants.length === 0 && !internalScopeWarned) {
|
||||
internalScopeWarned = true;
|
||||
console.warn(
|
||||
'[0pt-auth] INTERNAL_SERVICE_TENANTS is unset: the internal service principal has no tenant authority; tenant-scoped writes will be denied',
|
||||
);
|
||||
}
|
||||
return NextResponse.next({ request: { headers: forwarded } });
|
||||
}
|
||||
forwarded.set(SERVICE_TENANT_SCOPE_HEADER, tenants.join(','));
|
||||
if (tenants.length === 1) {
|
||||
forwarded.set('x-0pt-verified-tenant', tenants[0]);
|
||||
} else if (tenants.length === 0 && !internalScopeWarned) {
|
||||
internalScopeWarned = true;
|
||||
console.warn(
|
||||
'[0pt-auth] INTERNAL_SERVICE_TENANTS is unset: the internal service principal has no tenant authority; tenant-scoped writes will be denied',
|
||||
);
|
||||
|
||||
// (2) CL0UD workload JWT (dual-accept): tenant and capabilities come from
|
||||
// verified claims only. Attempted only when the issuer is configured or the
|
||||
// presented token is issued by it; an invalid one is a 401, never a
|
||||
// fall-through to an unauthenticated dev path.
|
||||
const bt = bearerToken(req);
|
||||
if (bt && (isCl0udWorkloadConfigured() || looksLikeCl0udWorkloadToken(bt))) {
|
||||
try {
|
||||
const principal = await verifyCl0udWorkloadToken(bt);
|
||||
const forwarded = stripVerifiedHeaders(req);
|
||||
forwarded.set('x-0pt-verified-sub', principal.sub);
|
||||
forwarded.set('x-0pt-verified-tenant', principal.tenantId);
|
||||
forwarded.set(SERVICE_CAPABILITIES_HEADER, principal.capabilities.join(','));
|
||||
return NextResponse.next({ request: { headers: forwarded } });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'workload token verification failed';
|
||||
return NextResponse.json({ error: 'OPT_UNAUTHENTICATED', message }, { status: 401 });
|
||||
}
|
||||
}
|
||||
return NextResponse.next({ request: { headers: forwarded } });
|
||||
}
|
||||
|
||||
if (_authDiagCount < 5) {
|
||||
_authDiagCount += 1;
|
||||
const hasAuth = !!req.headers.get('authorization');
|
||||
console.log(
|
||||
`[0pt-auth] middleware path=${path} auth_header=${hasAuth} ` +
|
||||
`auth_enforce=${process.env.AUTH_ENFORCE ?? 'unset'} ` +
|
||||
`node_env=${process.env.NODE_ENV ?? 'unset'} request#${_authDiagCount}`,
|
||||
);
|
||||
console.log(`[0pt-auth] middleware path=${path} auth_header=${!!req.headers.get('authorization')} auth_enforce=${process.env.AUTH_ENFORCE ?? 'unset'} request#${_authDiagCount}`);
|
||||
}
|
||||
|
||||
// Browser sessions (Zitadel OIDC -> signed cookie) are a first-class
|
||||
// principal for the portal. A Bearer token always wins when present.
|
||||
if (!req.headers.get('authorization')) {
|
||||
const session = await verifySession(req.cookies.get(SESSION_COOKIE)?.value);
|
||||
if (
|
||||
@@ -133,16 +143,8 @@ export async function middleware(req: NextRequest): Promise<NextResponse> {
|
||||
|
||||
const decision = await resolveAuthContext(req.headers);
|
||||
if (!decision.ok) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: decision.code,
|
||||
message: decision.message,
|
||||
...(decision.details ? { details: decision.details } : {}),
|
||||
},
|
||||
{ status: decision.status },
|
||||
);
|
||||
return NextResponse.json({ error: decision.code, message: decision.message, ...(decision.details ? { details: decision.details } : {}) }, { status: decision.status });
|
||||
}
|
||||
|
||||
const principal = decision.ctx.principal;
|
||||
if (principal) {
|
||||
const forwarded = stripVerifiedHeaders(req);
|
||||
|
||||
+26
-21
@@ -71,34 +71,39 @@
|
||||
"canonical": true,
|
||||
"parentRepo": null,
|
||||
"capabilities": [
|
||||
"prospekt.email_verify",
|
||||
"prospekt.jobs_write",
|
||||
"prospekt.jobs_read",
|
||||
"prospekt.search_read",
|
||||
"prospekt.search_write",
|
||||
"0pt.query_source",
|
||||
"0pt.catalog_list",
|
||||
"0pt.crawl_job",
|
||||
"0pt.document_ocr",
|
||||
"0pt.write_external_record",
|
||||
"0pt.estimate_compute",
|
||||
"0pt.execute_metric",
|
||||
"0pt.lakehouse_mapping_manage",
|
||||
"0pt.lakehouse_write",
|
||||
"0pt.source_rate_policy_manage",
|
||||
"0pt.screen_sanctions",
|
||||
"0pt.estimate_compute",
|
||||
"0pt.vehicle_lookup",
|
||||
"0pt.catalog_list",
|
||||
"0pt.source_registry_list",
|
||||
"0pt.load_full_table",
|
||||
"0pt.order_create",
|
||||
"0pt.order_payment",
|
||||
"0pt.write_iceberg_table",
|
||||
"0pt.structure.resolve_entities",
|
||||
"0pt.structure.get_lineage",
|
||||
"0pt.structure.quality_run",
|
||||
"0pt.structure.quality_list_runs",
|
||||
"0pt.structure.quality_checks",
|
||||
"0pt.structure.quality_reports",
|
||||
"0pt.query_source",
|
||||
"0pt.render_report",
|
||||
"0pt.run_data_quality_check",
|
||||
"0pt.screen_sanctions",
|
||||
"0pt.source_rate_policy_manage",
|
||||
"0pt.source_registry_list",
|
||||
"0pt.structure.extract_document",
|
||||
"0pt.structure.get_lineage",
|
||||
"0pt.structure.normalize_value",
|
||||
"0pt.structure.quality_checks",
|
||||
"0pt.structure.quality_list_runs",
|
||||
"0pt.structure.quality_reports",
|
||||
"0pt.structure.quality_run",
|
||||
"0pt.structure.resolve_entities",
|
||||
"0pt.structure.route_parsing",
|
||||
"0pt.structure.normalize_value"
|
||||
"0pt.vehicle_lookup",
|
||||
"0pt.write_external_record",
|
||||
"0pt.write_iceberg_table",
|
||||
"prospekt.email_verify",
|
||||
"prospekt.jobs_read",
|
||||
"prospekt.jobs_write",
|
||||
"prospekt.search_read",
|
||||
"prospekt.search_write"
|
||||
],
|
||||
"surfaces": [
|
||||
"api",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"id": "0pt.crawl_job",
|
||||
"name": "0pt.crawl_job",
|
||||
"owner": "0pt",
|
||||
"version": "0.1.0",
|
||||
"riskLevel": "L2",
|
||||
"piiLevel": "low",
|
||||
"surfaces": [
|
||||
"api",
|
||||
"cli",
|
||||
"mcp",
|
||||
"job"
|
||||
],
|
||||
"requiresJob": true,
|
||||
"tenantScoped": true,
|
||||
"operationId": "siax.acquisition.run",
|
||||
"description": "Ägare 0pt. Registrerad i CL0UD capability-registry (packages/capability-registry/src/acquisition-capabilities.ts, runtime B0TS). operationId är den faktiska kontraktsoperationen siax.acquisition.run, refererad även i 0pt/acquisition.consumer.json — ingen påhittad id."
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"id": "0pt.execute_metric",
|
||||
"name": "0pt.execute_metric",
|
||||
"owner": "0pt",
|
||||
"version": "0.1.0",
|
||||
"riskLevel": "L1",
|
||||
"piiLevel": "none",
|
||||
"surfaces": [
|
||||
"api",
|
||||
"cli"
|
||||
],
|
||||
"requiresJob": false,
|
||||
"tenantScoped": true,
|
||||
"operationId": "0ptExecuteMetric",
|
||||
"description": "Ägare 0pt. Implementation: 0pt/services/analytics/app.py:366 execute_metric, rutt POST /api/0pt/analytics/metrics/{metric_id}/query. Konsumeras av ACT0 consulting_delivery_analytics (governed-metric-steg). operationId är registrerad kontraktsnamn i CL0UD capability-registry (consulting-capabilities.ts)."
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"id": "0pt.load_full_table",
|
||||
"name": "0pt.load_full_table",
|
||||
"owner": "0pt",
|
||||
"version": "0.1.0",
|
||||
"riskLevel": "L3",
|
||||
"piiLevel": "high",
|
||||
"surfaces": [
|
||||
"job"
|
||||
],
|
||||
"requiresJob": true,
|
||||
"tenantScoped": true,
|
||||
"description": "Ägare 0pt. Registrerad i CL0UD capability-registry (0pt-full-table-capabilities.ts); best befintliga jobbgräns 0pt.full_table_job, utförd av p0lytics.docstruct.full_table_worker. Endast jobb-ytan deklareras — ingen HTTP-operation existerar, därför medvetet ingen operationId (registret säger uttryckligen att ingen påhittas)."
|
||||
}
|
||||
@@ -12,5 +12,6 @@
|
||||
],
|
||||
"requiresJob": true,
|
||||
"tenantScoped": true,
|
||||
"operationId": "0pt.create_order",
|
||||
"description": "Risk tilldelad av RW-005b-regel (L3/low): Produktionsmutation av data (RAG-003 reg 1) — övervakning krävs. RAG-003-RISK-TAXONOMY + siax-tenancy deny-by-default."
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@
|
||||
],
|
||||
"requiresJob": true,
|
||||
"tenantScoped": true,
|
||||
"operationId": "0pt.query_source",
|
||||
"description": "Risk tilldelad av RW-005b-regel (L2/none): Läsande/beräknande — ingen mutation, begränsad påverkan. RAG-003-RISK-TAXONOMY + siax-tenancy deny-by-default."
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"id": "0pt.render_report",
|
||||
"name": "0pt.render_report",
|
||||
"owner": "0pt",
|
||||
"version": "0.1.0",
|
||||
"riskLevel": "L1",
|
||||
"piiLevel": "none",
|
||||
"surfaces": [
|
||||
"api"
|
||||
],
|
||||
"requiresJob": false,
|
||||
"tenantScoped": true,
|
||||
"operationId": "0ptRenderReport",
|
||||
"description": "Ägare 0pt. ACT0 consulting_delivery_analytics render-steg (artifact-before-notice). Registrerad i CL0UD capability-registry (consulting-capabilities.ts); operationId är registrerad kontraktsnamn, inte en gissning."
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"id": "0pt.run_data_quality_check",
|
||||
"name": "0pt.run_data_quality_check",
|
||||
"owner": "0pt",
|
||||
"version": "0.1.0",
|
||||
"riskLevel": "L1",
|
||||
"piiLevel": "none",
|
||||
"surfaces": [
|
||||
"api",
|
||||
"cli"
|
||||
],
|
||||
"requiresJob": false,
|
||||
"tenantScoped": true,
|
||||
"operationId": "0ptRunDataQualityCheck",
|
||||
"description": "Ägare 0pt. ACT0 consulting_delivery_analytics kvalitetsgrind + seedade analystmallar (tmpl_000010/000011/000575 använder samma capability-id). Registrerad i CL0UD capability-registry (consulting-capabilities.ts)."
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"repo": "0pt",
|
||||
"framework": "dockerfile",
|
||||
"build": "Coolify build_pack=dockerfile (byggd av Coolify från main)",
|
||||
"start": "Coolify container (app 0pt)",
|
||||
"port": 3000,
|
||||
"healthcheck": {
|
||||
"path": "/api/health"
|
||||
},
|
||||
"dedicated": true
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "pe-0pt-829150fd0481",
|
||||
"repo": "0pt",
|
||||
"evidenceType": "deploy-log",
|
||||
"result": "pass",
|
||||
"verifiedAt": "2026-11-10T10:04:54Z",
|
||||
"verifiedBy": "coolify-deployment-db (application_deployment_queues, senaste finished-deploy)",
|
||||
"proofRef": "coolify://deployment/https://0pt.app,https://api.0pt.app",
|
||||
"sourceSha": "829150fd0481191b4c96b52475ecc822e46a5fe7"
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"name": "0pt",
|
||||
"slug": "0pt",
|
||||
"origin_url": "https://git.siax.io/admin/0pt.git",
|
||||
"manifest_file": "siax.repo.v3.json",
|
||||
"manifest_operational_state": "running",
|
||||
"assessed_level": "LIVE_VERIFIED",
|
||||
"observed_live": "LIVE_VERIFIED",
|
||||
"gaps": [
|
||||
"NO_BACKUP_POLICY"
|
||||
],
|
||||
"ui": true,
|
||||
"ui_dirs": [
|
||||
"app",
|
||||
"public"
|
||||
],
|
||||
"prod_domains": [
|
||||
"0pt.app",
|
||||
"api.0pt.app"
|
||||
],
|
||||
"live": [
|
||||
{
|
||||
"host": "0pt.app",
|
||||
"status": 200,
|
||||
"class": "public-ok",
|
||||
"title": "0pt — your data"
|
||||
},
|
||||
{
|
||||
"host": "api.0pt.app",
|
||||
"status": 200,
|
||||
"class": "public-ok",
|
||||
"title": "0pt — your data"
|
||||
}
|
||||
],
|
||||
"deep": {
|
||||
"tracked_files": 954,
|
||||
"test_files": 178,
|
||||
"e2e_files": 0,
|
||||
"has_playwright": false,
|
||||
"has_cypress": false,
|
||||
"api_contracts": [
|
||||
"contracts/openapi.yaml"
|
||||
],
|
||||
"migrations": 0,
|
||||
"health_refs": 69,
|
||||
"uses_siax_ui": true,
|
||||
"has_a11y_tooling": false,
|
||||
"has_design_conformance": true,
|
||||
"ui_state_files": [
|
||||
"app/error.tsx",
|
||||
"app/not-found.tsx"
|
||||
],
|
||||
"todo_count": 10,
|
||||
"has_runbook_docs": true,
|
||||
"has_architecture_docs": true,
|
||||
"has_status_docs": false
|
||||
},
|
||||
"backlog": [
|
||||
{
|
||||
"priority": "P1",
|
||||
"task": "Backup",
|
||||
"next_step": "Definiera frekvens, retention, mål och kryptering i `siax.backup`."
|
||||
},
|
||||
{
|
||||
"priority": "P1",
|
||||
"task": "E2E i webbläsare",
|
||||
"next_step": "Lägg Playwright-flöde för inloggning och kärnflöde mot riktig miljö."
|
||||
},
|
||||
{
|
||||
"priority": "P1",
|
||||
"task": "Tillgänglighetsgrind",
|
||||
"next_step": "Aktivera eslint-plugin-jsx-a11y/axe och en blockerande WCAG 2.2-kontroll."
|
||||
},
|
||||
{
|
||||
"priority": "P2",
|
||||
"task": "Statusdokument",
|
||||
"next_step": "Lägg `docs/STATUS.md` med nivå, bevis, kända gap och nästa steg."
|
||||
},
|
||||
{
|
||||
"priority": "P2",
|
||||
"task": "Teknisk skuld",
|
||||
"next_step": "Prioritera bland 10 TODO/FIXME-markeringar; stäng eller gör dem spårbara som issues."
|
||||
}
|
||||
],
|
||||
"standard": "SIAX Master Definition of Done"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
# 0pt — cosign-signeringskedjan (2026-09-29)
|
||||
|
||||
Prod-imagen git.cloud.siax.io/sax3l/0pt:prod-6b57f7cb9d (sha256:52522a9c0914ba35932ac8095b16ede5202fde4c79b97b1788d1d60930d02f02) är cosign-signerad
|
||||
Prod-imagen git.cloud.siax.io/sax3l/0pt:prod-1e5fafce1a (sha256:80237edf1530110650cdfc6da8e821130d9a005cd47d79528d03dbeae2485822) är cosign-signerad
|
||||
med nyckelparet vars pubkey ligger här. Privata nyckeln raderad efter signering.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzKRSiKdDcfb4IdFB5S5qWVzmtD3V
|
||||
Oj6RxCa68Ox6WEG+6Yuzxo85tgOSWhHNwqfBXYHdNOqKm3J0uQDJNGvvxw==
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEgomLeApgQ4ZWeypoU2LfjLIkuBCa
|
||||
hGwo5+pYW9ae3XMKauDUK17QwMXaSwJ2u9ulefai7+/Fiv3/4Jh8EciMVA==
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"id": "sb-0pt-829150fd0481",
|
||||
"repo": "0pt",
|
||||
"commitSha": "829150fd0481191b4c96b52475ecc822e46a5fe7",
|
||||
"branch": "main",
|
||||
"producedAt": "2026-11-10T10:04:54Z"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.crawl_job",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#siax.acquisition.run",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.crawl_job",
|
||||
"kind": "cli",
|
||||
"entrypoint": "siax 0pt crawl-job",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.crawl_job",
|
||||
"kind": "job",
|
||||
"entrypoint": "n0d job:0pt.crawl_job",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.crawl_job",
|
||||
"kind": "mcp",
|
||||
"entrypoint": "mcp:0pt.crawl_job",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.execute_metric",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0ptExecuteMetric",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.execute_metric",
|
||||
"kind": "cli",
|
||||
"entrypoint": "siax 0pt execute-metric",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.load_full_table",
|
||||
"kind": "job",
|
||||
"entrypoint": "n0d job:0pt.load_full_table",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.render_report",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0ptRenderReport",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.run_data_quality_check",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0ptRunDataQualityCheck",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.run_data_quality_check",
|
||||
"kind": "cli",
|
||||
"entrypoint": "siax 0pt run-data-quality-check",
|
||||
"authRequired": true,
|
||||
"status": "planned"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.extract_document",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.extract_document",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.get_lineage",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.get_provenance",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.normalize_value",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.normalize_value",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.quality_checks",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.quality.checks",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.quality_list_runs",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.quality.list_runs",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.quality_reports",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.quality.reports",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.quality_run",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.quality.run",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.resolve_entities",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.resolve_entities",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.surface.schema.json",
|
||||
"capabilityId": "0pt.structure.route_parsing",
|
||||
"kind": "api",
|
||||
"entrypoint": "contracts/openapi.yaml#0pt.route_parsing",
|
||||
"authRequired": true,
|
||||
"status": "live"
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* CL0UD workload-identity JWT verification for explicit machine routes.
|
||||
* Config-driven; fail-closed when a workload token is presented but invalid.
|
||||
* Tenant/capabilities come from verified claims only.
|
||||
*/
|
||||
import { createRemoteJWKSet, decodeJwt, jwtVerify, type JWTPayload } from 'jose';
|
||||
|
||||
export type WorkloadPrincipal = {
|
||||
sub: string;
|
||||
tenantId: string;
|
||||
capabilities: string[];
|
||||
claims: JWTPayload;
|
||||
};
|
||||
|
||||
export class WorkloadVerificationError extends Error {
|
||||
constructor(message: string) { super(message); this.name = 'WorkloadVerificationError'; }
|
||||
}
|
||||
|
||||
const jwksCache = new Map<string, ReturnType<typeof createRemoteJWKSet>>();
|
||||
let resolverOverride: ((protectedHeader: unknown, token: unknown) => Promise<CryptoKey | Uint8Array>) | null = null;
|
||||
|
||||
export function __setWorkloadKeyResolverForTests(fn: typeof resolverOverride) { resolverOverride = fn; }
|
||||
export function __resetWorkloadJwksCache() { jwksCache.clear(); resolverOverride = null; }
|
||||
|
||||
function readEnv(name: string): string | undefined {
|
||||
const v = process.env[name];
|
||||
return v && v.trim() ? v.trim() : undefined;
|
||||
}
|
||||
|
||||
export function cl0udWorkloadConfig() {
|
||||
const issuer = readEnv('CL0UD_WORKLOAD_ISSUER') ?? readEnv('CL0UD_ISSUER');
|
||||
const jwksUrl = readEnv('CL0UD_WORKLOAD_JWKS_URL');
|
||||
const audience = readEnv('CL0UD_WORKLOAD_AUDIENCE') ?? '0pt';
|
||||
const tenantClaim = readEnv('CL0UD_WORKLOAD_TENANT_CLAIM') ?? 'tenant_id';
|
||||
const capabilitiesClaim = readEnv('CL0UD_WORKLOAD_CAPABILITIES_CLAIM') ?? 'capabilities';
|
||||
return { issuer, jwksUrl, audience, tenantClaim, capabilitiesClaim };
|
||||
}
|
||||
|
||||
export function isCl0udWorkloadConfigured(): boolean {
|
||||
const c = cl0udWorkloadConfig();
|
||||
return Boolean(c.issuer || c.jwksUrl);
|
||||
}
|
||||
|
||||
async function getJwks(c: ReturnType<typeof cl0udWorkloadConfig>) {
|
||||
if (resolverOverride) return resolverOverride;
|
||||
const url = c.jwksUrl ?? (c.issuer ? `${c.issuer.replace(/\/$/, '')}/.well-known/jwks.json` : undefined);
|
||||
if (!url) throw new WorkloadVerificationError('CL0UD workload JWKS URL/issuer not configured');
|
||||
let jwks = jwksCache.get(url);
|
||||
if (!jwks) { jwks = createRemoteJWKSet(new URL(url)); jwksCache.set(url, jwks); }
|
||||
return jwks;
|
||||
}
|
||||
|
||||
function stringArray(v: unknown): string[] {
|
||||
if (Array.isArray(v)) return v.filter((x): x is string => typeof x === 'string' && x.length > 0);
|
||||
if (typeof v === 'string' && v.trim()) return v.split(/[\s,]+/).filter(Boolean);
|
||||
return [];
|
||||
}
|
||||
|
||||
export async function verifyCl0udWorkloadToken(token: string): Promise<WorkloadPrincipal> {
|
||||
const c = cl0udWorkloadConfig();
|
||||
if (!isCl0udWorkloadConfigured()) throw new WorkloadVerificationError('CL0UD workload identity not configured');
|
||||
const jwks = await getJwks(c);
|
||||
const { payload } = await jwtVerify(token, jwks as any, {
|
||||
...(c.issuer ? { issuer: c.issuer } : {}),
|
||||
audience: c.audience,
|
||||
});
|
||||
const tenantId = payload[c.tenantClaim];
|
||||
if (typeof tenantId !== 'string' || !tenantId) throw new WorkloadVerificationError(`missing ${c.tenantClaim} claim`);
|
||||
const sub = typeof payload.sub === 'string' && payload.sub ? payload.sub : `workload:${tenantId}`;
|
||||
const capabilities = stringArray(payload[c.capabilitiesClaim] ?? payload.scope);
|
||||
return { sub, tenantId, capabilities, claims: payload };
|
||||
}
|
||||
|
||||
/** Best-effort check: does this bearer look like a configured CL0UD workload token? */
|
||||
export function looksLikeCl0udWorkloadToken(token: string): boolean {
|
||||
const c = cl0udWorkloadConfig();
|
||||
if (!c.issuer) return false;
|
||||
try { return decodeJwt(token).iss === c.issuer; } catch { return false; }
|
||||
}
|
||||
@@ -50,6 +50,13 @@ export const INTERNAL_SERVICE_TENANTS_VAR = 'INTERNAL_SERVICE_TENANTS';
|
||||
*/
|
||||
export const SERVICE_TENANT_SCOPE_HEADER = 'x-0pt-verified-service-tenants';
|
||||
|
||||
/**
|
||||
* Request header installed by middleware.ts ONLY: the CL0UD workload token's
|
||||
* verified capability list, comma-separated. Stripped from every inbound
|
||||
* request like the tenant scope.
|
||||
*/
|
||||
export const SERVICE_CAPABILITIES_HEADER = 'x-0pt-verified-capabilities';
|
||||
|
||||
/** Parse a comma-separated tenant allowlist (trimmed, de-duplicated, ordered). */
|
||||
export function parseServiceTenants(value: string | undefined | null): string[] {
|
||||
if (!value) return [];
|
||||
|
||||
+19
-49
@@ -1,53 +1,8 @@
|
||||
/**
|
||||
* src/http/tenant-guard.ts
|
||||
* ==========================
|
||||
* P014 fix: every route under `app/api/0pt/**` sits behind `middleware.ts`,
|
||||
* which performs real Zitadel Bearer verification and — only when a
|
||||
* principal was actually verified — forwards the result as the
|
||||
* `x-0pt-verified-tenant` request header (see middleware.ts, src/auth/context.ts).
|
||||
*
|
||||
* Independently of that, every one of these route handlers reads `tenant_id`
|
||||
* from CLIENT-CONTROLLED input (a `?tenant_id=` query param or a JSON body
|
||||
* field) to decide which tenant's rows to read or write. Until this pass,
|
||||
* NONE of them cross-checked that client-supplied value against the verified
|
||||
* header — so a caller holding a valid token for tenant A could read or
|
||||
* write tenant B's sources, rights, provenance, health, quality rules/runs,
|
||||
* documents, or lakehouse mappings simply by naming `tenant_id=t_b` in the
|
||||
* request. `SourceRegistryService.assertSourceTenant` (and friends) only
|
||||
* checks that the object being read *belongs* to the tenant_id it was asked
|
||||
* to check against — it has no way to know whether the CALLER is actually
|
||||
* entitled to assert that tenant_id in the first place. That entitlement
|
||||
* check belongs at the HTTP boundary, once, here.
|
||||
*
|
||||
* This mirrors the exact decision `src/auth/context.ts`'s `resolveAuthContext`
|
||||
* already makes for the enforced-Bearer path ("a disagreeing X-Tenant-Id
|
||||
* header is a 403"), applied uniformly to every 0pt capability route that
|
||||
* takes tenant_id as a body/query parameter rather than relying on
|
||||
* middleware to inject ctx.tenantId directly (most of these routes predate
|
||||
* that plumbing and read tenant_id straight from the request; fixing that
|
||||
* more deeply is a larger refactor than this pass — this closes the actual
|
||||
* authz hole without changing every route's request contract).
|
||||
*/
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { readServiceTenantScope } from "@/src/auth/internal-service-tenant";
|
||||
|
||||
export const VERIFIED_TENANT_HEADER = "x-0pt-verified-tenant";
|
||||
|
||||
/**
|
||||
* Returns a 403 NextResponse when `tenantId` (whatever the route read it
|
||||
* from — query string or body) disagrees with the tenant middleware.ts
|
||||
* already verified for this request. Returns `null` when the caller may
|
||||
* proceed — either because the tenant matches, or because no verified
|
||||
* tenant is present on the request at all.
|
||||
*
|
||||
* The header is absent only in the explicit local-development escape hatch
|
||||
* (`AUTH_ENFORCE=false` with no bearer token presented) — `assertAuthConfigSafe()`
|
||||
* refuses to boot that way in production, so an absent header here can only
|
||||
* happen in a mode that already accepts fully unauthenticated requests.
|
||||
* Rejecting in that mode would be strictly more restrictive than the
|
||||
* existing dev escape hatch intends, so this deliberately no-ops rather than
|
||||
* invents a tenant to compare against.
|
||||
*/
|
||||
export function assertTenantMatchesVerified(
|
||||
request: NextRequest,
|
||||
tenantId: string | null | undefined,
|
||||
@@ -74,7 +29,7 @@ export function assertTenantMatchesVerified(
|
||||
return null;
|
||||
}
|
||||
if (!verified) return null;
|
||||
if (!tenantId) return null; // handlers already 400 on a missing tenant_id separately
|
||||
if (!tenantId) return null;
|
||||
if (tenantId !== verified) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -88,7 +43,6 @@ export function assertTenantMatchesVerified(
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Bind document operations to middleware's verified subject; never accept a conflicting body actor. */
|
||||
export function resolveDocumentActor(
|
||||
request: NextRequest,
|
||||
requestedActor: string | undefined,
|
||||
@@ -102,7 +56,23 @@ export function resolveDocumentActor(
|
||||
),
|
||||
};
|
||||
}
|
||||
// Absence is the existing unauthenticated development path. In enforced
|
||||
// mode middleware always installs the verified subject before this route.
|
||||
return { actorId: verified || requestedActor };
|
||||
}
|
||||
|
||||
export function assertWorkloadCapabilities(
|
||||
request: NextRequest,
|
||||
required: readonly string[],
|
||||
): NextResponse | null {
|
||||
if (!required.length) return null;
|
||||
const raw = request.headers.get('x-0pt-verified-capabilities');
|
||||
if (raw === null) return null; // not a workload-capability-scoped principal
|
||||
const caps = raw ? raw.split(',').map((s) => s.trim()).filter(Boolean) : [];
|
||||
const missing = required.filter((r) => !caps.includes(r) && !caps.includes('*'));
|
||||
if (missing.length) {
|
||||
return NextResponse.json(
|
||||
{ error: 'OPT_ACCESS_DENIED', message: 'missing required workload capability', details: { missing } },
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* Dual-accept workload identity: the machine routes accept EITHER the legacy
|
||||
* shared `X-Internal-Token` (server-configured single-tenant scope) OR a
|
||||
* verified CL0UD workload JWT (tenant + capabilities from verified claims
|
||||
* only). These tests pin the security properties that make that safe:
|
||||
*
|
||||
* - a client-supplied `x-0pt-verified-*` header can never authorize
|
||||
* anything (it is stripped before the handler sees it);
|
||||
* - an ambiguous legacy scope is refused instead of silently widening;
|
||||
* - a workload token for tenant A cannot write tenant B's facts;
|
||||
* - a workload token without the required capability is denied.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { NextRequest } from 'next/server';
|
||||
import { SignJWT, generateKeyPair } from 'jose';
|
||||
import { middleware } from '../../middleware';
|
||||
import { assertTenantMatchesVerified, assertWorkloadCapabilities } from '../../src/http/tenant-guard';
|
||||
import { __resetWorkloadJwksCache, __setWorkloadKeyResolverForTests } from '../../src/auth/cl0ud-workload';
|
||||
import { SERVICE_CAPABILITIES_HEADER, SERVICE_TENANT_SCOPE_HEADER } from '../../src/auth/internal-service-tenant';
|
||||
|
||||
const ISSUER = 'https://cl0ud.siax.io';
|
||||
const TENANT_A = '379976258701823235';
|
||||
const TENANT_B = '999999999999999999';
|
||||
|
||||
function req(path: string, headers: Record<string, string> = {}): NextRequest {
|
||||
return new NextRequest(new URL(path, 'http://localhost'), { headers });
|
||||
}
|
||||
|
||||
let privateKey: CryptoKey;
|
||||
let publicKey: CryptoKey;
|
||||
|
||||
beforeEach(async () => {
|
||||
const pair = await generateKeyPair('RS256');
|
||||
privateKey = pair.privateKey as CryptoKey;
|
||||
publicKey = pair.publicKey as CryptoKey;
|
||||
__setWorkloadKeyResolverForTests(async () => publicKey);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
__resetWorkloadJwksCache();
|
||||
for (const key of ['INTERNAL_TOKEN', 'INTERNAL_SERVICE_TENANTS', 'CL0UD_WORKLOAD_ISSUER', 'CL0UD_WORKLOAD_AUDIENCE', 'AUTH_ENFORCE']) {
|
||||
delete process.env[key];
|
||||
}
|
||||
});
|
||||
|
||||
async function workloadToken(claims: Record<string, unknown>, audience = '0pt'): Promise<string> {
|
||||
return await new SignJWT(claims)
|
||||
.setProtectedHeader({ alg: 'RS256' })
|
||||
.setIssuer(ISSUER)
|
||||
.setAudience(audience)
|
||||
.setSubject('svc-0pt-worker')
|
||||
.setIssuedAt()
|
||||
.setExpirationTime('5m')
|
||||
.sign(privateKey);
|
||||
}
|
||||
|
||||
describe('middleware: legacy internal token scope', () => {
|
||||
beforeEach(() => {
|
||||
process.env.INTERNAL_TOKEN = 'engine-shared-secret';
|
||||
delete process.env.CL0UD_WORKLOAD_ISSUER;
|
||||
});
|
||||
|
||||
it('single configured tenant becomes the verified tenant and the service scope', async () => {
|
||||
process.env.INTERNAL_SERVICE_TENANTS = TENANT_A;
|
||||
const res = await middleware(req('/api/0pt/canonical/facts', { 'x-internal-token': 'engine-shared-secret' }));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get('x-middleware-request-x-0pt-verified-tenant')).toBe(TENANT_A);
|
||||
expect(res.headers.get(`x-middleware-request-${SERVICE_TENANT_SCOPE_HEADER}`)).toBe(TENANT_A);
|
||||
});
|
||||
|
||||
it('an ambiguous multi-tenant scope is refused, not widened', async () => {
|
||||
process.env.INTERNAL_SERVICE_TENANTS = `${TENANT_A},${TENANT_B}`;
|
||||
const res = await middleware(req('/api/0pt/canonical/facts', { 'x-internal-token': 'engine-shared-secret' }));
|
||||
expect(res.status).toBe(401);
|
||||
expect((await res.json()).error).toBe('OPT_UNAUTHENTICATED');
|
||||
});
|
||||
|
||||
it('forged client-supplied verified headers are stripped', async () => {
|
||||
process.env.INTERNAL_SERVICE_TENANTS = TENANT_A;
|
||||
const res = await middleware(
|
||||
req('/api/0pt/canonical/facts', {
|
||||
'x-internal-token': 'engine-shared-secret',
|
||||
'x-0pt-verified-tenant': TENANT_B,
|
||||
[SERVICE_TENANT_SCOPE_HEADER]: TENANT_B,
|
||||
}),
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get('x-middleware-request-x-0pt-verified-tenant')).toBe(TENANT_A);
|
||||
expect(res.headers.get(`x-middleware-request-${SERVICE_TENANT_SCOPE_HEADER}`)).toBe(TENANT_A);
|
||||
});
|
||||
});
|
||||
|
||||
describe('middleware: CL0UD workload token (dual-accept)', () => {
|
||||
beforeEach(() => {
|
||||
process.env.CL0UD_WORKLOAD_ISSUER = ISSUER;
|
||||
process.env.CL0UD_WORKLOAD_AUDIENCE = '0pt';
|
||||
delete process.env.INTERNAL_TOKEN;
|
||||
});
|
||||
|
||||
it('derives tenant and capabilities from verified claims', async () => {
|
||||
const token = await workloadToken({ tenant_id: TENANT_A, capabilities: ['0pt.canonical.write'] });
|
||||
const res = await middleware(req('/api/0pt/canonical/facts', { authorization: `Bearer ${token}` }));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get('x-middleware-request-x-0pt-verified-tenant')).toBe(TENANT_A);
|
||||
expect(res.headers.get(`x-middleware-request-${SERVICE_CAPABILITIES_HEADER}`)).toBe('0pt.canonical.write');
|
||||
});
|
||||
|
||||
it('rejects a token with the wrong audience', async () => {
|
||||
const token = await workloadToken({ tenant_id: TENANT_A, capabilities: ['0pt.canonical.write'] }, 'n0d');
|
||||
const res = await middleware(req('/api/0pt/canonical/facts', { authorization: `Bearer ${token}` }));
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
|
||||
it('rejects a token that carries no tenant claim', async () => {
|
||||
const token = await workloadToken({ capabilities: ['0pt.canonical.write'] });
|
||||
const res = await middleware(req('/api/0pt/canonical/facts', { authorization: `Bearer ${token}` }));
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
|
||||
it('ignores forged verified headers on the workload path too', async () => {
|
||||
const token = await workloadToken({ tenant_id: TENANT_A, capabilities: ['0pt.canonical.write'] });
|
||||
const res = await middleware(
|
||||
req('/api/0pt/canonical/facts', {
|
||||
authorization: `Bearer ${token}`,
|
||||
'x-0pt-verified-tenant': TENANT_B,
|
||||
}),
|
||||
);
|
||||
expect(res.headers.get('x-middleware-request-x-0pt-verified-tenant')).toBe(TENANT_A);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tenant guard: scope and capability enforcement', () => {
|
||||
it('denies a write for a tenant outside the service scope', () => {
|
||||
const request = req('/api/0pt/canonical/facts', { [SERVICE_TENANT_SCOPE_HEADER]: TENANT_A });
|
||||
expect(assertTenantMatchesVerified(request, TENANT_A)).toBeNull();
|
||||
const denied = assertTenantMatchesVerified(request, TENANT_B);
|
||||
expect(denied?.status).toBe(403);
|
||||
});
|
||||
|
||||
it('denies a tenant that disagrees with a verified workload tenant', () => {
|
||||
const request = req('/api/0pt/canonical/facts', { 'x-0pt-verified-tenant': TENANT_A });
|
||||
expect(assertTenantMatchesVerified(request, TENANT_A)).toBeNull();
|
||||
expect(assertTenantMatchesVerified(request, TENANT_B)?.status).toBe(403);
|
||||
});
|
||||
|
||||
it('denies a missing capability on a capability-scoped principal', () => {
|
||||
const request = req('/api/0pt/canonical/facts', { [SERVICE_CAPABILITIES_HEADER]: '0pt.canonical.read' });
|
||||
expect(assertWorkloadCapabilities(request, ['0pt.canonical.write'])?.status).toBe(403);
|
||||
expect(assertWorkloadCapabilities(request, ['0pt.canonical.read'])).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,116 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { isolatedSt0reFetch, probeSt0reRealinfra, resolveSt0reRealinfraTarget } from "@/tests/support/st0re-realinfra";
|
||||
|
||||
describe("ST0RE realinfra safety guard", () => {
|
||||
it("uses real HTTP for local writes while forbidding redirect following", async () => {
|
||||
const fetchSpy = vi.fn<typeof fetch>().mockResolvedValue(new Response("{}"));
|
||||
const transport = isolatedSt0reFetch("http://127.0.0.1:4620", fetchSpy);
|
||||
await transport("http://127.0.0.1:4620/v1/st0re/lakehouse/tables", { method: "POST", body: "{}", redirect: "follow" });
|
||||
expect(fetchSpy).toHaveBeenCalledWith("http://127.0.0.1:4620/v1/st0re/lakehouse/tables",
|
||||
{ method: "POST", body: "{}", redirect: "error" });
|
||||
});
|
||||
|
||||
it.each(["https://api.st0re.siax.io/v1/st0re/lakehouse/tables", "http://127.0.0.1:4621/v1/st0re/lakehouse/tables"])
|
||||
("refuses a write outside the exact test origin without sending it (%s)", async (url) => {
|
||||
const fetchSpy = vi.fn<typeof fetch>();
|
||||
const transport = isolatedSt0reFetch("http://127.0.0.1:4620", fetchSpy);
|
||||
await expect(transport(new Request(url, { method: "POST" }))).rejects.toThrow(/isolated test origin/);
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{},
|
||||
{ ST0RE_URL: "https://api.st0re.siax.io" },
|
||||
{ ST0RE_TEST_URL: "http://localhost:4620" },
|
||||
{ ST0RE_TEST_URL: "https://api.st0re.siax.io" },
|
||||
{ ST0RE_REALINFRA_TESTS: "true", ST0RE_TEST_URL: "http://localhost:4620" },
|
||||
{ ST0RE_REALINFRA_TESTS: "0", ST0RE_TEST_URL: "http://localhost:4620" },
|
||||
])("stays disabled without exact opt-in and makes no request (%j)", async (env) => {
|
||||
const fetchSpy = vi.fn<typeof fetch>();
|
||||
expect(resolveSt0reRealinfraTarget(env)).toBeUndefined();
|
||||
expect(await probeSt0reRealinfra(env, fetchSpy)).toEqual({
|
||||
reachable: false,
|
||||
reason: expect.stringContaining("disabled"),
|
||||
});
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
undefined,
|
||||
"",
|
||||
"https://api.st0re.siax.io",
|
||||
"https://st0re.siax.io",
|
||||
"https://example.com",
|
||||
"http://192.168.1.1",
|
||||
"http://localhost.example.com",
|
||||
"http://127.1",
|
||||
"http://2130706433",
|
||||
"http://127.0.0.2",
|
||||
"http://[::ffff:127.0.0.1]",
|
||||
"ftp://localhost",
|
||||
"not-a-url",
|
||||
"http://localhost:65536",
|
||||
["http://", "user:password", "@localhost"].join(""),
|
||||
["http://", "@localhost"].join(""),
|
||||
"http://localhost/path",
|
||||
"http://localhost/..",
|
||||
"http://localhost?query=1",
|
||||
"http://localhost?",
|
||||
"http://localhost#fragment",
|
||||
"http://localhost#",
|
||||
"http://localhost\\remote",
|
||||
" http://localhost",
|
||||
])("fails closed before fetch for missing or invalid target (%s)", async (target) => {
|
||||
const env = {
|
||||
ST0RE_REALINFRA_TESTS: "1",
|
||||
ST0RE_TEST_URL: target,
|
||||
ST0RE_URL: "http://localhost:4620",
|
||||
};
|
||||
const fetchSpy = vi.fn<typeof fetch>();
|
||||
expect(() => resolveSt0reRealinfraTarget(env)).toThrow(/ST0RE realinfra configuration error/);
|
||||
await expect(probeSt0reRealinfra(env, fetchSpy)).rejects.toThrow(/ST0RE_TEST_URL/);
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
"http://localhost:4620",
|
||||
"http://127.0.0.1:4620",
|
||||
"http://[::1]:4620",
|
||||
"https://localhost:4620/",
|
||||
"https://127.0.0.1",
|
||||
"https://[::1]",
|
||||
])("probes an explicit loopback target with one GET (%s)", async (target) => {
|
||||
const env = {
|
||||
ST0RE_REALINFRA_TESTS: "1",
|
||||
ST0RE_TEST_URL: target,
|
||||
ST0RE_URL: "https://api.st0re.siax.io",
|
||||
};
|
||||
const origin = new URL(target).origin;
|
||||
const fetchSpy = vi.fn<typeof fetch>().mockResolvedValue(new Response("[]", { status: 200 }));
|
||||
expect(resolveSt0reRealinfraTarget(env)).toBe(origin);
|
||||
expect(await probeSt0reRealinfra(env, fetchSpy)).toEqual({ target: origin, reachable: true, reason: "" });
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
expect(fetchSpy).toHaveBeenCalledWith(`${origin}/v1/st0re/lakehouse/namespaces`, {
|
||||
method: "GET",
|
||||
redirect: "error",
|
||||
headers: { "X-Tenant-Id": "t_0pt_realinfra_local", "X-Actor-Id": "0pt-realinfra-test" },
|
||||
signal: expect.any(AbortSignal),
|
||||
});
|
||||
});
|
||||
|
||||
it("reports HTTP 500 as unreachable", async () => {
|
||||
const target = "http://localhost:4620";
|
||||
const fetchSpy = vi.fn<typeof fetch>().mockResolvedValue(new Response(null, { status: 500 }));
|
||||
expect(await probeSt0reRealinfra({ ST0RE_REALINFRA_TESTS: "1", ST0RE_TEST_URL: target }, fetchSpy))
|
||||
.toEqual({ target, reachable: false, reason: "ST0RE responded HTTP 500" });
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("reports a throwing fetch as unreachable", async () => {
|
||||
const target = "http://localhost:4620";
|
||||
const fetchSpy = vi.fn<typeof fetch>().mockRejectedValue(new Error("synthetic connection failure"));
|
||||
expect(await probeSt0reRealinfra({ ST0RE_REALINFRA_TESTS: "1", ST0RE_TEST_URL: target }, fetchSpy))
|
||||
.toEqual({ target, reachable: false, reason: "Local ST0RE reachability probe failed" });
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
type St0reTestEnv = Readonly<Record<string, string | undefined>>;
|
||||
|
||||
export interface St0reRealinfraProbe {
|
||||
target?: string;
|
||||
reachable: boolean;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
/** Keep the real client's subsequent writes inside the selected test origin too. */
|
||||
export function isolatedSt0reFetch(target: string, fetchImpl: typeof fetch): typeof fetch {
|
||||
const origin = resolveSt0reRealinfraTarget({ ST0RE_REALINFRA_TESTS: "1", ST0RE_TEST_URL: target });
|
||||
return async (input, init) => {
|
||||
const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
|
||||
if (url.origin !== origin) throw new Error("ST0RE realinfra request escaped its isolated test origin");
|
||||
return fetchImpl(input, { ...init, redirect: "error" });
|
||||
};
|
||||
}
|
||||
|
||||
/** Only an explicit, isolated loopback origin can enable real-infrastructure tests. */
|
||||
export function resolveSt0reRealinfraTarget(env: St0reTestEnv): string | undefined {
|
||||
if (env.ST0RE_REALINFRA_TESTS !== "1") return undefined;
|
||||
|
||||
const target = env.ST0RE_TEST_URL;
|
||||
const configError = () => new Error(
|
||||
"ST0RE realinfra configuration error: ST0RE_REALINFRA_TESTS=1 requires ST0RE_TEST_URL to be an HTTP(S) loopback origin (localhost, 127.0.0.1 or [::1]), without credentials, path, query or fragment. Remote/production targets are forbidden."
|
||||
);
|
||||
// Check the original spelling too: URL parsing normalizes paths and IP aliases.
|
||||
if (!target || !/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(?::[0-9]+)?\/?$/i.test(target)) {
|
||||
throw configError();
|
||||
}
|
||||
try {
|
||||
return new URL(target).origin;
|
||||
} catch {
|
||||
throw configError();
|
||||
}
|
||||
}
|
||||
|
||||
export async function probeSt0reRealinfra(
|
||||
env: St0reTestEnv,
|
||||
fetchImpl: typeof fetch,
|
||||
): Promise<St0reRealinfraProbe> {
|
||||
// Configuration failures must escape the reachability catch and fail closed.
|
||||
const target = resolveSt0reRealinfraTarget(env);
|
||||
if (!target) {
|
||||
return { reachable: false, reason: "disabled: ST0RE_REALINFRA_TESTS is not 1" };
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetchImpl(`${target}/v1/st0re/lakehouse/namespaces`, {
|
||||
method: "GET",
|
||||
redirect: "error",
|
||||
headers: {
|
||||
"X-Tenant-Id": env.ST0RE_TEST_TENANT_ID ?? "t_0pt_realinfra_local",
|
||||
"X-Actor-Id": "0pt-realinfra-test",
|
||||
},
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
return {
|
||||
target,
|
||||
reachable: response.ok,
|
||||
reason: response.ok ? "" : `ST0RE responded HTTP ${response.status}`,
|
||||
};
|
||||
} catch {
|
||||
return { target, reachable: false, reason: "Local ST0RE reachability probe failed" };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user