このトピックでは、Distributed Cloud Container Platform for Kubernetes GitOpsのマルチテナント権限を設定する方法と、権限を検証する方法について説明します。
目次
権限モデル
利用シナリオ
ユーザー | ロール | リソーススコープ | 権限 |
admin | スーパー管理者 | すべてのリソース |
|
team01-admin | プロジェクト管理者 | プロジェクトteam01 | リポジトリなどのプロジェクトレベルのリソースを照会、作成、変更、および削除します。 |
team02-admin | プロジェクト管理者 | プロジェクトteam02 | リポジトリなどのプロジェクトレベルのリソースを照会、作成、変更、および削除します。 |
team01-user01 | アプリケーション管理者 | team01 /本番アプリ | team01/production-appでアプリケーションを照会、作成、変更、および削除します。 |
team01-user02 | アプリケーション管理者 | team01/staging-app | team01/staging-appでアプリケーションを照会、作成、変更、および削除します。 |
ACK One GitOpsのマルチテナント権限の設定
次のコマンドを実行して、
argocd-cm
ConfigMapを変更します。kubectl edit cm argocd-cm -n argocd
次のローカルユーザーを
argocd-cm
ConfigMapに追加します。data: accounts.team01-admin: login accounts.team01-admin.enabled: "true" accounts.team01-user01: login accounts.team01-user01.enabled: "true" accounts.team01-user02: login accounts.team01-user02.enabled: "true" accounts.team02-admin: login accounts.team02-admin.enabled: "true"
次のコマンドを実行して、
argocd-rbac-cm
ConfigMapを変更します。kubectl edit cm argocd-rbac-cm -n argocd
argocd-RBAC-cm
ConfigMapで、ローカルユーザーに対して次のロールベースのアクセス制御 (rbac) ルールを設定します。管理者アカウントでArgoCDにログインし、ローカルユーザーを表示し、各ローカルユーザーのパスワードを設定します。
次のコマンドを実行して、ローカルユーザーを表示します。
export ARGOCD_OPTS='--port-forward-namespace argocd --port-forward' argocd account list
期待される出力:
NAME ENABLED CAPABILITIES admin true apiKey, login team01-admin true login team01-user01 true login team01-user02 true login team02-admin true login
次のコマンドを実行して、ローカルユーザーのパスワードを設定します。
argocd account update-password --account <username> --current-password <current password> --new-password <new password>
管理者アカウントでArgoCDにログインし、次のコマンドを実行してグローバルリポジトリを追加します。
argocd repo add https://code.aliyun.com/bigteam/echo-server01.git argocd repo add https://code.aliyun.com/bigteam/echo-server02.git argocd repo list TYPE NAME REPO INSECURE OCI LFS CREDS STATUS MESSAGE PROJECT git https://code.aliyun.com/bigteam/echo-server01.git false false false false Successful git https://code.aliyun.com/bigteam/echo-server02.git false false false false Successful
管理者アカウントでArgoCDにログオンし、次のコマンドを実行してProject team01およびProject team02を作成および設定します。
カテゴリ
Gitリポジトリ
クラスター
Project team01がアクセスを許可されているリソース
https://code.aliyun.com/bigteam/echo-server01.git
https:// 47.111.XX.XX:6443
Project team02がアクセスを許可されているリソース
https://code.aliyun.com/bigteam/echo-server02.git
https:// 47.97.XX.XX:6443
argocd proj create team01 argocd proj add-source team01 https://code.aliyun.com/bigteam/echo-server01.git argocd proj add-destination team01 https://47.111.XX.XX:6443 "*" argocd proj create team02 argocd proj add-source team02 https://code.aliyun.com/bigteam/echo-server02.git argocd proj add-destination team02 https://47.97.XX.XX:6443 "*"
team01-adminアカウントとteam02-adminアカウントを使用して、プロジェクトにリポジトリを作成します。
team01-管理者
次のコマンドを実行して、team01-adminアカウントでログインします。
argocd login Username: team01-admin Password: 'team01-admin:login' logged in successfully Context 'port-forward' updated
次のコマンドを実行して、Project team01にリポジトリを作成します。
argocd repo add https://code.aliyun.com/team01/echo-server.git --project team01
期待される出力:
Repository 'https://code.aliyun.com/team01/echo-server.git' added
team02-管理者
次のコマンドを実行して、team02-adminアカウントでログインします。
argocd login Username: team02-admin Password: 'team01-admin:login' logged in successfully Context 'port-forward' updated
次のコマンドを実行して、Project team02にリポジトリを作成します。
argocd repo add https://code.aliyun.com/team02/echo-server.git --project team02
期待される出力:
Repository 'https://code.aliyun.com/team02/echo-server.git' added
ACK One GitOpsの権限モデルを確認する
リソースに対するプロジェクト管理者の権限を確認する
プロジェクトの権限を確認する
次のコマンドを実行して、プロジェクトに対するteam01-adminの権限を確認します。
argocd account can-i create projects "*"
no
argocd account can-i update projects "team01"
no
argocd account can-i delete projects "team01"
no
argocd account can-i get projects "team01"
yes
argocd account can-i get projects "team02"
no
上記の出力は、プロジェクト管理者がproject team01のみを表示できることを示しています。 プロジェクト管理者には他の権限がありません。
リポジトリの権限を確認する
次のコマンドを実行して、リポジトリに対するteam01-adminの権限を確認します。
argocd account can-i create repositories "*"
no
argocd account can-i update repositories "*"
no
argocd account can-i delete repositories "*"
no
argocd account can-i get repositories "*"
yes
argocd account can-i create repositories "team01/*"
yes
argocd account can-i update repositories "team01/*"
yes
argocd account can-i delete repositories "team01/*"
yes
argocd account can-i get repositories "team01/*"
yes
上記の出力は、プロジェクト管理者がグローバルリポジトリを表示し、project team01でリポジトリを照会、作成、変更、および削除できることを示しています。
クラスターの権限を確認する
次のコマンドを実行して、クラスターに対するteam01-adminの権限を確認します。
argocd account can-i create clusters "*"
no
argocd account can-i update clusters "*"
no
argocd account can-i delete clusters "*"
no
argocd account can-i get clusters "*"
yes
argocd account can-i create clusters "team01/*"
no
argocd account can-i update clusters "team01/*"
no
argocd account can-i delete clusters "team01/*"
no
上記の出力は、プロジェクト管理者がグローバルクラスターのみを表示できることを示しています。 プロジェクト管理者には他の権限がありません。
アプリケーションの権限を確認する
次のコマンドを実行して、アプリケーションに対するteam01-adminの権限を確認します。
argocd account can-i create applications "*"
no
argocd account can-i update applications "*"
no
argocd account can-i delete applications "*"
no
argocd account can-i get applications "*"
no
argocd account can-i create applications "team01/*"
yes
argocd account can-i update applications "team01/*"
yes
argocd account can-i delete applications "team01/*"
yes
argocd account can-i get applications "team01/*"
yes
上記の出力は、プロジェクト管理者がproject team01でアプリケーションの照会、作成、変更、および削除のみできることを示しています。 プロジェクト管理者には他の権限がありません。
クラスターを作成する権限を確認する
次のコマンドを実行して、Project team01のteam01-adminの権限を表示します。
team01-adminがアクセスできるリポジトリ:
グローバル
リポジトリ
:https://code.aliyun.com/bigteam/echo-server01.git
。Project team01:
https://code.aliyun.com/team01/echo-server.git
のスコープ付きリポジトリ
。
team01-adminがアクセスできるクラスター:
https:// 47.111.XX.XX:6443
argocd proj get team01 Name: team01 Description: Destinations: https://47.111.XX.XX:6443,* Repositories: https://code.aliyun.com/bigteam/echo-server01.git Scoped Repositories: https://code.aliyun.com/team01/echo-server.git Allowed Cluster Resources: <none> Scoped Clusters: <none> Denied Namespaced Resources: <none> Signature keys: <none> Orphaned Resources: disabled
次のコマンドを実行して、Project team01の外部にアプリケーションを作成します。
argocd app create team01-admin-echo-server --repo https://code.aliyun.com/bigteam/echo-server01.git --dest-namespace team01-admin-echo-server --dest-server https://47.111.XX.XX:6443
期待される出力:
FATA[0001] rpc error: code = PermissionDenied desc = permission denied: applications, create, default/team01-admin-echo-server, sub: team01-admin, iat: 2022-10-20T03:20:47Z
上記の出力は、システムがProject team01の外部にアプリケーションを作成できなかったことを示しています。
次のコマンドを実行して、不正なリポジトリとクラスターを使用してアプリケーションを作成します。
argocd app create team01-admin-echo-server --project team01 --repo https://code.aliyun.com/bigteam/echo-server02.git --path manifests/directory/production --dest-namespace team01-admin-echo-server --dest-server https://47.97.XX.XX:6443
期待される出力:
FATA[0002] rpc error: code = InvalidArgument desc = application spec for team01-admin-echo-server is invalid: InvalidSpecError: application repo https://code.aliyun.com/bigteam/echo-server02.git is not permitted in project 'team01';InvalidSpecError: application destination {https://xx.xx.xx.xx:6443 team01-admin-echo-server} is not permitted in project 'team01
では許可されていません
上記の出力は、システムが不正なリポジトリとクラスターを使用してアプリケーションを作成できなかったことを示しています。
次のコマンドを実行して、承認されたリポジトリとクラスターを使用してProject team01にアプリケーションを作成します。
argocd app create team01-admin-echo-server --project team01 --repo https://code.aliyun.com/bigteam/echo-server01.git --path manifests/directory/production --dest-namespace team01-admin-echo-server --dest-server https://47.111.XX.XX:6443 application 'team01-admin-echo-server' created
期待される出力:
application 'team01-admin-echo-server' created
上記の出力は、システムがProject team01でアプリケーションを作成したことを示しています。