Re: Row-level security--is it possible?

Поиск
Список
Период
Сортировка
От Doug McNaught
Тема Re: Row-level security--is it possible?
Дата
Msg-id 878ye2xyzi.fsf@asmodeus.mcnaught.org
обсуждение исходный текст
Ответ на Row-level security--is it possible?  (Michal Taborsky <michal@taborsky.cz>)
Ответы Re: Row-level security--is it possible?  (Michal Taborsky <michal@taborsky.cz>)
Список pgsql-general
Michal Taborsky <michal@taborsky.cz> writes:

> Hello.
>
> We are currently facing a design issue, which I am a bit stuck
> with. We are talking about row-level access regulation. I'll make it
> clear with an example.
>
> Let there be a table of products:
>
> CREATE TABLE products
> (
>     Product_ID serial,
>     Name text,
>     Producer_ID int4 NOT NULL,
>     PRIMARY KEY (Product_ID)
> )
>
> We have two users Joe and Pete. The thing is, that Pete is just an
> intern and should have access only to products from a specific
> producer, while Joe should have unlimited access. Of course we could
> resolve it on application level (PHP/Apache), but that I don't want to
> do. My first idea was to create specific views for every user, like
> this:
>
> CREATE VIEW products_pete AS
> SELECT * FROM products WHERE Producer_ID=1;
>
> and
>
> CREATE VIEW products_joe AS
> SELECT * FROM products;
>
> But this is not very usable.

But why not create a "products_restricted" view that uses the
CURRENT_USER function to see who's running it?

CREATE VIEW products_restricted AS
SELECT * FROM products WHERE Producer_ID = get_producer_id(CURRENT_USER);

[CURRENT_USER returns a string, so you would need to map it to your
producer_id somehow.]

-Doug

В списке pgsql-general по дате отправления:

Предыдущее
От: Michal Taborsky
Дата:
Сообщение: Row-level security--is it possible?
Следующее
От: Don Isgitt
Дата:
Сообщение: Re: [real] Re: Slow dump with pg_dump/pg_restore ? How