Bylaw

Gallery › Managed Identity › Azure built-in policies

[Preview]: [Preview]: Managed Identity Federated Credentials from Azure Kubernetes should be from trusted sources

Converted Policy Audit Deny Disabled Mode All Version 1.0.0-preview Preview

This policy limits federeation with Azure Kubernetes clusters to only clusters from approved tenants, approved regions, and a specific exception list of additional clusters.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONFIC_LimitToAzureKubernetesIssuer.json · 121 lines
{
  "properties": {
    "displayName": "[Preview]: [Preview]: Managed Identity Federated Credentials from Azure Kubernetes should be from trusted sources",
    "mode": "All",
    "policyType": "BuiltIn",
    "description": "This policy limits federeation with Azure Kubernetes clusters to only clusters from approved tenants, approved regions, and a specific exception list of additional clusters.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Managed Identity",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "allowedTenants": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed tenants",
          "description": "The list of allowed Azure AD tenant ID's of AKS OIDC issuers. Empty to allow all tenants."
        }
      },
      "allowedLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed locations",
          "description": "The list of allowed locations for AKS OIDC issuers. Empty to allow any location.",
          "strongType": "location"
        },
        "defaultValue": []
      },
      "allowedClusterExceptions": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Exception Clusters",
          "description": "The list of specific cluster ids that will be exceptions to the location and tenant rules."
        },
        "defaultValue": []
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials"
          },
          {
            "allOf": [
              {
                "value": "[if(greaterOrEquals(length(split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')),3),split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')[2],'')]",
                "like": "*.oic.prod-aks.azure.com"
              },
              {
                "not": {
                  "anyOf": [
                    {
                      "allOf": [
                        {
                          "anyOf": [
                            {
                              "count": {
                                "value": "[parameters('allowedLocations')]"
                              },
                              "equals": 0
                            },
                            {
                              "value": "[if(greaterOrEquals(length(split(if(greaterOrEquals(length(split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')),3),split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')[2],''), '.')),1),split(if(greaterOrEquals(length(split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')),3),split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')[2],''), '.')[0],'')]",
                              "in": "[parameters('allowedLocations')]"
                            }
                          ]
                        },
                        {
                          "anyOf": [
                            {
                              "count": {
                                "value": "[parameters('allowedTenants')]"
                              },
                              "equals": 0
                            },
                            {
                              "value": "[if(greaterOrEquals(length(split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')),4),split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')[3],'')]",
                              "in": "[parameters('allowedTenants')]"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "value": "[if(greaterOrEquals(length(split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')),5),split(field('Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer'),'/')[4],'')]",
                      "in": "[parameters('allowedClusterExceptions')]"
                    }
                  ]
                }
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ae62c456-33de-4dc8-b100-7ce9028a7d99",
  "name": "ae62c456-33de-4dc8-b100-7ce9028a7d99"
}
Bylawae62c456-33de-4dc8-b100-7ce9028a7d99.bylaw.ps1 · 63 lines
# Converted from FIC_LimitToAzureKubernetesIssuer.json by ConvertTo-Bylaw.
Policy 'ae62c456-33de-4dc8-b100-7ce9028a7d99' {

    Properties @{
        DisplayName   = '[Preview]: [Preview]: Managed Identity Federated Credentials from Azure Kubernetes should be from trusted sources'
        Description   = 'This policy limits federeation with Azure Kubernetes clusters to only clusters from approved tenants, approved regions, and a specific exception list of additional clusters.'
        Version       = '1.0.0-preview'
        Category      = 'Managed Identity'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'All'
    }

    Parameter AllowedTenants @{
        Type        = 'Array'
        DisplayName = 'Allowed tenants'
        Description = 'The list of allowed Azure AD tenant ID''s of AKS OIDC issuers. Empty to allow all tenants.'
    }
    Parameter AllowedLocations @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed locations'
        Description = 'The list of allowed locations for AKS OIDC issuers. Empty to allow any location.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter AllowedClusterExceptions @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed Exception Clusters'
        Description = 'The list of specific cluster ids that will be exceptions to the location and tenant rules.'
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled', 'Deny')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }

    Resource 'Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials' {

        When {
            Arm '[if(greaterOrEquals(length(split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')),3),split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')[2],'''')]' | Must -BeLike '*.oic.prod-aks.azure.com'
        }

        Require 'issuer is as required' {
            AnyOf {
                AllOf {
                    AnyOf {
                        Count -Value (Param AllowedLocations) | Must -Be 0
                        Arm '[if(greaterOrEquals(length(split(if(greaterOrEquals(length(split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')),3),split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')[2],''''), ''.'')),1),split(if(greaterOrEquals(length(split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')),3),split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')[2],''''), ''.'')[0],'''')]' | Must -BeIn (Param AllowedLocations)
                    }
                    AnyOf {
                        Count -Value (Param AllowedTenants) | Must -Be 0
                        Arm '[if(greaterOrEquals(length(split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')),4),split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')[3],'''')]' | Must -BeIn (Param AllowedTenants)
                    }
                }
                Arm '[if(greaterOrEquals(length(split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')),5),split(field(''Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/issuer''),''/'')[4],'''')]' | Must -BeIn (Param AllowedClusterExceptions)
            }
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Managed Identity/FIC_LimitToAzureKubernetesIssuer.json in Azure/azure-policy, under the MIT licence.