LoginSignup
4
3

More than 5 years have passed since last update.

oci-policy-generator の使い方

Posted at

はじめに

OCI の IAM で作成したユーザ・グループに、適切な権限を設定するためには、複雑な Policy をテキストで指定する必要があり、わかりにくい設定方法となっています。

例えば、sugigroupという名前のグループに、userの管理者権限を付与する場合は、次のテキストを指定してポリシーを作成することになります。

allow group sugigroup to manage users in tenancy

上のテキストを、Documentを調べながら作り出すのはしんどいので、GitHubで公開されている oci-policy-generator を使用して、比較的簡単に生成することが出来ます。

前提条件

  • OCI CLI が Install されていること
  • Java JDK が Install されていること

OCI CLI Install

次の記事などを参考に、OCI CLI を Install します
https://qiita.com/sugimount/items/63a8cfe1163030ae8804

JDK Install

適当にJDKをInstallします

oci-policy-generator install

GitHubで公開されている jar ファイルをダウンロードします

mkdir ~/oci-policy-generator
cd ~/oci-policy-generator
wget https://github.com/recursivecodes/oci-policy-generator/releases/download/0.3/oci-policy-generator-0.3.jar

oci-policy-generator の実行

javaコマンドで、ダウンロードしてきたjarファイルを指定して、ジェネレーターを起動します

java -jar oci-policy-generator-0.3.jar

実行例

> java -jar oci-policy-generator-0.3.jar
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/home/sugi/oci-policy-generator/oci-policy-generator-0.3.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

   ____  __________   ____        ___               ______                           __
  / __ \/ ____/  _/  / __ \____  / (_)______  __   / ____/__  ____  ___  _________ _/ /_____  _____
 / / / / /    / /   / /_/ / __ \/ / / ___/ / / /  / / __/ _ \/ __ \/ _ \/ ___/ __ `/ __/ __ \/ ___/
/ /_/ / /____/ /   / ____/ /_/ / / / /__/ /_/ /  / /_/ /  __/ / / /  __/ /  / /_/ / /_/ /_/ / /
\____/\____/___/  /_/    \____/_/_/\___/\__, /   \____/\___/_/ /_/\___/_/   \__,_/\__/\____/_/
                                       /____/

OCI Policy Generator v0.3 is using OCI CLI version 2.5.1.

Any User (0), Group (1) or Service (2)?

ポリシーを生成するサンプル

プロンプトに従って、数字を入力していくことで、Policyを生成する流れとなります。
OCIのGroupを使用してPolicyを生成するために、1 を入力します。

Any User (0), Group (1) or Service (2)? 1

OCIに存在しているGroupを自動取得し、選択肢に表示されます。1 を入力します。

Available Subjects:
0: Administrators
1: sugigroup
Choose subject(s) [0-1] (separate multiple with a comma): 1

manage(全権限)を付与するため、3 を入力します

Available Verbs:
0: inspect
1: read
2: use
3: manage
Select verb [0-3]: 3

users を対象にするため、69 を入力します

Available Resource Types:

 0: all-resources (includes all shown below)

 1: cluster-family (includes 2-4)
 2: clusters                     3: cluster-node-pools           4: cluster-work-requests

 5: database-family (includes 6-10)
 6: db-systems                   7: db-nodes                     8: db-homes
 9: databases                    10: backups

 11: autonomous-transaction-processing-family (includes 12-13)
 12: autonomous-database         13: autonomous-backup

 14: autonomous-data-warehouse-family (includes 15-16)
 15: autonomous-data-warehouse    16: autonomous-data-warehouse-backup

 17: dns (includes 18-20)
 18: dns-zones                   19: dns-records                 20: dns-traffic

 21: file-family (includes 22-24)
 22: file-systems                23: mount-targets               24: export-sets

 25: instance-family (includes 26-33)
 26: app-catalog-listing         27: console-histories           28: instance-configurations
 29: instance-console-connection    30: instance-images             31: instance-pools
 32: instances                   33: volume-attachments

 34: object-family (includes 35-37)
 35: objectstorage-namespaces    36: buckets                     37: objects

 38: virtual-network-family (includes 39-59)
 39: vcns                        40: subnets                     41: route-tables
 42: security-lists              43: dhcp-options                44: private-ips
 45: public-ips                  46: internet-gateways           47: nat-gateways
 48: service-gateways            49: local-peering-gateways      50: remote-peering-connections
 51: drgs                        52: drg-attachments             53: cpes
 54: ipsec-connections           55: cross-connects              56: cross-connect-groups
 57: virtual-circuits            58: vnics                       59: vnic-attachments

 60: volume-family (includes 61-65)
 61: volumes                     62: volume-attachments          63: volume-backups
 64: boot-volume-backups         65: backup-policies

 66: functions-family (none at this time)

 68: compartments                69: users
 70: groups                      71: dynamic-groups              72: policies
 73: identity-providers          74: tenancies                   75: tag-namespaces
 76: tagdefinitions              77: workrequest                 78: repos


Select resource type [0-78]: 69

Tenancyを指定するため、0 を入力します

Available Locations:
0: tenancy
1: compartment
Tenancy (0) or Compartment (1)? 0

Condition を指定し、対象を制限します。特に必要ない場合は、コンディションは空白のままエンターを押します。
https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm#Conditio

For more info on conditions, see: https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm#Conditio
To add a condition, enter it as a string.
Ex: "target.group.name != 'Administrators'"
Leave blank for no condition(s): target.user.name = 'sugi'

Policyが生成されます。続けて、ジェネレーターからPolicy を Apply することが出来ますが、今回はSkipします

Your generated policy is:
allow group sugigroup to manage users in tenancy where target.user.name = 'sugi'

Apply Policy? Yes (1) or No (0): 0

上記で生成されたポリシーを使用して、OCIへ設定していくと反映されます。

参考URL

Oracle Blog
https://blogs.oracle.com/developers/automated-generation-for-oci-iam-policies

GitHub
https://github.com/recursivecodes/oci-policy-generator

4
3
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
4
3