Rezin Core Rezin Core
Docs

Database

Why was this refused?

When your application is refused a row, or is given fewer rows than you expected, Rezin Core can show you the decision: what was checked, in what order, and the exact part of a rule that decided it. It works for a refusal that already happened and for one you want to try before it does.

Nothing is changed by asking. A read-only member of the company can use it.

Where it is

  • Security, Access rules. Every table's card has Why?
  • Refused lately, on the same page: the requests through the API that the rules turned away, newest first. Press Why? beside one and the question is filled in for you.
  • The command-line tool: rezin explain-access.
  • The connector for AI coding assistants: the explain_access tool, under the database permission.

Asking

Say three things:

  1. What is being done: read, add, change or delete.
  2. Who is asking:
    • a signed-in account of your application;
    • your own server with the secret key, acting for an organization, with nobody signed in;
    • a visitor: the publishable key and nobody signed in.
  3. Which row. For reading you may leave it at "the whole table" and get counts. For changing and deleting, pick the row. For adding, give the new row's values; for changing, the values being set.

What you get

The verdict, allowed or refused, and what decided it, in a sentence.

The steps, in the order the database takes them:

  1. Who is asking, and what the database is told about them.
  2. Whether the application may do this to the table at all. If not, no rule is even looked at.
  3. Whether row-level security is on. If it is off, every row passes, for everyone.
  4. The rules.

Each rule that applies, with its result for this row and this caller. A rule made of parts joined by "and" or "or" is shown part by part, so you see which one decided. Where a part compares two things, both values are shown:

The ruleWhat it compared
Does not holdorganization_id = core.app_org()the row's organization_id 7c1e… = the caller's organization 2a90…

A rule that mixes "and" and "or" in a way that cannot be taken apart safely is shown whole, with its one result, and the page says so.

To change this: the smallest change that would allow it, as a proposal you can open in the rule editor. Nothing is applied for you. When the only change available would open the table to everyone, the proposal says so in plain words.

Worked examples

"My user cannot see a row they should"

Table notes, rule own_org: organization_id = core.app_org(). Ask: read, as that user, that row.

Refused. This row is hidden: none of the rules that could allow it holds for this row and this caller. The row's organization_id is 7c1e…, and the caller's organization is 2a90….

The row belongs to another organization. Either the row was saved with the wrong organization, or the person is in the wrong one. The rule is doing its job.

"My server gets nothing, but the app does"

Rule: organization_id = core.app_org() and core.app_user() is not null. Ask: read, as your server with the secret key.

The part core.app_user() IS NOT NULL is false: nobody is signed in, so this is empty.

A request made with the secret key has an organization and no account. A rule that needs an account never holds for it.

"Adding a row fails with 403"

Ask: add, as the user, with the values your application sends.

Refused by the check on new values of rule "add_own": the row as it would be added does not satisfy it. The row's organization_id is 7c1e…, and the caller's organization is 2a90….

Your application is sending another organization's ID, or none. Send the caller's own.

"Nothing can read the table at all"

Refused: no rule lets the application read rows of prices.

Row-level security is on and there is no rule, so the table is closed. The proposal is the narrowest rule the table allows. For a table with no organization or owner column the only rule available is "every signed-in account", and the proposal warns that it opens every row to all of them.

"A visitor gets 401"

Refused: nobody is signed in. With the publishable key, a table can be reached only by a signed-in account.

That request never reaches the database.

From a refusal your application received

When the rules refuse a request, the answer carries a short ID:

{ "error": "not_allowed", "message": "That row is outside what this account may write.", "requestId": "rq_k3v9x2m7q1ab" }

The same ID is on the Refused lately list, with the table, the action, who was asking and when. Nothing of the row or the request's values is kept. The list holds the newest 200 for a project.

Reads are different: a row the rules hide is simply not returned, so there is no refusal to list. Ask about the row from the table's card.

From the command line

rezin explain-access notes read --user 3f2b… id=9d41…
rezin explain-access notes add --user 3f2b… --set organization_id=7c1e… --set body=hello
rezin explain-access notes change --org 2a90… id=9d41… --set body=edited
rezin explain-access prices read --visitor

key=value names the row. --set gives the new row, or the values being set.

How it is worked out

The rules are read as the database stores them and checked one at a time for the row and the caller, with the caller's identity set exactly as the API sets it. The action is then attempted as your application's own database role inside a transaction that is always undone, and the database's own answer is the verdict. If the two ever differ (a rule that looks into another table, a trigger, a constraint), the database's answer is the one shown and the page says so.

Everything runs inside your project's own part of the database, with a time limit. Each question is on the project's record: the table, the action and the kind of caller, never a row.

This page as Markdown · llms.txt · Rezin Core is in development and available by invitation.