forked from dalibo/ldap2pg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldap2pg.yml
147 lines (137 loc) · 3.87 KB
/
ldap2pg.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#
# **LDAP2PG SAMPLE CONFIGURATION**
#
# This is a sample starting point configuration file for ldap2pg.yml. Including
# static roles, groups, privilege and LDAP query.
#
# This configuration assumes the following principles:
#
# - All LDAP users are grouped in `ldap_roles` group.
# - Read privileges are granted to `readers` group.
# - Write privileges are granted to `writers` group.
# - DDL privileges are granted to `owners` group.
# - We have one or more databases with public and maybe a schema.
# - Grants are not specific to a schema. Once you're writer in a database, you
# are writer to all schemas in it.
#
# Adapt to your needs! See also full documentation on how to configure ldap2pg
# at https://ldap2pg.readthedocs.io/en/latest/config/.
#
verbosity: 5
postgres:
# Scope the database where to purge objects when dropping roles. This is the
# scope of grant on `__all__` databases.
databases_query: [postgres, appdb, olddb]
# List of managed schema. This skip pg_toast, pg_temp1, etc. but not pg_catalog.
schemas_query: |
SELECT nspname FROM pg_catalog.pg_namespace
WHERE nspname = 'pg_catalog' OR nspname NOT LIKE 'pg_%'
# Return managed roles which can be dropped or revoked.
managed_roles_query: |
SELECT DISTINCT role.rolname
FROM pg_roles AS role
LEFT OUTER JOIN pg_auth_members AS ms ON ms.member = role.oid
LEFT OUTER JOIN pg_roles AS ldap_roles
ON ldap_roles.rolname = 'ldap_roles' AND ldap_roles.oid = ms.roleid
WHERE role.rolname IN ('ldap_roles', 'readers', 'writers', 'owners')
OR ldap_roles.oid IS NOT NULL
ORDER BY 1;
# Since readers/writer/owners groups are globals, we have a global
# owners_query.
owners_query: |
SELECT DISTINCT role.rolname
FROM pg_catalog.pg_roles AS role
JOIN pg_catalog.pg_auth_members AS ms ON ms.member = role.oid
JOIN pg_catalog.pg_roles AS owners
ON owners.rolname = 'owners' AND owners.oid = ms.roleid
ORDER BY 1;
privileges:
# Define an privilege group `ro` with read-only grants
ro:
- __connect__
- __execute__
- __select_on_tables__
- __select_on_sequences__
- __usage_on_schemas__
- __usage_on_types__
# `rw` privilege group lists write-only grants
rw:
- __all_on_tables__
- __all_on_sequences__
# `ddl` privilege group lists DDL only grants.
ddl:
- __create_on_schemas__
sync_map:
# First, setup static roles and grants
- roles:
- names:
- ldap_roles
- readers
options: NOLOGIN
- name: writers
# Grant reading to writers
parent: readers
options: NOLOGIN
- name: owners
# Grant read/write to owners
parent: writers
options: NOLOGIN
# Now grant privileges to each groups
grant:
- privilege: ro
role: readers
# Let's everyone see pg_catalog
schema: __all__
- privilege: rw
role: writers
# But avoid writers to write in pg_catalog
schema: public
# Allow ddl to create tables in public only
- privilege: ddl
role: owners
schema: public
# owners must have write access to pg_catalog
- privilege: rw
role: owners
schema: pg_catalog
# Grants on specific schema appdb.appns:
- privilege: rw
role: writers
database: appdb
schema: appns
- privilege: ddl
role: owners
database: appdb
schema: appns
# Now query LDAP to create roles and grant them privileges by parenting.
- ldap:
base: ou=groups,dc=ldap,dc=ldap2pg,dc=docker
filter: "(cn=dba)"
role:
name: '{member.cn}'
options: LOGIN SUPERUSER
parent:
- ldap_roles
- owners
- ldap:
base: ou=groups,dc=ldap,dc=ldap2pg,dc=docker
filter: "(cn=app*)"
role:
name: '{member.cn}'
options: LOGIN
parent:
- ldap_roles
- writers
- ldap:
base: ou=groups,dc=ldap,dc=ldap2pg,dc=docker
filter: |
(&
(cn=bi)
(objectClass=*)
)
role:
name: '{member.cn}'
options: LOGIN
parent:
- ldap_roles
- readers