fix(auth): honor trusted root api key role#1725
Open
Hinotoi-agent wants to merge 1 commit into
Open
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨No code suggestions found for the PR. |
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
Fixes #1722.
In trusted mode, requests authenticated with the configured
root_api_keywere accepted as valid trusted requests but still resolved toRole.USERunless the supplied account/user existed in the API key manager with a higher role. That meantov reindex --sudocould send the right root key and tenant headers, but privileged non-admin routes such as/api/v1/maintenance/reindexstill failed withPERMISSION_DENIED.This PR makes the trusted-mode root key behave as the deployment-level root credential after it has been validated.
What changed
root_api_key.Role.ROOTwhile preserving the explicit tenant headers on the resulting identity.ROOT/ADMIN, matching theov reindex --sudofailure mode.Relationship to prior work
This complements #1589, which wired
--sudoto useroot_api_keyon the CLI side. That PR made the client send the correct credential; this PR fixes the remaining server-side trusted-mode role resolution so the credential satisfies privileged route checks.Related but different prior work:
NewAPIKeyManager.get_user_roleproxy regression that caused 500s, but not theroot_api_keyresolving asUSERbehavior.Files changed
openviking/server/auth.pyroot_api_keyrequests now resolve asRole.ROOT.tests/server/test_auth.pyTest plan
PYTHONPATH=. /Users/$USER/.hermes/hermes-agent/venv/bin/python -m py_compile openviking/server/auth.py tests/server/test_auth.pyPYTHONPATH=. /Users/$USER/.hermes/hermes-agent/venv/bin/python -m pytest -o addopts='' tests/server/test_auth.py::test_trusted_mode_with_root_api_key_requires_matching_api_key tests/server/test_auth.py::test_trusted_mode_with_root_api_key_accepts_matching_api_key tests/server/test_auth.py::test_trusted_mode_http_routes_require_api_key_when_root_key_configured tests/server/test_auth.py::test_trusted_mode_http_routes_accept_api_key_when_root_key_configured tests/server/test_auth.py::test_trusted_mode_root_api_key_grants_root_role_for_maintenance_routes -qruff check openviking/server/auth.py tests/server/test_auth.pyruff format --check openviking/server/auth.py tests/server/test_auth.pygit diff --checkNote: I also tried the full
tests/server/test_auth.pyfile locally, but unrelated existing fixture setup in this environment reads the operator's~/.openviking/ov.confand fails before many tests run because local Volcengine embedding/VLM API keys are not configured. The focused auth tests above avoid that unrelated environment dependency and cover this regression directly.