title: Possible to restrict PostgreSQL security definer function to RLS use?
body: <p>I am using RLS (Row Level Security) with supabase.io for a &quot;serverless&quot; application.  I have to use various security definer functions for RLS policies.  These are still callable through supabase's rpc library.  Is there anyway to limit calling these functions to either the admin (me) or when used as part of a RLS policy?</p>
  <p>e.g.:</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION get_bases_editable_or_viewable_for_user(user_id uuid, allow_edit bool)
  returns setof bigint as $$
    select base_id
    from access_controls
    where access_controls.user_id = $1 AND ($2 AND access_controls.access_level = 'editor') OR access_controls.access_level = 'viewer';
  $$ stable language sql security definer;
  
  CREATE policy &quot;Users can read bases they are editors or viewers of&quot;
  on public.bases
  for select using ( bases.id in (get_bases_editable_or_viewable_for_user(auth.uid(), true)) );
  </code></pre>
  <p><code>get_bases_editable_or_viewable_for_user</code> allows any user, once they have another user's UID, to find out the UIDs that this user has access to as an editor or viewer:</p>
  <pre class="lang-js prettyprint-override"><code>supabase.rpc(
    &quot;get_bases_editable_or_viewable_for_user&quot;,
    { user_id: &quot;dddddde6-1111-4bdf-aaaa-33336ccc31ee&quot;, allow_edit: true }
  )
  .then(console.log) // =&gt; bad
  </code></pre>
  <p>Minimising opportunities for leaking information is always important for maximising the security of an application and the privacy of its users.</p>