Bylaw

Gallery › Kubernetes › Azure Community Policy

Control which user ID containers are run with in a Kubernetes Cluster

Doesn't convert yet Policy Audit Deny Disabled Mode Microsoft.Kubernetes.Data Version 1.0.0 Preview

This policy controls allowed user IDs for containers to run with in a Kubernetes Cluster. For instructions on using this policy, please visit https://aka.ms/kubepolicydoc.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 206 lines
{
  "properties": {
    "displayName": "Control which user ID containers are run with in a Kubernetes Cluster",
    "policyType": "Custom",
    "mode": "Microsoft.Kubernetes.Data",
    "description": "This policy controls allowed user IDs for containers to run with in a Kubernetes Cluster. For instructions on using this policy, please visit https://aka.ms/kubepolicydoc.",
    "metadata": {
      "version": "1.0.0",
      "category": "Kubernetes",
      "preview": true
    },
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "excludedNamespaces": {
        "type": "Array",
        "metadata": {
          "displayName": "Namespace exclusions",
          "description": "List of Kubernetes namespaces to exclude from policy evaluation."
        },
        "defaultValue": [
          "kube-system",
          "gatekeeper-system",
          "azure-arc"
        ]
      },
      "runAsUserRule": {
        "type": "String",
        "metadata": {
          "displayName": "Run as User",
          "description": "RunAsUser controls the user ID that containers are allowed to run with"
        },
        "allowedValues": [
          "MustRunAs",
          "MustRunAsNonRoot",
          "RunAsAny"
        ]
      },
      "runAsUserRanges": {
        "type": "Object",
        "metadata": {
          "displayName": "Valid user IDs",
          "description": "Configure what user IDs are valid for pods to use. An empty list means there is no restriction on user IDs used.",
          "schema": {
            "type": "object",
            "properties": {
              "ranges": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "min": {
                      "type": "integer"
                    },
                    "max": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "min",
                    "max"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "ranges"
            ],
            "additionalProperties": false
          }
        },
        "defaultValue": {
          "ranges": [
            {
              "min": 100,
              "max": 200
            }
          ]
        }
      },
      "runAsGroupRule": {
        "type": "String",
        "metadata": {
          "displayName": "Run as Group",
          "description": "RunAsGroup controls the group ID that containers are allowed to run with"
        },
        "allowedValues": [
          "MustRunAs",
          "MayRunAs",
          "RunAsAny"
        ]
      },
      "runAsGroupRanges": {
        "type": "Object",
        "metadata": {
          "displayName": "Valid group IDs",
          "description": "Configure what group IDs are valid for pods to use. An empty list means there is no restriction on group IDs used. This is defined as a list of objects with a min and a max group id value. E.g. { \"ranges\": [{\"min\": 100, \"max\": 200}] }"
        },
        "defaultValue": {
          "ranges": [
            {
              "min": 100,
              "max": 200
            }
          ]
        }
      },
      "supplementalGroupsRule": {
        "type": "String",
        "metadata": {
          "displayName": "Supplemental Groups",
          "description": "SupplementalGroups controls the supplemental groups ID that pods are allowed to add"
        },
        "allowedValues": [
          "MustRunAs",
          "MayRunAs",
          "RunAsAny"
        ]
      },
      "supplementalGroupsRanges": {
        "type": "Object",
        "metadata": {
          "displayName": "Valid supplmental group IDs",
          "description": "Configure what supplmental group IDs are valid for pods to use. An empty list means there is no restriction on supplmental group IDs used. This is defined as a list of objects with a min and a max supplmental group id value. E.g. { \"ranges\": [{\"min\": 100, \"max\": 200}] }"
        },
        "defaultValue": {
          "ranges": [
            {
              "min": 100,
              "max": 200
            }
          ]
        }
      },
      "fsGroupRule": {
        "type": "String",
        "metadata": {
          "displayName": "FS Group",
          "description": "FSGroup controls the fsgroup ID that containers are allowed to run with"
        },
        "allowedValues": [
          "MustRunAs",
          "MayRunAs",
          "RunAsAny"
        ]
      },
      "fsGroupRanges": {
        "type": "Object",
        "metadata": {
          "displayName": "Valid fsgroup IDs",
          "description": "Configure what fsgroup IDs are valid for pods to use. An empty list means there is no restriction on fsgroup IDs used. This is defined as a list of objects with a min and a max fsgroup id value. E.g. { \"ranges\": [{\"min\": 100, \"max\": 200}] }"
        },
        "defaultValue": {
          "ranges": [
            {
              "min": 100,
              "max": 200
            }
          ]
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "in": [
          "AKS Engine",
          "Microsoft.Kubernetes/connectedClusters",
          "Microsoft.ContainerService/managedClusters"
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "constraintTemplate": "https://raw.githubusercontent.com/Azure/Community-Policy/master/policyDefinitions/Kubernetes/allowed-users/template.yaml",
          "constraint": "https://raw.githubusercontent.com/Azure/Community-Policy/master/policyDefinitions/Kubernetes/allowed-users/constraint.yaml",
          "values": {
            "excludedNamespaces": "[parameters('excludedNamespaces')]",
            "runAsUserRule": "[parameters('runAsUserRule')]",
            "runAsUserRanges": "[parameters('runAsUserRanges').ranges]",
            "runAsGroupRule": "[parameters('runAsGroupRule')]",
            "runAsGroupRanges": "[parameters('runAsGroupRanges').ranges]",
            "supplementalGroupsRule": "[parameters('supplementalGroupsRule')]",
            "supplementalGroupsRanges": "[parameters('supplementalGroupsRanges').ranges]",
            "fsGroupRule": "[parameters('fsGroupRule')]",
            "fsGroupRanges": "[parameters('fsGroupRanges').ranges]"
          }
        }
      }
    }
  },
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "bc5dd487-c01f-4f8d-b0aa-b708e8f33711"
}

Source: policyDefinitions/Kubernetes/allowed-users/azurepolicy.json in Azure/Community-Policy, under the MIT licence.