Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres revoke database access from user

Tags:

postgresql

When I tried

REVOKE ALL PRIVILEGES ON DATABASE postgres from admin; 

but the user admin is still able to connect to postgres remotely via pgadmin after that.

How do I completely revoke an user's access to a database?

/root$ psql -U postgres
psql (9.2.24)
Type "help" for help.

postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
 admin     | No inheritance                                 | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}

postgres=# REVOKE ALL PRIVILEGES ON DATABASE postgres from admin; 
REVOKE
postgres=# SELECT * FROM pg_stat_activity;
 datid | datname  |  pid   | usesysid | usename  | application_name | client_addr | client_hostname | client_port |         backend_start         |          xact_start           |
          query_start          |         state_change          | waiting | state  |              query              
-------+----------+--------+----------+----------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+
-------------------------------+-------------------------------+---------+--------+---------------------------------
 12924 | postgres | 121487 |       10 | postgres | psql             |             |                 |          -1 | 2018-03-10 20:20:42.458031+08 | 2018-03-10 20:21:27.367078+08 |
 2018-03-10 20:21:27.367078+08 | 2018-03-10 20:21:27.367082+08 | f       | active | SELECT * FROM pg_stat_activity;
(1 row)

postgres=# \q
/root$ psql -U admin postgres
psql (9.2.24)
Type "help" for help.

postgres=>

enter image description here

like image 809
Avery235 Avatar asked Dec 13 '22 17:12

Avery235


1 Answers

You probably also need to do a

REVOKE CONNECT ON DATABASE postgres FROM PUBLIC; 

Each role is an implicit member of PUBLIC.

like image 106
Eelke Avatar answered Jan 08 '23 08:01

Eelke