refactor: remove unused serviceuser-user relation from SpiceDB schema#1561
refactor: remove unused serviceuser-user relation from SpiceDB schema#1561whoAbhishekSah merged 2 commits intomainfrom
Conversation
The `user` relation on `app/serviceuser` and the `CreatedByUser` field were scaffolded but never wired up — the handler never populates the creator, so the relation is never written. The audit record already captures who created the service user via the actor context. This simplifies the `manage` permission to just `org->serviceusermanage`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 22 minutes and 28 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Update the test golden file to match the removed `user` relation and simplified `manage` permission on `app/serviceuser`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Coverage Report for CI Build 24713216959Coverage increased (+0.02%) to 42.085%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Manual end-to-end test reportSimulated the full SDK flow against this branch: create SU → project policy → token → authed calls. Also tested the delete path to check for regressions. SDK flow
Schema + permission (the focus of this PR)
Delete flow
Observations1. Leak in delete flow — pre-existing, not introduced here. Reproduced on a fresh SU with no tokens/policies; the leaks still occur. Root cause in s.relationService.Delete(ctx, relation.Relation{
Subject: relation.Subject{ID: id, Namespace: schema.ServiceUserPrincipal},
})Only deletes relations where the SU is the Subject. Relations where the SU is the Object (e.g. 2. Minor auth-contract note. The SDK description in the test ask mentioned "bearer" auth, but opaque SU tokens actually authenticate via VerdictLGTM. The |
There was a problem hiding this comment.
Pull request overview
Removes an unused user relation and related dead code from the ServiceUser authorization model, aligning the SpiceDB schema with how service users are actually created and audited in the codebase.
Changes:
- Remove
relation user: app/userfromapp/serviceuserin the SpiceDB schema. - Simplify
app/serviceuser.managepermission toorg->serviceusermanageonly. - Remove the transient
CreatedByUserfield and the (previously unreachable) conditional relation creation logic.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/bootstrap/testdata/compiled_schema.zed | Updates compiled schema snapshot to drop serviceuser.user relation and simplify manage permission. |
| internal/bootstrap/schema/base_schema.zed | Removes serviceuser.user relation and updates manage permission definition in the base schema. |
| core/serviceuser/serviceuser.go | Removes unused transient CreatedByUser field from ServiceUser struct. |
| core/serviceuser/service.go | Removes conditional creation of serviceuser#user@... relation during service user creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
userrelation fromapp/serviceuserSpiceDB schema — it was never written (handler never setsCreatedByUser)managepermission to justorg->serviceusermanageCreatedByUsertransient field from the service user struct and the conditional relation creation codeWhy this is safe to delete
The relation was never written. The
CreateServiceUserhandler (serviceuser.go:145) constructs theServiceUserstruct without settingCreatedByUser. The conditional block inservice.go:110(if len(serviceUser.CreatedByUser) > 0) was therefore never entered — zeroserviceuser#user@<creator>tuples exist in SpiceDB.The
managepermission loses nothing. Before:permission manage = org->serviceusermanage + user. Sinceuserwas never populated, the effective permission was already justorg->serviceusermanage. This change makes the schema match reality.Creator attribution is already captured. Two independent audit mechanisms record who created a service user:
serviceuser_repository.go:125):BuildAuditRecordcaptures the authenticated actor (ID, type, name) from request context viaenrichActorFromContext, stored in theaudit_recordstable within the same transaction as the insert.serviceuser.go:163):audit.GetAuditor(ctx, orgID).LogWithAttrs(ServiceUserCreatedEvent, ...)emits a separate audit event with the acting user from context.Both paths derive the creator from the auth context — no struct field or SpiceDB relation needed.
Context
Part of the membership package migration (#1478). This cleans up dead code before migrating service user org membership to the
core/membershippackage.Test plan
🤖 Generated with Claude Code