forked from open-cluster-management-io/policy-collection
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpolicy-oauth-ldapsync.yaml
275 lines (269 loc) · 11.1 KB
/
policy-oauth-ldapsync.yaml
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# This policy configures the OAuth for using an LDAP provider, and creates a job to sync with an external LDAP.
# In this example, Active Directory is used as external IDP.
# For more information on configuring the OAuth server, consult the OpenShift documentation:
# https://docs.openshift.com/container-platform/4.10/authentication/identity_providers/configuring-ldap-identity-provider.html
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: policy-oauth-ldap
annotations:
policy.open-cluster-management.io/categories: CM Configuration Management, AC Access Control
policy.open-cluster-management.io/controls: AC-3 Access Enforcement
policy.open-cluster-management.io/standards: NIST SP 800-53
spec:
disabled: false
policy-templates:
# Create a secret that stores the LDAP bind password
# bindPassword: <password> --> Password used by the bindDN to connect with the LDAP. Since this object is a Kubernetes secret, encode the password in base64.
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldap-secret
spec:
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: v1
data:
bindPassword: <password>
kind: Secret
metadata:
name: ldap-secret
namespace: openshift-config
type: Opaque
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
# Configure the OAuth for using LDAP as the identity provider
# bindDN: <bindDN> --> Full DN of the user account used to connect with the LDAP. Example: CN=user1,CN=Users,DC=example,DC=com
# url: <ldapurl> --> The LDAP url. The configured url is an RFC 2255 URL, which specifies the LDAP host and search parameters to use. The format is ldap://host:port/basedn?attribute?scope?filter
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth
spec:
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: ldapidp
ldap:
attributes:
name:
- cn
email:
- mail
id:
- sAMAccountName
preferredUsername:
- sAMAccountName
bindDN: <bindDN>
bindPassword:
name: ldap-secret
insecure: true
url: <ldapurl>
mappingMethod: claim
type: LDAP
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
# Create a CronJob in the cluster-ops namespace to sync with LDAP. In this example, AD is used.
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldapsync-project
spec:
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: project.openshift.io/v1
kind: Project
metadata:
name: cluster-ops
spec:
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
# Create a ConfigMap that stores the LDAP sync configuration.
# url: <ldapurl> --> The LDAP url. The configured url is an RFC 2255 URL, which specifies the LDAP host and search parameters to use. The format is ldap://host:port/basedn?attribute?scope?filter
# bindDN: <bindDN> --> Full DN of the user account used to connect with the LDAP. Example: CN=user1,CN=Users,DC=example,DC=com
# bindPassword: <password> --> Password used by the bindDN to connect with the LDAP. Since this object is a Kubernetes configmap, the password is stored in plaintext.
# baseDN: <baseDN> --> The starting point an LDAP server uses when searching for users within your directory.
# filter: <filter> --> A valid LDAP search filter. If not provided, defaults to (objectClass=*)
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldapsync-configmap
spec:
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: v1
data:
ldap-sync.yml: >
kind: LDAPSyncConfig
apiVersion: v1
url: ldap://<ldapurl>
insecure: true
bindDN: "<ldapbindDN>"
bindPassword: '<ldapbindPassword>'
augmentedActiveDirectory:
groupsQuery:
derefAliases: never
pageSize: 0
groupUIDAttribute: dn
groupNameAttributes: [ cn ]
groupMembershipAttributes: [ memberOf ]
usersQuery:
baseDN: "<baseDN>"
scope: sub
derefAliases: never
pageSize: 0
filter: <filter>
userNameAttributes: [ sAMAccountName ]
kind: ConfigMap
metadata:
name: ldap-config
namespace: cluster-ops
labels:
template: cronjob-ldap-group-sync
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldapsync-cronjob
spec:
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cronjob-ldap-group-sync
namespace: cluster-ops
labels:
template: cronjob-ldap-group-sync
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
activeDeadlineSeconds: 500
containers:
- name: cronjob-ldap-group-sync
command:
- /bin/bash
- -c
- "oc adm groups sync
--sync-config=/etc/config/ldap-group-sync.yaml
--confirm || :"
image: registry.redhat.io/openshift4/ose-cli:latest
volumeMounts:
- name: ldap-sync-volume
mountPath: /etc/config
dnsPolicy: ClusterFirst
restartPolicy: Never
serviceAccount: ldap-group-syncer
serviceAccountName: ldap-group-syncer
terminationGracePeriodSeconds: 30
volumes:
- name: ldap-sync-volume
configMap:
name: ldap-config
items:
- key: ldap-sync.yml
path: ldap-group-sync.yaml
schedule: "@hourly"
successfulJobsHistoryLimit: 5
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldapsync-cronjob-sa-cr
spec:
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: authorization.openshift.io/v1
kind: ClusterRole
metadata:
name: ldap-group-syncer
labels:
template: cronjob-ldap-group-sync
rules:
- apiGroups:
- ""
- user.openshift.io
resources:
- groups
verbs:
- get
- list
- create
- update
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldapsync-cronjob-sa-crb
spec:
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: ldap-group-syncers
labels:
template: cronjob-ldap-group-sync
roleRef:
name: ldap-group-syncer
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
subjects:
- name: ldap-group-syncer
namespace: cluster-ops
kind: ServiceAccount
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: policy-oauth-ldapsync-cronjob-sa
spec:
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: v1
kind: ServiceAccount
metadata:
name: ldap-group-syncer
namespace: cluster-ops
labels:
template: cronjob-ldap-group-sync
pruneObjectBehavior: DeleteIfCreated
remediationAction: inform
severity: high
remediationAction: inform