-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Deploy-GitOps-Flux2-to-Kubernetes-cluster-HTTPS-secrets_DINE.json
461 lines (461 loc) · 19.2 KB
/
Deploy-GitOps-Flux2-to-Kubernetes-cluster-HTTPS-secrets_DINE.json
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
{
"properties": {
"displayName": "Configure Kubernetes clusters with Flux v2 configuration using Git repository and HTTPS secrets",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Deploy a 'fluxConfiguration' to Kubernetes clusters to assure that the clusters get their source of truth for workloads and configurations from the defined Git repository. This definition requires a HTTPS key secret stored in Key Vault. For instructions, visit https://aka.ms/GitOpsFlux2Policy.",
"metadata": {
"version": "1.0.0",
"category": "Kubernetes"
},
"version": "1.0.0",
"parameters": {
"configurationName": {
"type": "string",
"metadata": {
"displayName": "Configuration Instance Name",
"description": "The name for the fluxConfigurations resource in Azure. Maximum of 30 lowercase alphanumeric characters or hyphens. Must start and end with an alphanumeric character. Learn more about setting up GitOps configuration: https://aka.ms/doc-use-flux2."
}
},
"configurationNamespace": {
"type": "string",
"metadata": {
"displayName": "Configuration Namespace",
"description": "The namespace in the cluster within which the Flux custom resources will be installed for this configuration. This can be an existing namespace or a new one that will be created when the configuration is deployed. Maximum of 63 lowercase alphanumeric characters or hyphens. Must start and end with an alphanumeric character."
},
"defaultValue": "default"
},
"configurationScope": {
"type": "string",
"metadata": {
"displayName": "Configuration Scope",
"description": "The permission scope for the Flux configuration. Possible values are 'cluster' (create resources throughout cluster) or 'namespace' (create resources only in namespace)."
},
"allowedValues": [
"cluster",
"namespace"
],
"defaultValue": "cluster"
},
"repositoryUrl": {
"type": "string",
"metadata": {
"displayName": "Repository Url",
"description": "The URL for the Git repository. Formats supported: http://, https://, ssh://."
}
},
"repositorySyncInterval": {
"type": "integer",
"metadata": {
"displayName": "Repository Sync Interval (seconds)",
"description": "The time period, in seconds, between attempted syncs of the Git repository to the cluster."
},
"defaultValue": 600
},
"repositoryRefBranch": {
"type": "string",
"metadata": {
"displayName": "Repository Reference Branch",
"description": "The branch within the GitRepository source to sync to the cluster."
},
"defaultValue": ""
},
"repositoryRefTag": {
"type": "string",
"metadata": {
"displayName": "Repository Tag",
"description": "The tag within the GitRepository source to sync to the cluster. Takes precedence over branch."
},
"defaultValue": ""
},
"repositoryRefSemver": {
"type": "string",
"metadata": {
"displayName": "Repository Semver Range",
"description": "The tag semver range within the GitRepository source to reconcile with the cluster. Takes precedence over tag and branch."
},
"defaultValue": ""
},
"repositoryRefCommit": {
"type": "string",
"metadata": {
"displayName": "Repository Commit SHA",
"description": "The commit SHA within the GitRepository source to sync to the cluster. Takes precedence over semver and tag. May be used with branch."
},
"defaultValue": ""
},
"repositoryHttpsUser": {
"type": "string",
"metadata": {
"displayName": "Plaintext HTTPS user name",
"description": "Plaintext HTTPS username used to access private git repositories over HTTPS"
}
},
"httpsKeyKeyVaultSecretName": {
"type": "String",
"metadata": {
"displayName": "HTTPS-key Key Vault secret name",
"description": "The name of the Key Vault secret that holds the base64-encoded HTTPS key."
}
},
"keyVaultName": {
"type": "String",
"metadata": {
"displayName": "Key Vault name",
"description": "The name of the Key Vault that holds the HTTPS-key Key Vault secret.",
"strongType": "Microsoft.KeyVault/vaults",
"assignPermissions": true
}
},
"repositoryHttpsCACert": {
"type": "string",
"metadata": {
"displayName": "HTTPS CA Cert",
"description": "The base64-encoded HTTPS certificate authority contents used to access private git repositories over HTTPS."
},
"defaultValue": ""
},
"kustomizationName": {
"type": "string",
"metadata": {
"displayName": "Kustomization Name",
"description": "The name of the Kustomization. Maximum of 30 lowercase alphanumeric characters or hyphen. Must start and end with an alphanumeric character."
},
"defaultValue": "kustomization-1"
},
"kustomizationPath": {
"type": "string",
"metadata": {
"displayName": "Kustomization Path",
"description": "The path within the source where the Kustomization will begin looking for manifests to reconcile. If left blank, the root path of the repository will be used."
},
"defaultValue": "./"
},
"kustomizationTimeout": {
"type": "integer",
"metadata": {
"displayName": "Kustomization Timeout (seconds)",
"description": "The sync timeout, in seconds, defines how long a Kustomization reconciliation will be allowed to continue before timing out."
},
"defaultValue": 600
},
"kustomizationSyncInterval": {
"type": "integer",
"metadata": {
"displayName": "Kustomization Sync Interval (seconds)",
"description": "The sync interval, in seconds, defines how often the Kustomization reconciles the cluster with the manifests to ensure that the cluster remains in sync with the GitRepository or Bucket source. A Kustomization sync interval more frequent than the source sync interval can be used to catch and reconcile any cluster drift."
},
"defaultValue": 600
},
"kustomizationPrune": {
"type": "boolean",
"metadata": {
"displayName": "Kustomization Prune",
"description": "Enable prune to assure that objects are removed from the cluster if they are removed from the GitRepository or Bucket source or when this Kustomization or GitOps configuration is removed from the cluster."
},
"defaultValue": false
},
"kustomizationForce": {
"type": "boolean",
"metadata": {
"displayName": "Kustomization Force",
"description": "Enable force to instruct the controller to recreate resources if they can't be changed due to an immutable field change."
},
"defaultValue": false
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"in": [
"Microsoft.Kubernetes/connectedClusters",
"Microsoft.ContainerService/managedClusters"
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.KubernetesConfiguration/fluxConfigurations",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/scope",
"equals": "[parameters('configurationScope')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/namespace",
"equals": "[parameters('configurationNamespace')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.url",
"equals": "[parameters('repositoryUrl')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.syncIntervalInSeconds",
"equals": "[parameters('repositorySyncInterval')]"
},
{
"anyOf": [
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.repositoryRef.branch",
"equals": "[parameters('repositoryRefBranch')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.repositoryRef.tag",
"equals": "[parameters('repositoryRefTag')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.repositoryRef.semver",
"equals": "[parameters('repositoryRefSemver')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.repositoryRef.commit",
"equals": "[parameters('repositoryRefCommit')]"
}
]
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.httpsUser",
"equals": "[parameters('repositoryHttpsUser')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/gitRepository.httpsCAFile",
"equals": "[parameters('repositoryhttpsCACert')]"
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterResourceType": {
"type": "string"
},
"clusterName": {
"type": "string"
},
"clusterLocation": {
"type": "string"
},
"configurationName": {
"type": "string"
},
"configurationNamespace": {
"type": "string"
},
"configurationScope": {
"type": "string"
},
"sourceKind": {
"type": "string"
},
"repositoryUrl": {
"type": "string"
},
"repositoryTimeout": {
"type": "int"
},
"repositorySyncInterval": {
"type": "int"
},
"repositoryRefBranch": {
"type": "string"
},
"repositoryRefTag": {
"type": "string"
},
"repositoryRefSemver": {
"type": "string"
},
"repositoryRefCommit": {
"type": "string"
},
"repositoryHttpsUser": {
"type": "string"
},
"repositoryHttpsKey": {
"type": "securestring"
},
"repositoryhttpsCACert": {
"type": "string"
},
"kustomizationName": {
"type": "string"
},
"kustomizationPath": {
"type": "string"
},
"kustomizationTimeout": {
"type": "int"
},
"kustomizationSyncInterval": {
"type": "int"
},
"kustomizationRetryInterval": {
"type": "int"
},
"kustomizationPrune": {
"type": "bool"
},
"kustomizationForce": {
"type": "bool"
},
"suspend": {
"type": "bool"
}
},
"resources": [
{
"comments": "Create a Flux configuration with GitRepository source in the connected (ARC) or managed (AKS) cluster using HTTPS authentication.",
"type": "Microsoft.KubernetesConfiguration/fluxConfigurations",
"name": "[parameters('configurationName')]",
"location": "[parameters('clusterLocation')]",
"apiVersion": "2022-03-01",
"properties": {
"scope": "[parameters('configurationScope')]",
"namespace": "[parameters('configurationNamespace')]",
"sourceKind": "[parameters('sourceKind')]",
"gitRepository": {
"url": "[parameters('repositoryUrl')]",
"timeoutInSeconds": "[parameters('repositoryTimeout')]",
"syncIntervalInSeconds": "[parameters('repositorySyncInterval')]",
"repositoryRef": {
"branch": "[if(not(empty(parameters('repositoryRefBranch'))), parameters('repositoryRefBranch'), json('null'))]",
"tag": "[if(not(empty(parameters('repositoryRefTag'))), parameters('repositoryRefTag'), json('null'))]",
"semver": "[if(not(empty(parameters('repositoryRefSemver'))), parameters('repositoryRefSemver'), json('null'))]",
"commit": "[if(not(empty(parameters('repositoryRefCommit'))), parameters('repositoryRefCommit'), json('null'))]"
},
"httpsUser": "[parameters('repositoryHttpsUser')]",
"httpsCACert": "[if(not(empty(parameters('repositoryhttpsCACert'))), parameters('repositoryhttpsCACert'), json('null'))]"
},
"configurationProtectedSettings": {
"httpsKey": "[parameters('repositoryHttpsKey')]"
},
"kustomizations": {
"[parameters('kustomizationName')]": {
"path": "[parameters('kustomizationPath')]",
"timeoutInSeconds": "[parameters('kustomizationTimeout')]",
"syncIntervalInSeconds": "[parameters('kustomizationSyncInterval')]",
"retryIntervalInSeconds": "[parameters('kustomizationRetryInterval')]",
"prune": "[parameters('kustomizationPrune')]",
"force": "[parameters('kustomizationForce')]"
}
},
"suspend": "[parameters('suspend')]"
},
"scope": "[concat(if(contains(toLower(parameters('clusterResourceType')), toLower('connectedclusters')),'Microsoft.Kubernetes/connectedClusters/','Microsoft.ContainerService/managedClusters/'),parameters('clusterName'))]"
}
]
},
"parameters": {
"clusterLocation": {
"value": "[field('location')]"
},
"clusterName": {
"value": "[field('name')]"
},
"clusterResourceType": {
"value": "[field('type')]"
},
"configurationName": {
"value": "[parameters('configurationName')]"
},
"configurationNamespace": {
"value": "[parameters('configurationNamespace')]"
},
"configurationScope": {
"value": "[parameters('configurationScope')]"
},
"sourceKind": {
"value": "GitRepository"
},
"repositoryUrl": {
"value": "[parameters('repositoryUrl')]"
},
"repositoryTimeout": {
"value": 600
},
"repositorySyncInterval": {
"value": "[parameters('repositorySyncInterval')]"
},
"repositoryRefBranch": {
"value": "[parameters('repositoryRefBranch')]"
},
"repositoryRefTag": {
"value": "[parameters('repositoryRefTag')]"
},
"repositoryRefSemver": {
"value": "[parameters('repositoryRefSemver')]"
},
"repositoryRefCommit": {
"value": "[parameters('repositoryRefCommit')]"
},
"repositoryhttpsCACert": {
"value": "[parameters('repositoryhttpsCACert')]"
},
"kustomizationName": {
"value": "[parameters('kustomizationName')]"
},
"kustomizationPath": {
"value": "[parameters('kustomizationPath')]"
},
"kustomizationTimeout": {
"value": "[parameters('kustomizationTimeout')]"
},
"kustomizationSyncInterval": {
"value": "[parameters('kustomizationSyncInterval')]"
},
"kustomizationRetryInterval": {
"value": "[parameters('kustomizationSyncInterval')]"
},
"kustomizationPrune": {
"value": "[parameters('kustomizationPrune')]"
},
"kustomizationForce": {
"value": "[parameters('kustomizationForce')]"
},
"suspend": {
"value": false
},
"repositoryHttpsUser": {
"value": "[parameters('repositoryHttpsUser')]"
},
"repositoryHttpsKey": {
"reference": {
"keyVault": {
"id": "[parameters('keyVaultName')]"
},
"secretName": "[parameters('httpsKeyKeyVaultSecretName')]"
}
}
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/bf1a31be-3b79-5ba8-c9e0-9a8c9ad9f749",
"name": "bf1a31be-3b79-5ba8-c9e0-9a8c9ad9f749"
}