feat: add --api-key flag for persistent external API access#32
Merged
Conversation
Adds a static, non-expiring API key that enables external tools to access the Mesa API without relying on ephemeral per-run agent keys. Changes: - New --api-key <key> CLI flag (also MESA_API_KEY_EXTERNAL env) - Auth middleware checks the external key before DB lookup - External key resolves to a synthetic 'external' agent in context - New GET /api/v1/issues endpoint for listing all issues (with ?status= and ?limit= filters) - 3 new tests covering external key auth (valid, wrong value, not set) The external key is intended for orchestration tools, CI/CD pipelines, and external agents that need to create issues, read status, or post comments without being part of the internal agent roster. Usage: mesa --api-key my-secret-key -t enterprise 3001 curl -H 'Authorization: Bearer my-secret-key' http://localhost:3001/api/v1/issues
Owner
|
LGTM, thank you! |
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
Adds a static, non-expiring API key that enables external tools to access the Mesa API without relying on ephemeral per-run agent keys.
Problem
Mesa's current API keys are dynamically generated per-run, scoped to individual agents, and expire after 60 minutes. This makes it impossible for external orchestration tools, CI/CD pipelines, or wrapper agents to interact with Mesa's API — they can't obtain a valid key without being part of the internal agent roster.
Solution
A new
--api-key <key>CLI flag (andMESA_API_KEY_EXTERNALenv var) that configures a persistent external API key:Changes
cmd/mesa/main.go--api-keyflag andMESA_API_KEY_EXTERNALenv, wire to API, print usage on startupinternal/handlers/api.goSetExternalKey(), check external key inAuth()middleware before DB lookup, addGET /api/v1/issueslist endpointinternal/handlers/handlers_test.goDesign Decisions
externalagent so endpoints that callagentFromContext()work correctlyGET /api/v1/issues?status=&limit=since external callers need to list all issues (not just an agent's inbox)--api-keyis not providedTesting
All existing tests pass. 3 new tests added:
TestAuthExternalKey— valid key returns 200 with external agent in contextTestAuthExternalKeyWrongValue— wrong key returns 401TestAuthExternalKeyNotSet— without external key configured, falls through to DB lookupUse Case
I'm building an orchestration layer where an external agent (running outside Mesa) creates work blocks, injects issues, and reads results via the API. The current ephemeral keys make this impossible without direct SQLite access.