0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kong GatewayでWorkspaceを跨ぐロールを作成する

Posted at

OktaでKong Gatewayと連携する場合、OktaのGroup名を<KongのWorkspace名>:<KongのRole名>とすることでGroupに所属するユーザとKongのロールをマッピングすることが出来る。
以下の図だと、Oktaのdefault:super-adminGroupに所属する2人のユーザはDev、ProdそれぞれにSuper Adminとしてアクセスできる。
20241024100324.png

しかし、実運用を考えると以下のように環境によってはSuper Adminを渡したくないケースが出てくる。
20241024100451.png

Prod環境には権限を持たずにアクセスさせたい場合、Oktaのdefault:super-adminGroupに所属させるとマズいので、こういう場合は別のGroupとRoleを用意してあげる必要がある。
20241024101009.png

この時、dev-super-adminのようなカスタムロールを作成するのだが、これが少し面倒でKong ManagerからだとWorkspaceを跨いで利用できるロールが作成できない。
エンドポイントのパーミッションを以下のようにしても基本的に作成したWorkspaceでしか権限を持たないロールとなる。
20241024101235.png

これを回避するためにはAdmin APIを利用してロールのパーミッションを設定する必要がある。

実際に試してみる。
最初にロールを作成する。
ロールの作成はAPI仕様より/rbac/rolesにPOSTすれば作成できるので、以下のような感じで作成する。

curl -X POST -H "kong-admin-token: kong" \
   localhost:8001/rbac/roles \
   -H "Content-Type: application/json" \
   -d '{
        "name": "dev-super-admin",
        "comment": null
       }'

次にロールのエンドポイントのパーミッションを設定する。
こちらもAPI仕様より/rbac/roles/<ロール名>/endpoints以下のフォーマットでPOSTすれば設定できることが分かる。

{
  "workspace": "string",
  "endpoint": "string",
  "negative": "string",
  "actions": "string",
  "comment": "string"
}

仕様に従って以下のように実行する。

curl -X POST -H "kong-admin-token: kong" \
   localhost:8001/rbac/roles/dev-super-admin/endpoints \
   -H "Content-Type: application/json" \
   -d '{
       "workspace": "*",
       "endpoint": "*",
       "negative": false,
       "actions":  [
         "delete",
         "create",
         "update",
         "read"
       ],
       "comment": null
      }'    

"workspace": "*"の部分がミソで、ロールに紐づくWorkspaceはUIでは設定出来ないがAdmin APIでは設定できるようになっている。
ここに*を設定することでWorkspaceをまたいだロールとすることが出来る。

以上で設定は終了となる。

このロールを割り当てたユーザでKong Managerにログインすると、他のWorkspaceが確認できる。
20241024102249.png

Teams->Adminsで見ると当該ユーザのWorkspace Access*となっており、Workspaceによる制約がなくなっていることも確認できる。

20241024102419.png

ということで、Admin APIを使えばWorkspaceを跨いだ権限設定が出来ることが確認できた。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?