Add scoped API key auth for Gateway gRPC#166
Merged
Merged
Conversation
Bearer-token auth on SolverService and ExecutionService via tsk_<env>_<random>
opaque tokens. Scopes: read, reveal, wallet.execute:{address}, wallet.execute:*.
Token prefix is a hard environment scope (test vs live) — test keys can only
operate on testnet networks; GetRoutes/GetQuote filter or reject on env mismatch.
Stores SHA-256 of the token; raw value is shown once at creation. In-memory
60s absolute TTL cache so revocation propagates within one window.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EF migration creates the ApiKeys table with unique indexes on KeyHash and Name. Auth header swapped from `Authorization: Bearer` to `X-API-Key` (token sent as the raw header value, no prefix) — matches Stripe/Twilio/AWS convention and avoids confusion with OAuth/JWT auth flows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Header constant updated in interceptor + docs. StationAPI's SolverConfig gains an optional ApiKey field (read from station-config.json) and a client-side gRPC interceptor (ApiKeyClientInterceptor) that injects X-Train-API-Key on every outgoing solver call. Optional for backward compat with solvers that haven't enabled auth yet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sekhar-41745d # Conflicts: # csharp/src/StationAPI/Configuration/StationConfig.cs # csharp/src/StationAPI/station-config.json
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
SolverService+ExecutionServicevia opaquetsk_<env>_<random>tokens (~52 chars).read,reveal,wallet.execute:{address},wallet.execute:*.tsk_test_*keys can only operate on testnet networks,tsk_live_*only on mainnet.GetRoutes/GetQuotefilter or reject on env mismatch;SubmitTransaction/RevealSecret/GetOrder/GetTransactionStatusreject.SHA-256(token); raw value is shown once at creation, never retrievable afterwards./api/api-keys, AdminPanel page at/api-keyswith one-time token display..claude/rules/api-key-auth.md.Components
ApiKeyentity,IApiKeyRepository/EFApiKeyRepository,DbSet<ApiKey>with unique index onKeyHash.IApiKeyService/ApiKeyService(transient), singletonApiKeyCache. Token gen viaRandomNumberGenerator.GetBytes(32)+ base64url.SHA-256digest stored.ApiKeyAuthInterceptorregistered globally onAddGrpc.ApiKeyContextExtensions(RequireScope,RequireWalletExecute,RequireMatchingEnv) called per method.ApiKeys.razorwith create/view/revoke/delete and a one-time copy modal for the raw token.DB migration
Schema change adds
ApiKeystable with unique indexes onKeyHashandName. EF migration left for the user to generate per project convention.Test plan
dotnet ef migrations add AddApiKeysand apply.tsk_test_*key withreadscope via AdminPanel → callGetRoutes→ verify only testnet routes returned.GetQuotewith mainnet networks → expectPermissionDenied.tsk_live_*key withwallet.execute:0xABC...→ callSubmitTransactionfor that wallet on a mainnet network → succeeds.SubmitTransactionfor a testnet network → expectPermissionDenied.🤖 Generated with Claude Code