Auth
Can loopback staff sign-in and department policy be proved without an external identity account?
What question this set answers
Signing in establishes who a person is; authorization establishes which records and actions that person may access. The synthetic staff example keeps those questions separate.
The set asks how a hospital staff service can choose a sign-in method, register accounts, issue and revoke sessions, and enforce department and consent rules with a mounted local identity provider. No external identity account, OAuth application registration, client-secret file or OAuth environment variables are required. The workspace creates the local provider's client settings and callback URL.
The security architect needs a method choice for staff sign-in and department-scoped notes. The platform engineer needs a browser-visible Basic boundary; deployment requires HTTPS. The identity owner needs HTTP registration and revocable sessions, with database-backed token rejection. The security lead needs account-local lockout, refresh-reuse detection, session termination, and audit rows kept after account PII deletion. The integration engineer needs session-bound state, PKCE and an application session. The governance lead needs a decision before any model sees a request. The platform architect needs a separate authorization authority, a bounded cache and fail-closed outages.
There are 120 registration attempts, including four labelled rejections, so the expected persisted account count is 116. Public registration never accepts a role. The loopback service uses synthetic data, process-local session and lockout state, and HS256. Production adoption needs TLS, durable shared lifecycle state, operational key rotation, and application-approved identity and clinical policies. These examples are not a production clinical compliance certification.
How to run it
Install from the kit root, select that environment as the notebook kernel, and work from examples/auth/. The notebooks' setup cells name Python 3.11.
pip install -e '.[auth,auth-argon2,fastapi,sqlalchemy,alembic,codex]' pandas nbconvert ipykernel uvicorn httpxExecute from that directory in order, once, with a fresh kernel each notebook. Do not rerun automatically. Startup refuses an existing WORKSPACE_DIR under .runtime/, then creates owner-only signing, session, IP and service keys plus disposable identity and audit SQLite files. Cleanup stops owned apps and deletes those keys and databases. Usage metadata and browser evidence stay. Fixture credentials stay for later notebooks and are removed when the demonstration is retired. The notebooks do not copy, refresh or delete the Codex grant.
Notebooks 1–5 make no model calls. Notebooks 6 and 7 read ../../../travel-marketplace-agent/data/local/codex-auth and use its catalog and gpt-6-luna. No API-key provider or silent substitution is allowed. Notebook 6's cap is 40. It has 36 intended allowed generations and four denied requests with zero inference. Notebook 7's cap is 4, with two allowed generations. Policy denial and a service outage do not call the model.
Keep public fixtures with ignored .runtime/fixture-passwords.json. data/SOURCES.md records provenance. One-time generate_fixtures.py refuses to overwrite public inputs, so keep the original fixtures. Public displays exclude note text, credentials and hashes. Runtime IPs are HMAC-pseudonymized.
Notebook 5 calls loopback /auth/oauth/local/login, /callback and /me, and mounted /identity/authorize, /token and /user. It follows redirects, checks server-side state and S256 PKCE, rejects adverse inputs, and checks application-token binding. There is no external setup checkpoint, consent page or fixed callback port. Consent denial is local. Code sets live_oauth=False and CODE_EXPIRY_SECONDS to 61.
Notebook 2 keeps one Chrome checkpoint for the native Basic prompt and Swagger lock icons. basic-target.json holds the loopback URL. The driver writes owner-only basic-receipt.json at mode 0600, and the kit tightens it. Both handoff files must be private. Unpack Swagger UI 5.32.6 from the official npm package under .runtime/swagger. The notebook sets TIMING_ITERATIONS to 1000 and BROWSER_WAIT_SECONDS to 1800.
The page offers one local-provider button, session status, and /docs and /sandbox links. Other routes are registration, login, logout, refresh, reset, force logout, disable, delete, /resources/session, /assistant, and separate POST /authorize and GET /explain.
From the kit root, run tests/check_notebooks.py and tests/check_auth_notebooks.py before execution and again with --executed. Assertions are demonstration oracles. Ruff S101 is exempted only for test and notebook assertions. Limits are in docs/auth/auth-verification.md.
Notebooks in order
| Notebook | What it does | Recorded output |
|---|---|---|
auth-methods-and-models-decision-matrix.ipynb | Profiles the synthetic roster and compares authentication methods. Call cap 0. | yes |
basic-auth-sandbox-endpoint.ipynb | Serves a loopback training sandbox and compares Basic credentials. Call cap 0. | yes |
jwt-register-login-logout.ipynb | Posts all 120 registrations to /auth/register and checks scrypt salts. Call cap 0. | yes |
jwt-hardening-flows.ipynb | Registers staff, serves protected routes, and summarises a password spray. Call cap 0. | yes |
oauth-local-authorization-code.ipynb | Completes a local authorization-code flow and reads the application JWT. Call cap 0. | yes |
authorization-rbac-rebac-abac-hybrid.ipynb | Registers accounts and renders a pure RBAC action matrix. Call cap 40. | yes |
authorization-service-separated.ipynb | Starts a separate loopback authorization authority with its own service bearer. Call cap 4. | yes |
Saved output counts, in this order, are 15, 18, 30, 31, 28, 29 and 29.
What the recorded outputs show
Printed fixture tables show staff 120, notes 600, attempts 3000, relations 1316, rules 26 and prompts 40, each synthetic True, and say that credentials and note text were not displayed. Migration tables show revision auth_001 and foreign_key_violations 0.
Admin rows, in order, are cardiology 3, emergency 3, neurology 3, oncology 3, orthopedics 2, pediatrics 3, pharmacy 2, quality 2 and radiology 3. Auditor rows then show cardiology 3, emergency 3, neurology 3 and oncology 2; the digest is cut here. Measures are hospitals 4.00, departments 9.00, note_to_folder_edges 2.00, phi_share 0.25, stuffing_events 60.00 and spray_subjects 80.00. The method table prints Basic and JWT owned by application, and OAuth code + PKCE owned by identity provider. The cell asserts a fourth method, managed identity.
Basic auth listens at http://127.0.0.1:52463 with ready True. correct is status 200. wrong_password and unknown_user are status 401, code basic_unauthorized, challenge Basic realm="sandbox", charset="UTF-8".
JWT registration listens at http://127.0.0.1:51915 with ready True. The tail shows regular accepted, duplicate_casing rejected and weak_password rejected. The print says 120 requests produced 116 accounts and four named rejections. A scrypt table prints distinct_salts True and does not show the hashes.
Hardening listens at http://127.0.0.1:51949 with ready True. Its groupby is regular 201 accepted 116, duplicate_casing 409 duplicate_email 2, and weak_password 422 weak_password 2. The spray table prints events 80 and accounts 80, with no raw address. The hybrid and separated-service notebooks print that same groupby.
Local OAuth listens at http://127.0.0.1:53228 with ready True. After /auth/oauth/local/login, local_me shows connected True, provider local, application_token_issued True, and user c4274035-0e56-4bf0-bfb7-4d28856ee328. The session summary shows connected_sessions 1, provider_token_server_side True and provider_identity_bound True. The claim row shows iss northline-identity, aud clinical-documentation, role clinician, token_use access, provider local, iat 1792565253 and exp 1792566153. The cell asserts callback status 303, which is not a printed column.
The hybrid notebook sets gpt-6-luna, call cap 40, EXPLAIN_PAIRS 10, ALLOWED_PROMPTS 36 and DENIED_PROMPTS 4. The RBAC matrix prints clinician and nurse allowed for read and summarize and denied for administer, and department_lead allowed for read and summarize, with decided_by rbac. The digest is cut on the department_lead administer row. The print says a five-role matrix was rendered. The cell asserts 26 rules. The reading note names auditor denies and an admin allow through role-admin-administer.
The separated-service notebook sets the same model, call cap 4, DECISION_CACHE_SECONDS 30 and AUTHORIZATION_TIMEOUT_SECONDS 2. It reads the service bearer with version_stage="AWSCURRENT". The printed row is http://127.0.0.1:52276, listening True and ready True.
What is not shown or not run
No notebook is marked without recorded output. All seven saved files contain outputs.
The method table does not finish its fourth row, so managed identity's owner and limitation are not printed. The roster stops in the auditor block. The cell asserts the two 401 JSON bodies are equal, and the note says the table does not print them. Public displays exclude note text, credentials and hashes. The spray print has no raw network addresses.
The digest cuts off before these cells, so their outputs are not described here: Basic timing samples, the Chrome checkpoint, stuffing target 111, token cases tampered, wrong_audience and none, an argon2 result, nurse inheritance, forged OAuth state, and the assistant after host.start(). The JWT title names revocation. The digest ends before any revocation cell. Notebook 7's prose names fetched, cached, a new policy_version, and service_unavailable. The digest stops before the receipt cells.
Where it fits in the kit
The import cells name these kit modules.
| Module | Notebooks that import it |
|---|---|
recohut_kit.auth.matrices | Decision matrix, local OAuth |
recohut_kit.auth.credentials | Basic sandbox, JWT register |
recohut_kit.auth.flows | JWT hardening |
recohut_kit.auth.authorization | Hybrid policy, separated service |
recohut_kit.integrations.auth_services.showcase | All seven |
recohut_kit.integrations.auth_services.probes | Basic sandbox, JWT register, JWT hardening, local OAuth, separated service |
recohut_kit.integrations.auth_services.argon2 | JWT register |
recohut_kit.integrations.auth_services.codex_assistant | Hybrid policy, separated service |
recohut_kit.integrations.auth_services.authorization_service | Separated service |
recohut_kit.integrations.auth_services.authorization_client | Separated service |
recohut_kit.integrations.fastapi_contracts.runtime | Separated service imports LocalService |
showcase supplies Fixtures and DemoWorkspace in every notebook.
How is this page?
Last updated on