orders table where each signed-in user sees and changes only their own rows, then retrofit the same rule onto a table that already exists. The filter is ordinary Go in your handler file. Forge scaffolds it and checks that it stays there, but never injects a WHERE clause at runtime.
The security model explains why the rule is code you own.
Before you begin
- The
shopproject from Add a database table with a CRUD API and pages. Any forge API works the same way. - Forge v1.6.1 or later, run as
reliant forgeinside the project. - Find API endpoints that never check who is calling shows the audit this guide uses to confirm the result.
1
Declare who owns a row
Mark the owner field on the entity before you scaffold it.
forge:read-only keeps it off the create request, so the server stamps it from the caller instead.proto/services/catalog/v1/catalog.proto
2
Scaffold the entity
terminal
db/migrations/20261120100303_create_orders.up.sql
handlers_crud.go resolves the caller and adds the owner to the query: Get, Update and Delete match owner_id, List filters before it counts, and Create and Update stamp the column. Another user’s row reports not_found, the same as an id that doesn’t exist, so a caller can’t probe which ids are real.3
Map the caller to the owner value
Each of the five wrappers leaves one decision to you:
internal/handlers/catalog/handlers_crud.go
claims.UserID is the token’s subject. Keep it if owner_id stores that id; for rows owned by a team, use a column holding the org and claims.OrgID. Use a stable id, never an email address. Make the same choice in all five wrappers, then delete the FORGE_SCAFFOLD comments. lint --conventions flags a wrapper whose owner source differs from its siblings’.4
Confirm with the audit
terminal
jq output
GetOrder with a plain delegation, the audit fails.reliant forge project audit then exits 1, and the JSON’s owner_scoped_unscoped_rpcs[].remediation holds the wrapper to paste back.5
Prove it with two users
The audit proves each handler reads the caller. A test proves the filter. Create an order as one user and try every operation as another:Bob’s update sent
internal/handlers/catalog/order_owner_test.go
terminal
owner_id: "bob" in the body. It was still refused, because the predicate is checked against the stored row.6
Scope a table that already exists
handlers_crud.go already exists for reviews, so declaring an owner can’t regenerate it. Add the column and the comment in a new migration, and the field to the Review message (string author_id = 9; // forge:read-only):terminal
db/migrations/20261120102807_add_reviews_author.up.sql
reliant forge generate. The audit now fails for all five Review RPCs and prints each wrapper:terminal
// forge:auth-unscoped-ok: every signed-in shopper reads every review; only writes are the author's. With the product RPCs handled as in the previous guide, the audit is clean:DeleteReview returns not_found: review not found for him.What this does not do
- No runtime filter. Forge never adds a
WHEREclause on its own. A query you write yourself, in a custom RPC orinternal/db/*_repo_ext.go, needs its own filter, and the audit can’t arm the gate for a custom RPC. - No database row-level security. The rule lives in the API. Anything that connects to Postgres directly bypasses it.
- No roles or sharing model. One column names one owner. Shared rows, teams with several roles, or admin overrides are handler code you add.
- The audit can’t judge your mapping. It checks that each handler reads the caller, not that
ownerholds the right value; your tests do that.
Troubleshooting
[forgeconv-crud-owner-resolver] … scopes owner_id by …
[forgeconv-crud-owner-resolver] … scopes owner_id by …
The wrappers for one entity resolve the owner in different ways. Make every wrapper use the same expression. While one still reads
claims.UserID with its FORGE_SCAFFOLD comment, the lint treats it as undecided and suggests the other source, so read the suggestion before you apply it.The proto marker did nothing on an existing entity
The proto marker did nothing on an existing entity
// forge:owner on a proto field is read only when the entity is scaffolded. On an existing table, use the migration path in the last step.Every List returns zero rows
Every List returns zero rows
The owner values in the table don’t match what the wrapper computes from the claims. Check rows created before the column existed (empty owner) and that all wrappers use the same claim.
Next steps
Find unchecked endpoints
List every RPC that never reads the caller, and add role checks
Security model
Fail-closed auth, the owner gate and error redaction
Add sign-in
Passkeys, magic links or social login, and the RPCs that stay public
Zero-downtime migrations
Add the owner column without breaking the running release