AKS クラスターの Kubernetes RBAC 設定の確認

AKS で Kubernetes RBAC を有効にし、ロールとバインドで必要な操作だけを許可します。

説明

AKS の作成時に properties.enableRBAC: true を指定すると Kubernetes RBAC が有効になります。Entra の ID に Azure ロールで API 操作を認可する aadProfile.enableAzureRBAC は別の設定です。

想定される影響

不要な管理者権限を残すと、ユーザーやサービスアカウントが他のワークロードやデータにもアクセスできる場合があります。

対処方法

既存クラスターの RBAC 設定と権限を確認します。必要な操作だけを含む Role または ClusterRole を対象に結び付け、一般ユーザーとサービスアカウントで許可・拒否をテストしてください。既存の非 RBAC クラスターは新しいクラスターへ移行する必要があります。

例

どちらの例もマネージド ID とサービス既定の Kubernetes バージョンを使います。ノード管理者の adminUserName と公開鍵 sshPublicKey、リージョンで利用できる VM サイズを指定してください。

変更前

bicep
param adminUserName string
param sshPublicKey string
param nodeVmSize string = 'Standard_D2s_v3'

resource aksCluster1 'Microsoft.ContainerService/managedClusters@2024-10-01' = {
  name: 'aksCluster1'
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    dnsPrefix: 'dnsprefix'
    agentPoolProfiles: [
      {
        name: 'agentpool'
        count: 2
        vmSize: nodeVmSize
        osType: 'Linux'
        mode: 'System'
      }
    ]
    linuxProfile: {
      adminUsername: adminUserName
      ssh: {
        publicKeys: [
          {
            keyData: sshPublicKey
          }
        ]
      }
    }
  }
}

API バージョン 2024-10-01 は新しいクラスターの RBAC を既定で有効にします。最初の例はこの既定値を使い、2 つ目は同じ設定を明示します。

変更後

bicep
param adminUserName string
param sshPublicKey string
param nodeVmSize string = 'Standard_D2s_v3'

resource aksCluster1 'Microsoft.ContainerService/managedClusters@2024-10-01' = {
  name: 'aksCluster1'
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    enableRBAC: true
    dnsPrefix: 'dnsprefix'
    agentPoolProfiles: [
      {
        name: 'agentpool'
        count: 2
        vmSize: nodeVmSize
        osType: 'Linux'
        mode: 'System'
      }
    ]
    linuxProfile: {
      adminUsername: adminUserName
      ssh: {
        publicKeys: [
          {
            keyData: sshPublicKey
          }
        ]
      }
    }
  }
}

参考資料