将创建表特权限制为RDS PostgreSQL 9.6中的新创建用户

时间:2018-12-27 10:53:49

标签: postgresql rds database-permissions postgres-9.6

在RDS PostgreSQL 9.6中创建只读用户时遇到问题。我正在执行以下SQL命令:

---- ###### CREATE ROLE ################
CREATE ROLE readonlyrole_dev;

-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readonlyrole_dev;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonlyrole_dev;

-- set the privileges that will be applied to objects created in the future.
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonlyrole_dev;



CREATE USER readonly_dev WITH PASSWORD 'welcome1';
GRANT readonlyrole_dev TO readonly_dev;

当我使用readonly_dev用户登录时,默认情况下它具有创建新表的特权,但是我不想这样做。我想仅将readonly_dev保留为只读用户。

注意:要撤消我正在执行的用户的访问权限

REVOKE CREATE ON SCHEMA public FROM PUBLIC;

也会撤消所有旧用户的创建对象特权。我只想撤销新创建用户的创建特权。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您不能这样做,也没有必要。

只需拒绝用户在所有架构上的#include <stdio.h> #include <stdbool.h> unsigned count_cycles(const unsigned permutation[], const unsigned n) { unsigned num_cycles = 0; bool visited[n]; unsigned i; // initially, no elements are visited for(i = 0; i < n; ++i) { visited[i] = false; } // iterate through all elements for(i = 0; i < n; ++i) { if(!visited[i]) { // found a new cycle; mark all elements in it as visited int x = i; do { visited[x] = true; x = permutation[x] - 1; } while(!visited[x]); // account for the new cycle num_cycles++; } } return num_cycles; } int main() { const unsigned permutation[] = { 3, 4, 1, 2, 5}; const unsigned N = 5; printf("%u\n", count_cycles(permutation, N)); // prints "3" } 权限。您应该为此使用用户组-将应有特权的所有用户都放在对模式具有所需特权的组中,并从CREATE撤消CREATE

如果您坚持必须这样做,请尝试创建一个事件触发器,该触发器在特定用户尝试创建表时会引发异常。