Admin Oauth API#1472
Open
3kh0 wants to merge 4 commits into
Open
Conversation
Keep rollup refresh and assertions inside travel_to so weekly keys match the seeded heartbeats.
Contributor
Greptile SummaryThis PR adds OAuth access to the Admin API. The main changes are:
Confidence Score: 4/5Viewer OAuth tokens can reach Admin API write actions and this access path needs to be constrained before merging. OAuth token validity, scope, and current user role are checked on every request. Existing high-risk actions retain their explicit permission checks. Write actions that rely only on shared authentication can now be called by viewers. Admin API key creation provides a concrete viewer-accessible write path. app/controllers/api/admin/application_controller.rb and Admin API controllers with write actions
What T-Rex did
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Bearer token] --> B{Active Admin API key?}
B -->|Yes| C[Load key owner]
B -->|No| D{Valid OAuth token with admin scope?}
D -->|Yes| E[Load resource owner]
D -->|No| F[Return unauthorized]
C --> G{Staff admin level?}
E --> G
G -->|No| F
G -->|Yes, including viewer| H[Run Admin API action]
H --> I{Action has a role-specific guard?}
I -->|Yes| J[Enforce action permission]
I -->|No| K[Viewer can reach action]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Bearer token] --> B{Active Admin API key?}
B -->|Yes| C[Load key owner]
B -->|No| D{Valid OAuth token with admin scope?}
D -->|Yes| E[Load resource owner]
D -->|No| F[Return unauthorized]
C --> G{Staff admin level?}
E --> G
G -->|No| F
G -->|Yes, including viewer| H[Run Admin API action]
H --> I{Action has a role-specific guard?}
I -->|Yes| J[Enforce action permission]
I -->|No| K[Viewer can reach action]
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
app/controllers/api/admin/application_controller.rb:43
**Viewer Tokens Reach Write Actions**
A viewer can authorize the new `admin` scope and pass this shared authentication check, but some Admin API write actions have no separate viewer guard. For example, a viewer token can reach `POST /api/admin/v1/admin_api_keys` and mint an `hka_` credential, violating the viewer role's read-only contract. Enforce viewer-safe actions centrally or add role checks to every write endpoint.
Reviews (1): Last reviewed commit: "Fix flaky dashboard weekly stats test ti..." | Re-trigger Greptile |
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 of the problem
The Hackatime API is great, but juggling API keys is cringe, and frankly, I am on the 7th API key that I lost, so it's time to change that.
Describe your changes
Screenshots / Media
Scary notice when authing apps that request the admin scope