Gallery › Kubernetes › Azure built-in policies
Configure Kubernetes clusters with specified Flux v2 Bucket source using local secrets
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.0
Deploy a 'fluxConfiguration' to Kubernetes clusters to assure that the clusters get their source of truth for workloads and configurations from the defined Bucket. This definition requires local authentication secrets stored in the Kubernetes cluster. For instructions, visit https://aka.ms/GitOpsFlux2Policy.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONGitOps-Flux2-to-Kubernetes-cluster-Bucket-K8sSecret_DINE.json · 385 lines
{
"properties": {
"displayName": "Configure Kubernetes clusters with specified Flux v2 Bucket source using local 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 Bucket. This definition requires local authentication secrets stored in the Kubernetes cluster. For instructions, visit https://aka.ms/GitOpsFlux2Policy.",
"metadata": {
"version": "1.1.0",
"category": "Kubernetes"
},
"version": "1.1.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"
},
"bucketUrl": {
"type": "string",
"metadata": {
"displayName": "Bucket Url",
"description": "The URL for the Bucket. Formats supported: http://, https://, s3://."
}
},
"bucketName": {
"type": "string",
"metadata": {
"displayName": "Bucket Name",
"description": "The name of the Bucket."
}
},
"bucketTimeout": {
"type": "integer",
"metadata": {
"displayName": "Bucket Timeout (seconds)",
"description": "The maximum allowed time, in seconds, for syncing the Bucket source to the cluster, after which the sync fails and tries again in the next sync interval."
},
"defaultValue": 600
},
"bucketSyncInterval": {
"type": "integer",
"metadata": {
"displayName": "Bucket Sync Interval (seconds)",
"description": "The time period, in seconds, between attempted syncs of the Bucket source to the cluster."
},
"defaultValue": 600
},
"bucketLocalAuthRef": {
"type": "string",
"metadata": {
"displayName": "Bucket Local Auth Secret",
"description": "The name of a local secret on the Kubernetes cluster in the namespace of this Flux configuration that holds the values for authentication with the source."
}
},
"bucketInsecure": {
"type": "boolean",
"metadata": {
"displayName": "Bucket Insecure",
"description": "Communicate with a Bucket without TLS. Enter true or false."
},
"defaultValue": false
},
"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
},
"kustomizationRetryInterval": {
"type": "integer",
"metadata": {
"displayName": "Kustomization Retry Interval (seconds)",
"description": "The retry interval, in seconds, specifies how often the Kustomization will retry a previously failed reconciliation. If left blank, the value of the sync interval will be used."
},
"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/bucket.url",
"equals": "[parameters('bucketUrl')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/bucket.timeoutInSeconds",
"equals": "[parameters('bucketTimeout')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/bucket.syncIntervalInSeconds",
"equals": "[parameters('bucketSyncInterval')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/bucket.insecure",
"equals": "[parameters('bucketInsecure')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/bucket.bucketName",
"equals": "[parameters('bucketName')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/bucket.localAuthRef",
"equals": "[parameters('bucketLocalAuthRef')]"
},
{
"field": "Microsoft.KubernetesConfiguration/fluxConfigurations/provisioningState",
"notEquals": "Failed"
}
]
},
"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"
},
"configurationName": {
"type": "string"
},
"configurationNamespace": {
"type": "string"
},
"configurationScope": {
"type": "string"
},
"sourceKind": {
"type": "string"
},
"bucketUrl": {
"type": "string"
},
"bucketName": {
"type": "string"
},
"bucketTimeout": {
"type": "int"
},
"bucketSyncInterval": {
"type": "int"
},
"bucketLocalAuthRef": {
"type": "string"
},
"bucketInsecure": {
"type": "bool"
},
"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 Bucket source in the connected (ARC) or managed (AKS) cluster using a Kubernetes secret.",
"type": "Microsoft.KubernetesConfiguration/fluxConfigurations",
"name": "[parameters('configurationName')]",
"apiVersion": "2022-03-01",
"properties": {
"scope": "[parameters('configurationScope')]",
"namespace": "[parameters('configurationNamespace')]",
"sourceKind": "[parameters('sourceKind')]",
"bucket": {
"url": "[parameters('bucketUrl')]",
"bucketName": "[parameters('bucketName')]",
"timeoutInSeconds": "[parameters('bucketTimeout')]",
"syncIntervalInSeconds": "[parameters('bucketSyncInterval')]",
"insecure": "[parameters('bucketInsecure')]",
"localAuthRef": "[if(not(empty(parameters('bucketLocalAuthRef'))), parameters('bucketLocalAuthRef'), json('null'))]"
},
"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": {
"clusterName": {
"value": "[field('name')]"
},
"clusterResourceType": {
"value": "[field('type')]"
},
"configurationName": {
"value": "[parameters('configurationName')]"
},
"configurationNamespace": {
"value": "[parameters('configurationNamespace')]"
},
"configurationScope": {
"value": "[parameters('configurationScope')]"
},
"sourceKind": {
"value": "Bucket"
},
"bucketUrl": {
"value": "[parameters('bucketUrl')]"
},
"bucketName": {
"value": "[parameters('bucketName')]"
},
"bucketTimeout": {
"value": "[parameters('bucketTimeout')]"
},
"bucketSyncInterval": {
"value": "[parameters('bucketSyncInterval')]"
},
"bucketLocalAuthRef": {
"value": "[parameters('bucketLocalAuthRef')]"
},
"bucketInsecure": {
"value": "[parameters('bucketInsecure')]"
},
"kustomizationName": {
"value": "[parameters('kustomizationName')]"
},
"kustomizationPath": {
"value": "[parameters('kustomizationPath')]"
},
"kustomizationTimeout": {
"value": "[parameters('kustomizationTimeout')]"
},
"kustomizationSyncInterval": {
"value": "[parameters('kustomizationSyncInterval')]"
},
"kustomizationRetryInterval": {
"value": "[parameters('kustomizationRetryInterval')]"
},
"kustomizationPrune": {
"value": "[parameters('kustomizationPrune')]"
},
"kustomizationForce": {
"value": "[parameters('kustomizationForce')]"
},
"suspend": {
"value": false
}
}
}
}
}
}
},
"versions": [
"1.1.0",
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/b8c1d6c1-6137-97c6-9c34-d4627e54ca26",
"name": "b8c1d6c1-6137-97c6-9c34-d4627e54ca26"
}Bylawb8c1d6c1-6137-97c6-9c34-d4627e54ca26.bylaw.ps1 · 155 lines
# Converted from GitOps-Flux2-to-Kubernetes-cluster-Bucket-K8sSecret_DINE.json by ConvertTo-Bylaw.
Policy 'b8c1d6c1-6137-97c6-9c34-d4627e54ca26' {
Properties @{
DisplayName = 'Configure Kubernetes clusters with specified Flux v2 Bucket source using local secrets'
Description = 'Deploy a ''fluxConfiguration'' to Kubernetes clusters to assure that the clusters get their source of truth for workloads and configurations from the defined Bucket. This definition requires local authentication secrets stored in the Kubernetes cluster. For instructions, visit https://aka.ms/GitOpsFlux2Policy.'
Version = '1.1.0'
Category = 'Kubernetes'
PolicyVersion = '1.1.0'
Mode = 'Indexed'
}
Parameter ConfigurationName @{
Type = 'string'
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.'
}
Parameter ConfigurationNamespace @{
Type = 'string'
Default = 'default'
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.'
}
Parameter ConfigurationScope @{
Type = 'string'
AllowedValues = @('cluster', 'namespace')
Default = 'cluster'
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).'
}
Parameter BucketUrl @{
Type = 'string'
DisplayName = 'Bucket Url'
Description = 'The URL for the Bucket. Formats supported: http://, https://, s3://.'
}
Parameter BucketName @{
Type = 'string'
DisplayName = 'Bucket Name'
Description = 'The name of the Bucket.'
}
Parameter BucketTimeout @{
Type = 'integer'
Default = 600
DisplayName = 'Bucket Timeout (seconds)'
Description = 'The maximum allowed time, in seconds, for syncing the Bucket source to the cluster, after which the sync fails and tries again in the next sync interval.'
}
Parameter BucketSyncInterval @{
Type = 'integer'
Default = 600
DisplayName = 'Bucket Sync Interval (seconds)'
Description = 'The time period, in seconds, between attempted syncs of the Bucket source to the cluster.'
}
Parameter BucketLocalAuthRef @{
Type = 'string'
DisplayName = 'Bucket Local Auth Secret'
Description = 'The name of a local secret on the Kubernetes cluster in the namespace of this Flux configuration that holds the values for authentication with the source.'
}
Parameter BucketInsecure @{
Type = 'boolean'
Default = $false
DisplayName = 'Bucket Insecure'
Description = 'Communicate with a Bucket without TLS. Enter true or false.'
}
Parameter KustomizationName @{
Type = 'string'
Default = 'kustomization-1'
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.'
}
Parameter KustomizationPath @{
Type = 'string'
Default = './'
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.'
}
Parameter KustomizationTimeout @{
Type = 'integer'
Default = 600
DisplayName = 'Kustomization Timeout (seconds)'
Description = 'The sync timeout, in seconds, defines how long a Kustomization reconciliation will be allowed to continue before timing out.'
}
Parameter KustomizationSyncInterval @{
Type = 'integer'
Default = 600
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.'
}
Parameter KustomizationRetryInterval @{
Type = 'integer'
Default = 600
DisplayName = 'Kustomization Retry Interval (seconds)'
Description = 'The retry interval, in seconds, specifies how often the Kustomization will retry a previously failed reconciliation. If left blank, the value of the sync interval will be used.'
}
Parameter KustomizationPrune @{
Type = 'boolean'
Default = $false
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.'
}
Parameter KustomizationForce @{
Type = 'boolean'
Default = $false
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.'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource * {
Require 'type is not one of 2 values' {
Field type | Must -Not -BeIn @('Microsoft.Kubernetes/connectedClusters', 'Microsoft.ContainerService/managedClusters') -IfPresent
}
}
DeployIfNotExists 'Microsoft.KubernetesConfiguration/fluxConfigurations' -Role 'Contributor' -Effect (Param Effect) {
Require 'scope, namespace, bucket.url and 6 more are as required' {
Field scope | Must -Be (Param ConfigurationScope)
Field namespace | Must -Be (Param ConfigurationNamespace)
Field bucket.url | Must -Be (Param BucketUrl)
Field bucket.timeoutInSeconds | Must -Be (Param BucketTimeout)
Field bucket.syncIntervalInSeconds | Must -Be (Param BucketSyncInterval)
Field bucket.insecure | Must -Be (Param BucketInsecure)
Field bucket.bucketName | Must -Be (Param BucketName)
Field bucket.localAuthRef | Must -Be (Param BucketLocalAuthRef)
Field provisioningState | Must -Not -Be 'Failed' -IfPresent
}
Deployment -TemplateFile './templates/b8c1d6c1-6137-97c6-9c34-d4627e54ca26.json' -Parameters ([ordered]@{
clusterName = (Arm '[field(''name'')]')
clusterResourceType = (Arm '[field(''type'')]')
configurationName = (Param ConfigurationName)
configurationNamespace = (Param ConfigurationNamespace)
configurationScope = (Param ConfigurationScope)
sourceKind = 'Bucket'
bucketUrl = (Param BucketUrl)
bucketName = (Param BucketName)
bucketTimeout = (Param BucketTimeout)
bucketSyncInterval = (Param BucketSyncInterval)
bucketLocalAuthRef = (Param BucketLocalAuthRef)
bucketInsecure = (Param BucketInsecure)
kustomizationName = (Param KustomizationName)
kustomizationPath = (Param KustomizationPath)
kustomizationTimeout = (Param KustomizationTimeout)
kustomizationSyncInterval = (Param KustomizationSyncInterval)
kustomizationRetryInterval = (Param KustomizationRetryInterval)
kustomizationPrune = (Param KustomizationPrune)
kustomizationForce = (Param KustomizationForce)
suspend = $false
})
}
}Its deployment templates are written beside it:
templates/b8c1d6c1-6137-97c6-9c34-d4627e54ca26.json
Source: built-in-policies/policyDefinitions/Kubernetes/GitOps-Flux2-to-Kubernetes-cluster-Bucket-K8sSecret_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw