LoginSignup
0
0

More than 3 years have passed since last update.

AzureADのグループにAKSの読み取り権限をRBACを使って与える

Posted at

AKSの読み取り権限を、AzureAD上にあるグループに与える必要があり調べてみました。AzureADとKubernetesのロールなどを使って行いましたので、そのあたりをまとめてみました。

Azureの既存のロールをグループに割り当て

細かく権限を管理する場合は、カスタムロールを作って権限を精査する必要がありますが 、テスト環境などでそれほど気にしなくてよい場合は既存のロールで十分かと思います。
AzureADに存在するMyReadOnlyGroupに読み取り権限を与えます。

#権限をつけるグループとAKSのIDを取得
AksID=$(az aks show --resource-group my-resource \
      --name my-aks --query id -o tsv)
GroupID=$(az ad group show --group "MyReadOnlyGroup" \
        --query objectId -o tsv)

#ロールアサイメント
az role assignment create --assignee $GroupID \
   --role "Azure Kubernetes Service Cluster User Role" \
   --scope $AksID

Azure portalのAKSのアクセス制御(IAM)でMyReadOnlyGroupAzure Kubernetes Service Cluster User Roleが付いていることが確認できます。

KubernetesのCluster Role/Viewをグループに割り当て

先ほどと同じグループに次はKubernetes内でView権限を割り当てます。Viewロールだと大体のリソースを見ることはできますが、シークレットを見ることはできません。これもAzureADのロール同様、テスト環境なので既存のロールを使用しクラスター全体の読み取り権限を与えます。

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: aks-readonly
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
- kind: Group
  name: groupObjectId

groupObjectIdを先ほどの$GroupIDで置き換えると、MyReadOnlyGroupにK8Sの読み取り権限を与えることができます。

kubectlで確認するとこのような感じです。

kubectl describe clusterrolebinding aks-readonly

Name:         aks-readonly
Labels:       <none>
Annotations:  <none>
Role:
  Kind:  ClusterRole
  Name:  view
Subjects:
  Kind   Name                                  Namespace
  ----   ----                                  ---------
  Group  1111111-11111-1111-1111-111111111

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0