Skip to main content
You will make an 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

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
The migration records the declaration in the schema, where forge reads it from now on:
db/migrations/20261120100303_create_orders.up.sql
Every Order handler in 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
The five Order RPCs are scoped. The other ten were unscoped before this guide. Declaring the owner also armed a gate: if someone later replaces 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:
internal/handlers/catalog/order_owner_test.go
terminal
Bob’s update sent 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
Existing rows get an empty owner, which no caller matches; backfill them in the same migration if you know their authors. Run reliant forge generate. The audit now fails for all five Review RPCs and prints each wrapper:
terminal
Paste the wrappers for Create, Update and Delete over the plain delegations. Reviews are public to shoppers, so mark the two reads instead: // 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:
A test like the one above confirms that Bob can read Alice’s review but DeleteReview returns not_found: review not found for him.

What this does not do

  • No runtime filter. Forge never adds a WHERE clause on its own. A query you write yourself, in a custom RPC or internal/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 owner holds the right value; your tests do that.

Troubleshooting

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.
// 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.
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