Re: Row security violation error is misleading

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: Row security violation error is misleading
Date: 2015-04-08 11:50:05
Message-ID: CAEZATCU-xtwR4Wr60grdijpZ_8aSa39XfdJ2-3TA=esJzdAa5Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7 April 2015 at 13:11, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
> When attempting to insert a row that violates a row security policy that
> applies to writes, the error message emitted references WITH CHECK OPTION,
> even though (as far as the user knows) there's no such thing involved.
> If you understand the internals you'd know that row security re-uses the
> same logic as WITH CHECK OPTION, but it's going to be confusing for users.
>
> postgres=> INSERT INTO clients (account_name, account_manager) VALUES
> ('peters', 'peter'), ('johannas', 'johanna');
> ERROR: 44000: new row violates WITH CHECK OPTION for "clients"
> DETAIL: Failing row contains (7, johannas, johanna).
> LOCATION: ExecWithCheckOptions, execMain.c:1683
>
>
> ... yet "clients" is a table, not a view, and cannot have a WITH CHECK
> OPTION clause.
>
> There is no reference to the policy being violated or to the fact that it's
> row security involved.
>
> I think this is going to be very confusing for users. I was expecting to see
> something more like:
>
> ERROR: 44000: new row in table 'clients' violates row level security policy
> 'just_own_clients'
>

Yes, I agree - that's a bit confusing.

Note that it doesn't make sense to ask which RLS policy was violated.
There is a default deny policy in place, and each defined policy's
quals are combined using OR, so when there are multiple policies this
error indicates that none of the policies passed (in a sense, they
were all violated).

> Re-using the SQLSTATE 44000 is a bit iffy too. We should probably define
> something to differentiate this, like:
>
> 44P01 ROW SECURITY WRITE POLICY VIOLATION
>

Yes, that sounds sensible.

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2015-04-08 11:52:51 Re: Row security violation error is misleading
Previous Message David Rowley 2015-04-08 10:00:36 Re: Parallel Seq Scan