Repository navigation
feat(authkeys): labels on managed API keys applied to every request #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
54561c6
feat(authkeys): labels on managed API keys applied to every request
SantiagoDePolonia b4eddc1
refactor(usage): reuse shared sqlutil JSON label column helpers
SantiagoDePolonia d528d50
fix(dashboard): swap mobile theme toggle icon instead of stacking one…
SantiagoDePolonia 2197f45
fix(authkeys): unset mongo labels field on clear instead of storing null
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| --- | ||
| title: "Labelling" | ||
| description: "Attach labels to requests from HTTP headers or API keys, and break down usage and audit logs by label." | ||
| icon: "tags" | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| Labels tag every request for attribution: which team, feature, job, or | ||
| environment produced the traffic. A request can be labelled two ways, and both | ||
| can apply at once: | ||
|
|
||
| - **Tagging headers** — labels extracted from configured HTTP headers on each request. | ||
| - **API key labels** — labels bound to a managed API key, applied to every request authenticated with it. | ||
|
|
||
| Labels from both sources are merged and de-duplicated. They are recorded on | ||
| usage entries and audit log entries, and power the by-label usage breakdown in | ||
| the dashboard. | ||
|
|
||
| ## API key labels | ||
|
|
||
| Assign labels when creating a key in the admin dashboard: | ||
|
|
||
| `API Keys -> Create API Key -> Labels` | ||
|
|
||
| Or via the admin API: | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:8080/admin/auth-keys \ | ||
| -H "Authorization: Bearer $GOMODEL_MASTER_KEY" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"name": "team-a-batch", "labels": ["team-a", "batch-jobs"]}' | ||
| ``` | ||
|
|
||
| Every request authenticated with that key carries those labels — no client | ||
| changes needed. This is the simplest way to attribute traffic per team or | ||
| service: issue each consumer its own labelled key. | ||
|
|
||
| Labels can be changed later without rotating the key, in the dashboard | ||
| (`API Keys -> Edit Labels`) or via the admin API: | ||
|
|
||
| ```bash | ||
| curl -X PUT http://localhost:8080/admin/auth-keys/<key-id>/labels \ | ||
| -H "Authorization: Bearer $GOMODEL_MASTER_KEY" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"labels": ["team-a", "realtime"]}' | ||
| ``` | ||
|
|
||
| The new list replaces the old one; send `[]` to remove all labels. Changes | ||
| apply to new requests immediately on the instance that served the update and | ||
| within about a minute on other replicas (keys refresh from storage in the | ||
| background). | ||
|
|
||
| ## Tagging headers | ||
|
|
||
| Tagging rules name headers whose values carry labels. Manage them in the | ||
| dashboard (`Settings -> Tagging based on headers`) or declare them as | ||
| infrastructure-as-code: | ||
|
|
||
| ```yaml config.yaml | ||
| tagging: | ||
| headers: | ||
| - header: X-My-Tags | ||
| prefix: "tag-" # optional: "tag-alpha, beta" → labels "alpha", "beta" | ||
| - header: X-Internal-Routing | ||
| do_not_pass: true # stripped before forwarding to the provider | ||
| delimiter: ";" # default: "," | ||
| ``` | ||
|
|
||
| Or with environment variables (an env entry replaces the whole YAML entry with | ||
| the same header name; unset companion vars reset to defaults): | ||
|
|
||
| ```bash | ||
| TAGGING_HEADER_1=X-My-Tags | ||
| TAGGING_HEADER_1_PREFIX=tag- # optional, trimmed from each extracted label only | ||
| TAGGING_HEADER_1_DONOTPASS=true # optional, default false (headers are forwarded as-is) | ||
| TAGGING_HEADER_1_DELIMITER=";" # optional, default "," | ||
| ``` | ||
|
|
||
| A client then labels a request like this: | ||
|
|
||
| ```http | ||
| X-My-Tags: tag-alpha, beta | ||
| ``` | ||
|
|
||
| Rules declared in `config.yaml` or env are read-only in the dashboard. | ||
| Credential-bearing headers (`Authorization`, `Cookie`, API-key headers) are | ||
| rejected as tagging sources. | ||
|
|
||
| `do_not_pass` strips the header before forwarding on passthrough and realtime | ||
| routes; translated routes never forward client headers anyway. | ||
|
|
||
| ## Where labels show up | ||
|
|
||
| - **Usage dashboard** — the usage page shows a by-label breakdown | ||
| (`GET /admin/usage/labels`). A request with several labels counts once under | ||
| each of them. | ||
| - **Request log** — label chips per request, filterable with the `label` query | ||
| param on `GET /admin/usage/log`. | ||
| - **Audit logs** — recorded under `data.labels` on each entry (requires | ||
| `LOGGING_ENABLED=true`). | ||
| - **API keys page** — each key's labels are listed alongside its user path. | ||
|
|
||
| ## Defaults | ||
|
|
||
| Labelling is on by default and costs nothing until you configure a tagging | ||
| rule or create a labelled key. Requests without labels are tracked as before. |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Redundant
submittingreset after editor is closed.Line 362 sets
editor.submitting = falsebeforecloseAuthKeyLabelsEditor()reassignsthis.authKeyLabelsEditorto a fresh object; thefinallyblock at Line 368 then mutates the now-orphaned oldeditorreference. Harmless today, but worth simplifying so the intent (whysubmittingmust be cleared before close) is clearer to future readers.♻️ Simplify submit/close ordering
📝 Committable suggestion
🤖 Prompt for AI Agents