forked from open-cluster-management-io/policy-collection
-
Notifications
You must be signed in to change notification settings - Fork 31
/
policy-create-operator-backup-triliovault-for-kubernetes.yaml
230 lines (230 loc) · 9.01 KB
/
policy-create-operator-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
# This policy creates an operator based backup using Triliovault for Kubernetes (TVK)
# on all clusters with a label "protected-by=triliovault".
#
# To create operator based application 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:
# Application to be backed up selected by specified Operator ID
# 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,
# backup namespace, the Operator ID, Operator resources label-value and Operator
# Application label-value.
#
# 2.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.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_APP_NAMESPACE"
# operatorID: "PROVIDE_OPERATOR_ID"
# operatorResourceLabel: "PROVIDE_OPERATOR_RESOURCE_LABEL"
# operatorResourceValue: "PROVIDE_OPERATOR_RESOURCE_VALUE"
# operatorAppLabel: "PROVIDE_OPERATOR_APPLICATION_LABEL"
# operatorAppValue: "PROVIDE_OPERATOR_APPLICATION_VALUE"
#
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: create-tvk-operator-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-backup-operator-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-operator-backupplan
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: BackupPlan
metadata:
name: tvk-operator-backupplan
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
spec:
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
backupPlanComponents:
operators:
- operatorId: '{{hub fromConfigMap "" "aws-s3-configmap" "operatorID" hub}}'
operatorResources:
labelSelector:
- matchLabels:
'{{hub fromConfigMap "" "aws-s3-configmap" "operatorResourceLabel" hub}}': '{{hub fromConfigMap "" "aws-s3-configmap" "operatorResourceValue" hub}}'
applicationResources:
labelSelector:
- matchLabels:
'{{hub fromConfigMap "" "aws-s3-configmap" "operatorAppLabel" hub}}': '{{hub fromConfigMap "" "aws-s3-configmap" "operatorAppValue" hub}}'
backupPlanFlags:
skipImageBackup: true
status:
status: Available
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-operator-backup
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Backup
metadata:
name: tvk-operator-full-backup
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
spec:
type: Full
backupPlan:
name: tvk-operator-backupplan
namespace: '{{hub fromConfigMap "" "aws-s3-configmap" "backupNS" hub}}'
status:
status: Available