[superlog] Add manage:websites scope to insights service auth#470
[superlog] Add manage:websites scope to insights service auth#470superlog-app[bot] wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
The latest updates on your projects. Learn more about Unkey Deploy
|
Greptile SummaryAdds
Confidence Score: 4/5Safe to merge; fixes a real auth gap that was blocking every scheduled mutation in the insights agent. The fix is correct and minimal. The No files require special attention beyond the single changed line. Important Files Changed
Sequence DiagramsequenceDiagram
participant Scheduler
participant InsightsWorker as Insights Worker (runInsightsAgent)
participant ToolLoopAgent as ToolLoopAgent (AI)
participant RPC as callRPCProcedure
participant ServiceAuth as createServiceAuth
participant WithWorkspace as withWorkspace
participant ScopeCheck as requiredScopesForResource
Scheduler->>InsightsWorker: Trigger scheduled run
InsightsWorker->>InsightsWorker: "Build AppContext serviceAuth.scopes = [read:data, manage:websites]"
InsightsWorker->>ToolLoopAgent: run(tools, context)
ToolLoopAgent->>RPC: update_goal(websiteId, ...)
RPC->>ServiceAuth: createServiceAuth(orgId, scopes)
ServiceAuth-->>RPC: synthetic apiKey with scopes
RPC->>WithWorkspace: "withWorkspace(ctx, { websiteId, permissions: [update] })"
WithWorkspace->>WithWorkspace: "effectiveResource = website (because websiteId present)"
WithWorkspace->>ScopeCheck: requiredScopesForResource(website, [update])
ScopeCheck-->>WithWorkspace: [manage:websites]
WithWorkspace->>WithWorkspace: hasKeyScope(apiKey, manage:websites) OK
WithWorkspace-->>RPC: Workspace
RPC-->>ToolLoopAgent: success
Reviews (1): Last reviewed commit: "[superlog] Add manage:websites scope to ..." | Re-trigger Greptile |
| serviceAuth: { | ||
| organizationId: params.organizationId, | ||
| scopes: ["read:data"], | ||
| scopes: ["read:data", "manage:websites"], |
There was a problem hiding this comment.
manage:websites scope is wider than the current mutation tools require
manage:websites is the correct scope to unblock goal/funnel/annotation mutations (per RESOURCE_SCOPE_OVERRIDES), but it also grants authority over the website entity itself — domain name changes, deletion, etc. Right now the actual tool set is the effective limiter, but if a new tool is later added to the "mutations" capability (e.g. delete_website, update_website_domain) it would silently inherit this scope without any corresponding auth review. Consider documenting the intent here (e.g. a comment listing the specific mutation types this scope is intended to cover) so future contributors know to re-evaluate the scope if the tool set expands.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
The insights agent's goal auto-update feature fails with
FORBIDDEN: API key missing required scope: manage:websiteson every scheduled run that triggers a goal mutation.The insights agent is initialized with
capabilities: ["investigation", "mutations"], giving it tools likeupdate_goal,create_goal,create_funnel, andcreate_annotation. These tools callwithWorkspace(context, { websiteId, permissions: ["update"] })in the RPC layer. Because awebsiteIdis always passed,withWorkspaceresolves the effective resource as"website", which maps the"update"permission to the"manage:websites"scope viaRESOURCE_SCOPE_OVERRIDES. The service auth inrunInsightsAgentonly declared["read:data"], so every mutation call is rejected.The fix adds
"manage:websites"to the insights service auth scopes so that the agent can perform all website-scoped mutations it already has tools for.Alternative approach: instead of widening the service auth scope, goal/funnel/annotation mutations could be extracted to a separate worker call that uses full user credentials. This would be more restrictive but adds significant complexity. The current service-auth pattern already exists for internal service calls and widening it to
manage:websitesis the minimal correct fix given howwithWorkspaceresolves the resource.Incident on Superlog
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Adds the
manage:websitesscope to insights service auth so the agent can run website-scoped mutations. Fixes FORBIDDEN errors during scheduled goal auto-updates.runInsightsAgentservice auth to include["read:data", "manage:websites"].withWorkspace(..., { permissions: ["update"] })resolving to website resource which requiresmanage:websites.Written for commit fbc1007. Summary will update on new commits.