2. DBMS이야기/01. PostgreSQL

PostgreSQL Privileges Test 4

OSSW(Open Source System SoftWare 2014. 8. 29. 09:22

TEST 4 : DATABASE


세번째 테스트는 데이터베이스에 관한 테스트입니다.  모든 User는 권한 없이 DATABASE 이용이 가능한가에 관해 테스트를 진행해보겠습니다.

 

- Database 생성

edb=# create database fdb tablespace test_tbs1;

CREATE DATABASE

 

데이터베이스가 정상적으로 생성되었는지 확인하기 위해서는 아래와 같은 명령어를 날려주시면 됩니다.


edb=# \l+

                                                                     List of databases

   Name    |    Owner     | Encoding  | Collate | Ctype |       Access privileges       |  Size   | Tablespace |                Description                

-----------+--------------+-----------+---------+-------+-------------------------------+---------+------------+--------------------------------------------

edb       | enterprisedb | SQL_ASCII | C       | C     |                               | 8794 kB | pg_default |

 fdb       | enterprisedb | SQL_ASCII | C       | C     |                               | 8601 kB | test_tbs1  |

 postgres  | enterprisedb | SQL_ASCII | C       | C     |                               | 8601 kB | pg_default | default administrative connection database

template0 | enterprisedb | SQL_ASCII | C       | C     | =c/enterprisedb              +| 8601 kB | pg_default | unmodifiable empty database

           |              |           |         |       | enterprisedb=CTc/enterprisedb |         |            |

 template1 | enterprisedb | SQL_ASCII | C       | C     | =c/enterprisedb              +| 8601 kB | pg_default | default template for new databases

           |              |           |         |       | enterprisedb=CTc/enterprisedb |         |            |

(5 rows)

 

kim 유저에게 권한을 부여한 후 해당 db에 권한이 없는 ji 유저가 테이블을 생성할 수 있는 지 알아보겠습니다.


-- kim 유저에게 권한 생성

fdb=# grant create, connect on database fdb to kim;

GRANT

 

fdb=> create table test_11 (age number(1));

CREATE TABLE

fdb=> \dp+ test_11

                            Access privileges

Schema |  Name   | Type  | Access privileges | Column access privileges

--------+---------+-------+-------------------+--------------------------

public | test_11 | table |                   |

(1 row)

 

- Database 리스트 확인

fdb=> \l+

                                                                     List of databases

   Name    |    Owner     | Encoding  | Collate | Ctype |       Access privileges       |  Size   | Tablespace |                Description                

-----------+--------------+-----------+---------+-------+-------------------------------+---------+------------+--------------------------------------------

edb       | enterprisedb | SQL_ASCII | C       | C     |                               | 8794 kB | pg_default |

 fdb       | enterprisedb | SQL_ASCII | C       | C     | =Tc/enterprisedb             +| 8738 kB | test_tbs1  |

           |              |           |         |       | enterprisedb=CTc/enterprisedb+|         |            |

           |              |           |         |       | kim=Cc/enterprisedb           |         |            |

 postgres  | enterprisedb | SQL_ASCII | C       | C     |                               | 8601 kB | pg_default | default administrative connection database

template0 | enterprisedb | SQL_ASCII | C       | C     | =c/enterprisedb              +| 8601 kB | pg_default | unmodifiable empty database

           |              |           |         |       | enterprisedb=CTc/enterprisedb |         |            |

 template1 | enterprisedb | SQL_ASCII | C       | C     | =c/enterprisedb              +| 8601 kB | pg_default | default template for new databases

           |              |           |         |       | enterprisedb=CTc/enterprisedb |         |            |

(5 rows)


권한이 없는 또다른 유저인 sun 유저가 테이블을 생성할 수 있는지 알아보겠습니다.


fdb=# \c fdb sun

Password for user sun:

You are now connected to database "fdb" as user "sun".


fdb=> create table test_15 (age number(1)) tablespace test_tbs1;

CREATE TABLE

 

- sun 유저의 connect 권한 해제

fdb=> \c fdb enterprisedb

You are now connected to database "fdb" as user "enterprisedb".


fdb=# revoke connect on database fdb from sun;

REVOKE

 

fdb=# \c fdb sun

Password for user sun:

You are now connected to database "fdb" as user "sun".

 

fdb=> create table test_18 (age number(1));

CREATE TABLE

 

connect 권한을 해제했는데도 접속도 되는 것을 확인해볼 수 있습니다.

 

- public에 권한 해제

fdb=> \c fdb enterprisedb

You are now connected to database "fdb" as user "enterprisedb".

fdb=# revoke connect on database fdb from public;

REVOKE

 

fdb=# \c fdb sun

Password for user sun:

FATAL:  permission denied for database "fdb"

DETAIL:  User does not have CONNECT privilege.

Previous connection kept

 

유저 public 에 대한 권한을 해제하자 접속 권한없이 접속이 되지 않습니다.

 

- Database 리스트 확인

fdb=# \l+

                                                                     List of databases

   Name    |    Owner     | Encoding  | Collate | Ctype |       Access privileges       |  Size   | Tablespace |                Description                

-----------+--------------+-----------+---------+-------+-------------------------------+---------+------------+--------------------------------------------

4444      | enterprisedb | SQL_ASCII | C       | C     |                               | 8730 kB | pg_default |

 edb       | enterprisedb | SQL_ASCII | C       | C     |                               | 8794 kB | pg_default |

 fdb       | enterprisedb | SQL_ASCII | C       | C     | =T/enterprisedb              +| 8754 kB | test_tbs1  |

           |              |           |         |       | enterprisedb=CTc/enterprisedb+|         |            |

           |              |           |         |       | kim=Cc/enterprisedb           |         |            |

 postgres  | enterprisedb | SQL_ASCII | C       | C     |                               | 8601 kB | pg_default | default administrative connection database

template0 | enterprisedb | SQL_ASCII | C       | C     | =c/enterprisedb              +| 8601 kB | pg_default | unmodifiable empty database

           |              |           |         |       | enterprisedb=CTc/enterprisedb |         |            |

 template1 | enterprisedb | SQL_ASCII | C       | C     | =c/enterprisedb              +| 8601 kB | pg_default | default template for new databases

           |              |           |         |       | enterprisedb=CTc/enterprisedb |         |            |

(6 rows)


이렇게 4번째 테스트가 마무리 되었고, 마지막 5번째 테스트 시나리오는 Default Privilege 에 대해 진행해보도록 하겠습니다. 


Post by. 김지선 (2014.08.29)