Skip to content

ci(authenticator): endpoint coverage gate + OpenAPI drift gate - #2000

Merged
cyberantonz merged 2 commits into
constructorfabric:mainfrom
cyberantonz:feat/authenticator-endpoint-coverage-gate
Jul 29, 2026
Merged

ci(authenticator): endpoint coverage gate + OpenAPI drift gate#2000
cyberantonz merged 2 commits into
constructorfabric:mainfrom
cyberantonz:feat/authenticator-endpoint-coverage-gate

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Gives the authenticator the same endpoint-coverage machinery the analytics/identity lanes have (e2e-bronze-to-api.yml): a committed OpenAPI spec kept fresh by a drift gate, an e2e ledger of every request the suite makes, and a CI gate that fails when a documented operation is exercised by no test.

What's in here

  • authenticator openapi subcommand — emits the OpenAPI document offline from the exact build_operations route table the live gear serves (mirrors analytics openapi), so the committed doc and the running service can never diverge. Declares the provable 400 on back-channel-logout while at it (the e2e asserts it). Committed doc: docs/components/backend/authenticator/openapi.json (14 operations); drift-checked by a new job in openapi-specs.yml.
  • Coverage recording in the Rust e2e harness — new tests/common/mod.rs, a thin reqwest wrapper all 8 e2e_*.rs suites now share. It records (method, path) -> {status} into $E2E_COVERAGE_LEDGER (same schema as the bronze-to-api rig's observed_endpoints.json), origin-filtered by AUTH_BASE/AUTH_BASE_DISABLED so fakeidp / service-token-listener traffic can't pollute the ledger. run-e2e.sh resets + exports the path. The login loop now also asserts the discovery document — the one operation no test exercised.
  • authenticator suite in api_coverage.py — one SKIP (DELETE /auth/admin/users/{person_id}/sessions needs the gateway-JWT authn pipeline; exercised in the gateway compose e2e) and one BLOCKED code (back-channel-logout's 200 is answered to the IdP's server-side POST — proven via fakeidp's rp_status assertion — the test client can only observe the 400 rejection). Also genericizes the BLOCKED report preamble that was analytics-only prose.
  • New workflow .github/workflows/authenticator.yml — an e2e job that runs run-e2e.sh (this suite previously didn't run in CI at all) and uploads the ledger, plus an authenticator-endpoint-coverage-gate job that analyses it against the committed spec. Path-filtered like gateway.yml.

Gate state

PASS — 13/14 operations exercised + 1 approved SKIP, 0 missing. Non-blocking advisories: 401 unobserved on the csrf/sessions ops; observed-but-undeclared 403 (CSRF reject) and 429 (rate limiter) — follow-up candidates for .error_401/.error_403/.error_429 declarations.

Validation

  • Full run-e2e.sh green locally with recording on; gate PASS on the real ledger.
  • Negative test: removing one operation's traffic from the ledger fails the gate with MISSING (rc 1).
  • openapi_spec.py check green against the committed doc; unit tests (50), clippy, rustfmt, pre-commit all pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added comprehensive OpenAPI documentation for the Authenticator API, including login, sessions, logout, CSRF, OIDC metadata, and authorization endpoints.
    • Added an offline command to generate the Authenticator OpenAPI specification.
    • Added endpoint coverage tracking for end-to-end authentication tests.
  • Tests

    • Added automated endpoint coverage and OpenAPI drift checks to CI.
    • Expanded end-to-end validation to cover OpenID discovery metadata and documented endpoints.

Give the authenticator the same endpoint-coverage machinery the
analytics/identity lanes have (e2e-bronze-to-api.yml):

- `authenticator openapi` subcommand: emit the OpenAPI document offline
  from the exact build_operations route table the live gear serves
  (mirrors `analytics openapi`); declare the provable 400 on
  back-channel-logout while at it. Commit the generated doc at
  docs/components/backend/authenticator/openapi.json and drift-check it
  in openapi-specs.yml.
- tests/common/mod.rs: a reqwest wrapper the eight e2e_*.rs suites now
  share; it records every (method, path) -> {status} answered by the
  authenticator instances into $E2E_COVERAGE_LEDGER (same schema as the
  bronze-to-api rig's observed_endpoints.json), filtered by origin so
  fakeidp/service-token traffic can't pollute the ledger. run-e2e.sh
  resets + exports the ledger path. The login loop now also asserts the
  discovery document (the one operation no test exercised).
- api_coverage.py: an `authenticator` suite — one SKIP (admin
  revoke-by-user needs the gateway authn pipeline; covered in the
  gateway compose e2e), back-channel-logout's 200 BLOCKED (answered to
  the IdP's server-side POST, proven via fakeidp's rp_status assertion;
  the client only sees the 400 rejection). Genericize the BLOCKED
  report preamble that was analytics-only prose.
- .github/workflows/authenticator.yml: e2e job runs run-e2e.sh (which
  now didn't run in CI at all) and uploads the ledger;
  authenticator-endpoint-coverage-gate analyses it against the
  committed spec — a documented operation exercised by no test fails.

Local validation: run-e2e.sh green end-to-end; gate PASS (13/14
exercised + 1 approved SKIP, 0 missing); gate correctly FAILS (rc 1,
MISSING) when an operation's traffic is removed from the ledger.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz requested a review from a team as a code owner July 28, 2026 12:40
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Regenerate the connectors-ddl snapshot

This PR changes src/ingestion/**. If your change affects any
bronze / silver / gold schema, regenerate the committed DDL snapshot
and include it in this PR.

Prerequisites (details: src/ingestion/scripts/bootstrap-db/README.md):

  • docker + a fresh throwaway ClickHouse 25.7.5 (README "Local ClickHouse for testing")
  • .env from .env.bootstrap.example pointing at it; use the host LAN IP,
    reachable from both the host and connector containers
    (host.docker.internal does not resolve on the macOS host itself)
  • python3.12 or python3.11 on PATH (pinned dbt venv)
  • HubSpot + Salesforce credentials in .env — their discover calls the
    live APIs; without them, apply ../connectors-ddl/{hubspot,salesforce}.sql
    (relative to bootstrap-db/) to seed their bronze, then run the dbt step
cd src/ingestion/scripts/bootstrap-db
set -a; source pins.env; source .env; set +a
./bootstrap-db.sh connectors-config.yaml   # fresh ClickHouse 25.7.5
./dump-ddl.sh                              # writes scripts/connectors-ddl/*.sql

Commit the resulting scripts/connectors-ddl/*.sql diff. If nothing
changed, no snapshot update is needed. (Regeneration is manual for now.)

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Authenticator routes now generate an offline OpenAPI document, e2e tests record endpoint coverage, and CI validates both specification drift and exercised operations against the committed Authenticator API specification.

Changes

Authenticator contract and CI gates

Layer / File(s) Summary
Offline OpenAPI generation
docs/components/backend/authenticator/openapi.json, src/backend/services/authenticator/src/api/mod.rs, src/backend/services/authenticator/src/main.rs
Adds the Authenticator OpenAPI contract and an offline CLI generator built from the live route table.
E2E coverage ledger instrumentation
src/backend/services/authenticator/tests/common/mod.rs, src/backend/services/authenticator/tests/e2e_*.rs, src/backend/services/authenticator/tests/run-e2e.sh, src/backend/services/authenticator/tests/.gitignore
Routes e2e requests through a shared client that records method, path, and response statuses in a coverage ledger.
Authenticator coverage analysis
src/ingestion/tests/e2e/lib/api_coverage.py
Adds authenticator-specific suite configuration and wires it into endpoint coverage analysis.
CI generation and coverage enforcement
.github/workflows/authenticator.yml, .github/workflows/openapi-specs.yml
Adds OpenAPI drift validation and an e2e coverage gate using generated artifacts and the committed specification.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CI
  participant Authenticator
  participant OpenAPI
  participant CoverageGate
  CI->>Authenticator: run offline openapi command
  Authenticator-->>OpenAPI: emit generated JSON
  CI->>Authenticator: run e2e suite
  Authenticator-->>CoverageGate: upload observed endpoint ledger
  CoverageGate->>OpenAPI: compare observed operations with committed spec
  CoverageGate-->>CI: pass or fail coverage gate
Loading

Possibly related PRs

Suggested reviewers: aleksdotbar, mozhaev-dev, mitasovr

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main CI additions for authenticator endpoint coverage and OpenAPI drift checks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/backend/services/authenticator/src/main.rs (1)

98-118: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Defer AppConfig loading until config is actually needed.

Commands::Openapi says no config is required, but main() calls AppConfig::load_or_default(...)?, apply_cli_overrides(...), and print_config’s to_yaml() path before dispatch, so the OpenAPI subcommand still performs config loading. If config validation defaults or errors on missing backend fields, CI drift-gate runs without a real config could be misclassified as config failures. Move config loading/printing into the run/check/print-config paths, or make the OpenAPI path use a no-config state.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/services/authenticator/src/main.rs` around lines 98 - 118, Update
main so command dispatch occurs before AppConfig::load_or_default and
config.apply_cli_overrides, allowing Commands::Openapi to call print_openapi
without loading or validating configuration. Keep configuration loading for
Commands::Run and Commands::Check, and preserve the --print-config path only
where a loaded config is available.
🧹 Nitpick comments (2)
.github/workflows/openapi-specs.yml (1)

59-70: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Missing persist-credentials: false on new checkout step.

The new authenticator job's actions/checkout@v4 (Line 65) doesn't set persist-credentials: false, unlike the checkout steps added in .github/workflows/authenticator.yml in this same PR, which explicitly disable credential persistence. Static analysis flags this (artipacked). Align for consistency.

🔒 Proposed fix
       - uses: actions/checkout@v4
+        with:
+          persist-credentials: false
       - name: Install protoc + librdkafka build deps
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/openapi-specs.yml around lines 59 - 70, Update the
authenticator job’s actions/checkout@v4 step to set persist-credentials: false,
matching the existing checkout configuration in authenticator.yml.

Source: Linters/SAST tools

docs/components/backend/authenticator/openapi.json (1)

1-435: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Cookie-authenticated endpoints have no declared security.

Only the admin bearerAuth endpoint (Lines 132-136) declares a security requirement; every cookie-session-protected route (/auth/me, /auth/csrf, /auth/refresh, /auth/sessions*, etc.) declares none. Static analysis (checkov CKV_OPENAPI_4/5) flags this as no global/operation-level security. Since this doc is generated from OperationBuilder registrations, the underlying gap (if real) would need to be fixed in api/mod.rs/the toolkit OperationBuilder, not here directly. Given this appears to be a modeling limitation (cookie auth isn't representable as a bearerAuth-style scheme) rather than a missing enforcement, this is likely fine to leave as-is, but worth confirming whether toolkit::api::OperationBuilder supports declaring a cookie-based security scheme for documentation completeness.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/components/backend/authenticator/openapi.json` around lines 1 - 435,
Confirm whether toolkit::api::OperationBuilder supports declaring cookie-based
security schemes; if supported, add the appropriate scheme and apply it to
cookie-authenticated operations such as authenticator.me, authenticator.csrf,
authenticator.refresh, and authenticator.sessions.* in the registrations under
api/mod.rs, then regenerate the OpenAPI document. If unsupported, leave
enforcement unchanged and document or otherwise preserve this modeling
limitation rather than editing the generated JSON directly.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/backend/services/authenticator/tests/e2e_login_loop.rs`:
- Around line 184-203: Update the discovery assertions in the e2e login test to
extract the advertised jwks_uri, perform an HTTP GET against it, and parse the
response as JWKS; validate that the fetched key set contains the key material
required to verify the issued token, rather than only checking the URL suffix.
Preserve the existing issuer assertion and use the test’s existing token/JWKS
verification symbols where available.

---

Outside diff comments:
In `@src/backend/services/authenticator/src/main.rs`:
- Around line 98-118: Update main so command dispatch occurs before
AppConfig::load_or_default and config.apply_cli_overrides, allowing
Commands::Openapi to call print_openapi without loading or validating
configuration. Keep configuration loading for Commands::Run and Commands::Check,
and preserve the --print-config path only where a loaded config is available.

---

Nitpick comments:
In @.github/workflows/openapi-specs.yml:
- Around line 59-70: Update the authenticator job’s actions/checkout@v4 step to
set persist-credentials: false, matching the existing checkout configuration in
authenticator.yml.

In `@docs/components/backend/authenticator/openapi.json`:
- Around line 1-435: Confirm whether toolkit::api::OperationBuilder supports
declaring cookie-based security schemes; if supported, add the appropriate
scheme and apply it to cookie-authenticated operations such as authenticator.me,
authenticator.csrf, authenticator.refresh, and authenticator.sessions.* in the
registrations under api/mod.rs, then regenerate the OpenAPI document. If
unsupported, leave enforcement unchanged and document or otherwise preserve this
modeling limitation rather than editing the generated JSON directly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e898594b-ff18-4bc0-ad11-0b1f036e210b

📥 Commits

Reviewing files that changed from the base of the PR and between d284207 and 464bac5.

📒 Files selected for processing (17)
  • .github/workflows/authenticator.yml
  • .github/workflows/openapi-specs.yml
  • docs/components/backend/authenticator/openapi.json
  • src/backend/services/authenticator/src/api/mod.rs
  • src/backend/services/authenticator/src/main.rs
  • src/backend/services/authenticator/tests/.gitignore
  • src/backend/services/authenticator/tests/common/mod.rs
  • src/backend/services/authenticator/tests/e2e_backchannel.rs
  • src/backend/services/authenticator/tests/e2e_login_loop.rs
  • src/backend/services/authenticator/tests/e2e_override.rs
  • src/backend/services/authenticator/tests/e2e_ratelimit.rs
  • src/backend/services/authenticator/tests/e2e_refresh.rs
  • src/backend/services/authenticator/tests/e2e_refresher.rs
  • src/backend/services/authenticator/tests/e2e_service_token.rs
  • src/backend/services/authenticator/tests/e2e_sessions.rs
  • src/backend/services/authenticator/tests/run-e2e.sh
  • src/ingestion/tests/e2e/lib/api_coverage.py

Comment on lines +184 to +203
// 5b. The discovery document points downstream verifiers at that JWKS
// (cf-gears-oidc-authn-plugin resolves jwks_uri from it).
let discovery: serde_json::Value = http
.get(format!("{auth_base}/.well-known/openid-configuration"))
.send()
.await
.unwrap()
.json()
.await
.unwrap();
assert!(
discovery["issuer"].as_str().is_some_and(|s| !s.is_empty()),
"discovery must carry the issuer"
);
assert!(
discovery["jwks_uri"]
.as_str()
.is_some_and(|s| s.ends_with("/.well-known/jwks.json")),
"discovery must point at the published JWKS"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Dereference the discovered jwks_uri.

The suffix check accepts an unrelated or dead URL. Fetch jwks_uri and verify it serves the JWKS used to validate the issued token, so this actually tests the discovery contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/services/authenticator/tests/e2e_login_loop.rs` around lines 184
- 203, Update the discovery assertions in the e2e login test to extract the
advertised jwks_uri, perform an HTTP GET against it, and parse the response as
JWKS; validate that the fetched key set contains the key material required to
verify the issued token, rather than only checking the URL suffix. Preserve the
existing issuer assertion and use the test’s existing token/JWKS verification
symbols where available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants