forked from stolostron/policy-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy-create-ns-backup-triliovault-for-kubernetes.yaml
245 lines (244 loc) · 8.65 KB
/
policy-create-ns-backup-triliovault-for-kubernetes.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
# This policy creates a namespace based backup using Triliovault for Kubernetes (TVK)
# on all OpenShift managed clusters with a label "protected-by=triliovault".
#
# To create the namespace backup, following process is followed
# 1. Create the target object to store backup data
# This policy creates AWS S3 based target storage for storing backup images.
# 2. Create a backup plan that references the following:
# Namespace to be backed up
# Default Scheduling Policy - create daily 1 backup
# Target to where the data should be backed up
# 3. Apply the Backup CR that references the Backup
# This policy creates a full backup.
#
# IMPORTANT: Please follow below instructions for the policy to work
# 1. On the hub cluster, create a secret aws-s3-secret in the namespace where
# this policy is placed. The secret has AWS S3 credentials for target creation.
# 2. On the hub cluster, create a configmap aws-s3-configmap in the namespace
# where this policy is placed. The configmap has AWS S3 details for target creation,
# and name of the namespace for creating namespace based backup.
#
# 1. Secret Example yaml (replace the values)
# apiVersion: v1
# kind: Secret
# metadata:
# name: aws-s3-secret
# type: Opaque
# stringData:
# accessKey: "PROVIDE_ACCESS_KEY"
# secretKey: "PROVIDE_SECRET_KEY"
#
# 2. ConfigMap Example yaml (replace the values)
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: aws-s3-configmap
# Data:
# bucketName: "PROVIDE_S3_BUCKET_NAME"
# region: "PROVIDE_REGION"
# thresholdCapacity: "100Gi"
# backupNS: "PROVIDE_NAMESPACE"
#
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: create-tvk-ns-backup
annotations:
policy.open-cluster-management.io/categories: CA Security Assessment and Authorization
policy.open-cluster-management.io/standards: NIST SP 800-53
policy.open-cluster-management.io/controls: CA-2 Security Assessments, CA-7 Continuous Monitoring
spec:
disabled: false
remediationAction: inform
policy-templates:
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-check-backup-ns
spec:
remediationAction: inform
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: Namespace
metadata:
name: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-scheduling-policy
spec:
remediationAction: inform
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Policy
metadata:
name: trilio-daily-schedule-policy
namespace: default
spec:
scheduleConfig:
schedule:
- 0 23 * * *
type: Schedule
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-retention-policy
spec:
remediationAction: inform
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Policy
metadata:
name: trilio-latest-retention-policy
namespace: default
spec:
default: false
retentionConfig:
latest: 5
type: Retention
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-s3-secret
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: Secret
metadata:
name: tvk-s3-secret
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
type: Opaque
data:
accessKey: '{{hub fromSecret "" "aws-s3-secret" "accessKey" hub}}'
secretKey: '{{hub fromSecret "" "aws-s3-secret" "secretKey" hub}}'
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-s3-target
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Target
metadata:
name: tvk-s3-target
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
spec:
type: ObjectStore
vendor: AWS
objectStoreCredentials:
bucketName: '{{hub fromConfigMap "" "aws-s3-configmap" "bucketName" hub}}'
region: '{{hub fromConfigMap "" "aws-s3-configmap" "region" hub}}'
credentialSecret:
name: tvk-s3-secret
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
thresholdCapacity: '{{hub fromConfigMap "" "aws-s3-configmap" "thresholdCapacity" hub}}'
status:
status: Available
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-ns-backupplan
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: BackupPlan
metadata:
name: tvk-ns-backupplan
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
spec:
backupNamespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
backupConfig:
target:
name: tvk-s3-target
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
schedulePolicy:
fullBackupPolicy:
name: trilio-daily-schedule-policy
namespace: default
retentionPolicy:
name: trilio-latest-retention-policy
namespace: default
backupPlanFlags:
skipImageBackup: true
retainHelmApps: false
status:
status: Available
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-ns-backup
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Backup
metadata:
name: tvk-ns-full-backup
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
spec:
type: Full
backupPlan:
name: tvk-ns-backupplan
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
status:
status: Available
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementRule
metadata:
name: tvk-backup-placement
spec:
clusterSelector:
matchExpressions:
- key: protected-by
operator: In
values:
- triliovault
- key: vendor
operator: In
values:
- OpenShift
---
apiVersion: policy.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: tvk-backup-placement
placementRef:
name: tvk-backup-placement
apiGroup: apps.open-cluster-management.io
kind: PlacementRule
subjects:
- name: create-tvk-backup
apiGroup: policy.open-cluster-management.io
kind: Policy