relational-permissions
Skill1 starsChanged 5 months agoMITView on GitHub
Configure permissions on junction and child collections so that nested relational writes (M2M, O2M, M2A) are enforced at every level — not just the parent. Use when setting up write access for collections that participate in relational fields, or when debugging silent no-ops on nested mutations.
In this repository59 other files it gives its agents.
- add-buildpadSkill
- add-external-oauthSkill
- add-filesSkill
- add-i18nSkill
- add-microappSkill
- add-microfrontendSkill
- add-microfrontend-zonesSkill
- add-multitenancySkill
- add-usersSkill
- amplify-env-varsSkill
- authentication-proxySkill
- buildpad-debugSkill
- buildpad-discoverySkill
- buildpad-implSkill
- buildpad-referenceSkill
- buildpad-reviewSkill
- buildpad-spec-batchSkill
- buildpad-spec-designSkill
- buildpad-spec-initSkill
- buildpad-spec-quickSkill
- buildpad-spec-requirementsSkill
- buildpad-spec-statusSkill
- buildpad-spec-tasksSkill
- buildpad-steering-customSkill
- buildpad-steeringSkill
- buildpad-validate-designSkill
- buildpad-validate-gapSkill
- buildpad-validate-implSkill
- buildpad-verify-completionSkill
- code-simplificationSkill
- context-engineeringSkill
- create-api-routeSkill
- create-collectionSkill
- create-componentSkill
- create-cronSkill
- create-featureSkill
- create-form-builderSkill
- create-migrationSkill
- create-projectSkill
- create-rbacSkill
- create-serviceSkill
- create-testsSkill
- create-workflowSkill
- daas-platformSkill
- debugging-and-error-recoverySkill
- generate-docsSkill
- git-workflow-and-versioningSkill
- grant-module-accessSkill
- hooks-extensionsSkill
- idea-refineSkill
- incremental-implementationSkill
- manage-scopeSkill
- performance-optimizationSkill
- planning-and-task-breakdownSkill
- review-codeSkill
- security-and-hardeningSkill
- spec-driven-developmentSkill
- subagent-delegationSkill
- worker-messagingSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
When a client sends a PATCH to a parent collection with nested relational data:
- Distinctive: line 76
Use MCP to query:
- Very specific: line 236
Do not create any create/update/delete permission on the junction collection.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Relational Permissions
Configure permission enforcement for nested relational writes so that create/update/delete operations on junction and child collections are gated by the same two-layer model as top-level collections.
Why This Matters
When a client sends a PATCH to a parent collection with nested relational data:
PATCH /api/items/cmp_catalogues/:id
{
"catalogue_services": {
"create": [{ "service_id": "...", "quantity": 1 }],
"delete": ["junction-row-id"]
}
}The platform checks permission on cmp_catalogues (the parent). Without relational permission enforcement, the write to cmp_catalogue_services (the junction table) would execute without any permission check — any user with update on the parent could freely create/delete junction rows.
With relational permissions enabled, the platform also checks:
createoncmp_catalogue_services(for thecreateblock)deleteoncmp_catalogue_services(for thedeleteblock)
Two-Layer Enforcement Model
Request with nested relational data
│
├─ Layer 1: Gate Check (boolean)
│ "Does the user have ANY permission for this action on this child collection?"
│ → 403 if no → abort
│
└─ Layer 2: Item-Level Filter
"Which specific rows can the user touch?"
→ Resolved from daas_permissions.permissions JSONB
→ Applied as WHERE clause on UPDATE/DELETE
→ Applied as validation/fields/presets on INSERTLayer 1 — Gate Check
Uses check_permission_with_scope (scope-aware) or check_permission (flat). Returns true/false. Cached per request.
Layer 2 — Item-Level Filter
| Operation | How applied |
| UPDATE | Filter merged into WHERE clause — non-matching rows unchanged |
| DELETE | Filter merged into WHERE clause — non-matching rows kept |
| Nullify (O2M deselect) | Same as UPDATE |
| INSERT | fields (allowlist), validation (pre-check), presets (server defaults) |
Setup Steps
Step 1 — Identify the child/junction collections
For each relational field on the parent collection, identify the target table:
| Relation type | Target table |
| M2M | Junction table (from daas_relations.many_collection where junction_field is set) |
| O2M | Child table (from daas_relations.many_collection) |
| M2A | Junction table + each target collection in one_allowed_collections |
Use MCP to query:
{
"method": "tools/call",
"params": {
"name": "read_items",
"arguments": {
"collection": "daas_relations",
"query": {
"filter": { "one_collection": { "_eq": "cmp_catalogues" } }
}
}
}
}Step 2 — Create permissions on the child/junction collection
For each action the user needs on the child collection, create a daas_permissions row under the appropriate policy:
{
"method": "tools/call",
"params": {
"name": "create_item",
"arguments": {
"collection": "daas_permissions",
"item": {
"policy": "<policy-uuid>",
"collection": "cmp_catalogue_services",
"action": "create",
"fields": ["catalogue_id", "service_id", "quantity", "unit_price"],
"presets": {
"user_created": "$CURRENT_USER"
},
"permissions": null,
"validation": null
}
}
}
}Repeat for update and delete as needed:
{
"method": "tools/call",
"params": {
"name": "create_item",
"arguments": {
"collection": "daas_permissions",
"item": {
"policy": "<policy-uuid>",
"collection": "cmp_catalogue_services",
"action": "delete",
"permissions": {
"user_created": { "_eq": "$CURRENT_USER" }
}
}
}
}
}Step 3 — Verify with the audit endpoint
GET /api/utils/audit-relational-permissionsThis returns a report of all junction/child collections that are missing permissions for roles with parent access. After your setup, the child collection should no longer appear in the gap report.
Step 4 — Enable enforcement
Set the environment variable:
ENFORCE_RELATIONAL_PERMISSIONS=true⚠️ In warn mode (false, default), violations are logged but not blocked. Switch to true only after all permissions are seeded.
Filter Rule Constraints
🔴 CRITICAL: Not all filter patterns work on child/junction mutation queries. When writing permissions JSONB rules for child collections, use only the patterns marked ✅ below.
Supported (use these)
| Pattern | Example |
| Scalar operators | { "status": { "_eq": "active" } } |
_in / _nin | { "type": { "_in": ["A", "B"] } } |
_null / _nnull | { "deleted_at": { "_null": true } } |
| String operators | { "name": { "_starts_with": "TMP-" } } |
_between / _regex | { "sort": { "_between": [1, 100] } } |
_and / _or (scalar only) | { "_and": [{ "status": { "_eq": "draft" } }, { "user_created": { "_eq": "$CURRENT_USER" } }] } |
$CURRENT_USER / $CURRENT_POLICIES | { "user_created": { "_eq": "$CURRENT_USER" } } |
Unsupported — do NOT use on child collections
| Pattern | Why | Impact if used |
_has (relation existence) | PostgREST UPDATE/DELETE don't support !inner joins | Filter silently ignored — wider access than intended |
Dot-notation (owner.status) | Same as _has — requires embedded-resource joins | Filter silently ignored |
_some / _none | Not implemented in filter translator | Operator silently skipped — wider access |
_or mixing scalar + relational | Relational branch silently dropped | Partial enforcement only |
Nesting Depth Limit
Relational writes are processed one level deep. Nested relational fields inside a child record payload are not recursively processed.
✅ parent → child (1 level)
❌ parent → child → grandchild (2 levels — grandchild ignored)To mutate deeper levels, issue separate API calls for each level.
Common Patterns
Full junction access scoped to current user
{
"action": "create",
"collection": "catalogue_services",
"fields": ["catalogue_id", "service_id", "quantity", "unit_price"],
"presets": { "user_created": "$CURRENT_USER" }
}{
"action": "delete",
"collection": "catalogue_services",
"permissions": { "user_created": { "_eq": "$CURRENT_USER" } }
}O2M child with field restriction + validation
{
"action": "create",
"collection": "order_items",
"fields": ["product_id", "quantity", "unit_price"],
"validation": { "quantity": { "_gte": 1, "_lte": 100 } },
"presets": { "user_created": "$CURRENT_USER" }
}Read-only junction (user cannot modify relations)
Do not create any create/update/delete permission on the junction collection. The gate check will reject all mutation attempts.
References
- Relational Permissions Documentation
- Create RBAC Skill
- Grant Module Access Skill
- Manage Scope Skill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

