forked from stolostron/policy-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy-continuous-restore-backup-triliovault-for-kubernetes.yaml
220 lines (219 loc) · 7.82 KB
/
policy-continuous-restore-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
# This is the 2nd policy to setup Continuous Restore Functionality using
# Triliovault for Kubernetes (TVK).
#
# This policy creates backup on the source cluster participating in the Continuous
# Restore Functionality defined with labels "protected-by=triliovault" and
# "tvk-continuous-restore-cluster=source"
#
# Please note TVK should be installed and configured on the cluster and the event
# target created using policy
# ./CM-Configuration-Management/policy-continuous-restore-event-target-triliovault-for-kubernetes.yaml
# before applying this policy.
#
# Refer - https://docs.trilio.io/kubernetes/management-console/index/continuous-restore#create-a-backupplan
#
# To create the namespace backup, following process is followed
# 1. 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
# 2. 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 configmap tvk-cr-backup-configmap in the namespace
# where this policy is placed. The configmap has the name of the namespace
# for creating namespace based backup.
#
# 2. ConfigMap Example yaml (replace the values)
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: tvk-cr-backup-configmap
# Data:
# backupNS: "PROVIDE_NAMESPACE"
#
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: tvk-continuous-restore-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 "" "tvk-cr-backup-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-cr-policy
spec:
remediationAction: inform
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Policy
metadata:
name: tvk-cr-policy
namespace: default
spec:
continuousRestoreConfig:
consistentSets: 3
default: false
type: ContinuousRestore
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-cr-backupplan
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: BackupPlan
metadata:
name: tvk-cr-backupplan
namespace: '{{hub fromConfigMap "" "tvk-cr-backup-configmap" "backupNS" hub}}'
spec:
backupNamespace: '{{hub fromConfigMap "" "tvk-cr-backup-configmap" "backupNS" hub}}'
backupConfig:
target:
name: tvk-s3-event-target
namespace: default
schedulePolicy:
fullBackupPolicy:
name: trilio-daily-schedule-policy
namespace: default
retentionPolicy:
name: trilio-latest-retention-policy
namespace: default
backupPlanFlags:
skipImageBackup: true
continuousRestoreConfig:
continuousRestoreInstances:
- continuousRestorePolicy:
apiVersion: triliovault.trilio.io/v1
kind: Policy
name: tvk-cr-policy
namespace: default
instanceID: '{{with lookup "triliovault.trilio.io/v1" "Target" "default" "tvk-s3-event-target"}}{{- range $k, $v := .status.availableContinuousRestoreInstances }}{{ $k }}{{- end }}{{- end }}'
retainHelmApps: true
status:
status: Available
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: tvk-cr-backup
spec:
remediationAction: enforce
severity: high
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: triliovault.trilio.io/v1
kind: Backup
metadata:
name: tvk-cr-full-backup
namespace: '{{hub fromConfigMap "" "tvk-cr-backup-configmap" "backupNS" hub}}'
spec:
type: Full
backupPlan:
name: tvk-cr-backupplan
namespace: '{{hub fromConfigMap "" "tvk-cr-backup-configmap" "backupNS" hub}}'
status:
status: Available
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementRule
metadata:
name: tvk-cr-backup-placement
spec:
clusterSelector:
matchExpressions:
- key: protected-by
operator: In
values:
- triliovault
- key: tvk-continuous-restore-cluster
operator: In
values:
- source
---
apiVersion: policy.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: tvk-cr-backup-placement
placementRef:
name: tvk-cr-backup-placement
apiGroup: apps.open-cluster-management.io
kind: PlacementRule
subjects:
- name: tvk-continuous-restore-backup
apiGroup: policy.open-cluster-management.io
kind: Policy