pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryn Llewellyn <bryn@yugabyte.com>
To: Neeraj M R <neerajmr12219@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Restricting user to see schema structure
Date: Thu, 12 May 2022 11:29:59 -0700
Message-ID: <E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com> (raw)
In-Reply-To: <e3b4ecf7-cda2-d47b-cc0e-2b91c3b1c127@aklaver.com>
References: <CANV4nBEqKefjxaBJkYrucGDLM41Tr0QehG2WBmoM_D2BXTUrfg@mail.gmail.com>
	<e3b4ecf7-cda2-d47b-cc0e-2b91c3b1c127@aklaver.com>

> adrian.klaver@aklaver.com wrote:
> 
>> neerajmr12219@gmail.com wrote:
>> 
>> Is there anyway that we can restrict a user from seeing the schema structure. I can restrict the user from accessing the data in the schema but the user is still able to see the table names and what all columns are present in them.
> 
> No.


Here’s something that you can do, Neeraj. But you have to design your app this way from the start. It'd be hard to retrofit without a re-write.

Design (and document the practice) to encapsulate the database functionality (i.e. the business functions that the client side app must perform) behind an API exposed as user-defined functions that return query results for SELECT operations and outcome statuses (e.g. "success", "This nickname is taken. Try a different one", "Unexpected error. Report incident ID NNNNN to Support"). JSON is a convenient representation for all possible return values.

Use a regime of users, schemas, and privilege grants (functions having "security definer" mode) to implement the functionality. Create a dedicated user-and-schema to expose the API and nothing else. This will own only functions that are thin jackets to invoke the real work-doing functions that are hidden from the client. Allow clients to authorize ONLY as the API-owning user.  Grant "execute" on its functions to what's needed elsewhere.

I've prototyped this scheme. It seems to work as designed. A client that connects with psql (or any other tool) can list the API functions and whatever \df and \sf show. (notice that \d will reveal nothing.)But doing this reveals only the names of the functions that are called (which will be identical to the jacket names—so no risk here) and the name(s) of the schema(s) where they live (so a minor theoretical risk here). 

Full disclosure: I've never done this in anger.

Note: I believe this approach to be nothing other than the application of the time-honored principles (decades old) of modular software construction (where the entire database is a top-level module in the over all app's decomposition). It brings the security benefit that I sketched along with all the other famous benefits of modular programming—esp. e.g. the client is shielded from table design changes.




view thread (31+ messages)  latest in thread

Message-ID: <E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com>
Permalink:  ../E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com/
Also on:    postgresql.org/message-id/E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: bryn@yugabyte.com, neerajmr12219@gmail.com, adrian.klaver@aklaver.com
  Subject: Re: Restricting user to see schema structure
  In-Reply-To: <E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com>
  References: <CANV4nBEqKefjxaBJkYrucGDLM41Tr0QehG2WBmoM_D2BXTUrfg@mail.gmail.com> <e3b4ecf7-cda2-d47b-cc0e-2b91c3b1c127@aklaver.com> <E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox