feat(auth): add org_id to APIKey and return AuthContext from require_api_key#16
Merged
Conversation
…key-hashing fix: chdir to repo root on startup (policy file resolution)
…key-hashing fix: include policy.tool_access.yaml in Docker image
…quire_api_key - storage.py: add nullable org_id column to api_keys so decisions can be routed per-org - auth.py: require_api_key now returns AuthContext(raw_key, org_id) instead of a bare key string - api.py: update /v1/precheck, /v1/postcheck, /v1/keys/rotate, /v1/keys/revoke to consume AuthContext - tests: add test_auth_org_id.py covering org_id propagation, null handling, and 401 rejection paths Refs: GOV-11 (DL-1)
5 tasks
Merges the DL-4 CI improvements from dev: - Updated ci.yml with dev branch trigger, Python 3.12, and 60% coverage - Updated pyproject.toml with relaxed mypy config and 60% coverage threshold - Updated settings.py with extra='ignore' for unknown env vars - Updated conftest.py with StaticPool and hash_api_key fixtures - Fixes to test files matching actual implementation behavior Re-applied DL-1's api.py changes on top of dev's reformatted version: - AuthContext import and usage in rotate/revoke/precheck/postcheck - key_hash lookup replacing the removed APIKey.key column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
org_idcolumn to theAPIKeymodel so precheck decisions can be routed to the correct org.require_api_keynow returnsAuthContext(raw_key, org_id)(frozen dataclass) instead of a bare key string.Depends(require_api_key)call sites inapi.py(/v1/precheck,/v1/postcheck,/v1/keys/rotate,/v1/keys/revoke) to consume the new type. Rotate/revoke also fixed to usekey_hashinstead of a non-existentkeycolumn.tests/test_auth_org_id.pycovering: org_id propagation on valid key,Nonewhen column is null, per-org isolation, and 401 rejection for unknown/inactive/expired/missing keys.GovernsAI Tracker issue
GOV-11 (DL-1)
Reviewers
Tagging Nexus (code quality) and Cipher (security/arch) — both approvals required.
Test plan
pytest tests/test_auth_org_id.py— 8/8 passauth.org_idin precheck/postcheck handlersorg_idcolumnNotes
tests/test_auth_enforcement.pywere already inconsistent with the hashed-key model (usesAPIKey(key=...)— pre-existing). Not in scope for this PR; flagged for follow-up.