jawsug cli専門支部 #12 managed policyがやってきた

47
Managed Policy がやってきた JAWS-UG CLI #12 2015/02/16 Nobuhiro Nakayama

Upload: nobuhiro-nakayama

Post on 20-Jul-2015

654 views

Category:

Technology


2 download

TRANSCRIPT

Managed Policy がやってきたJAWS-UG CLI #12

2015/02/16

Nobuhiro Nakayama

me.json

{

"name“ : "Nobuhiro Nakayama",

"favorite aws services“ : [

"Storage Gateway",

"Directory Service",

"IAM"

],

"certifications“ : [

"AWS Certified Solutions Architect-Associate",

"AWS Certified SysOps Administrator-Associate",

"Microsoft Certified Solutions Expert : Server Infrastructure",

"Microsoft Certified Solutions Expert : SharePoint"

]

}

2015/2/22 2

目次

• これまでの IAM の問題点

• Managed Policy とは

• 使い方(Management Console)

• 使い方(CLI)

• まとめ

2015/2/22 3

注意事項

• 本資料は個人で準備した環境において、個人的に実施した結果や調査をもとに記載しております。

• また、本資料の内容ならびに閲覧により生じた一切の問題及び不利益について、発表者は一切の責任を負うことができませんのでご了承ください。

• 自己責任でのご活用をお願いします!

2015/2/22 4

(確認)これまでの IAM の問題点

• Group を現実の組織に則った構成にするとつらい

• 各 Group に同じ IAM Policy をコピペ・・・

• 例:CloudTrailで取得した監査ログが保存されたバケットに対する操作を禁止、など

• Policy の更新もコピペ・・・

• THE 刺身タンポポ• IAM Policy と Group が 1 対 1 になるように設計すると、Group への User の Attach が複雑になる・・・

• Role に至ってはグルーピングするような機能が無い・・・

• Pathを駆使すれば何とかなると思いますが、ガチ勢じゃないとつらい

2015/2/22 5

Managed Policyとは

• IAM Policy を独立して定義できるようになりました

• これまでは User / Group / Role に従属するものとして定義する必要があった

• User / Group / Role にアタッチできる

• バージョン管理ができる(!)

• ロールバックができる(!!!)

• ただし、5 世代まで

• User / Group / Role に従属していたこれまでの Policy は Inline Policy として残る

• (2015/2/22 追記) User / Group / Role にAttachできるManaged Policyは2つまで(?!)

• You can attach up to two managed policies to each principal entity.

• http://docs.aws.amazon.com/IAM/latest/UserGuide/managing-managed-policies-console.html#attach-managed-policy-console

2015/2/22 6

独立したリソースとしてのManaged Policy

2015/2/22 7

User / Group / Roleにアタッチした結果

2015/2/22 8

バージョン管理

2015/2/22 9

使い方(Management Console)

2015/2/22 10

Managed Policyの作成

2015/2/22 11

2015/2/22 12

2015/2/22 13

2015/2/22 14

2015/2/22 15

2015/2/22 16

2015/2/22 17

2015/2/22 18

2015/2/22 19

Managed PolicyのAttach

2015/2/22 20

2015/2/22 21

2015/2/22 22

2015/2/22 23

Policy Documentの修正

2015/2/22 24

2015/2/22 25

2015/2/22 26

2015/2/22 27

(補足)世代数が上限のときにPolicy Documentを更新

2015/2/22 28

2015/2/22 29

?!

(補足)Inline Policyの追加

2015/2/22 30

2015/2/22 31

使い方(CLI)

2015/2/22 32

と、その前に

2015/2/22 33

新しく追加された(と思われる)コマンド

• attach-group-policy

• attach-role-policy

• attach-user-policy

• create-policy

• create-policy-version

• delete-policy

• delete-policy-version

• detach-group-policy

• detach-role-policy

• detach-user-policy

• get-policy

• get-policy-version

• list-attached-group-policies

• list-attached-role-policies

• list-attached-user-policies

• list-entities-for-policy

• list-policies

• list-policy-versions

• set-default-policy-version

2015/2/22 34

set-default-policy-version

• Description

• Sets the specified version of the specified policy as the policy's default (operative) version.

• This action affects all users, groups, and roles that the policy is attached to. To list the users, groups, and roles that the policy is attached to, use the list-entities-for-policy API.

• ロールバックも簡単!

• もちろん影響範囲を事前に確認しましょう。(list-entities-for-policy)

2015/2/22 35

list-attached-*****-policies

• Managed Policy しかリスト表示してくれません。。。

• Inline Policyは以下のコマンドで確認する必要があります。

• list-group-policies

• list-role-policies

• list-user-policies

• Managed Policy と Inline Policy を併用したら不幸になりそう。。。

2015/2/22 36

改めて、、、

使い方(CLI)

2015/2/22 37

ポリシーの作成

コマンド>> aws iam create-policy

--policy-name "TestPolicy01“

--policy-document file://TestPolicy01.json

出力{

"Policy": {

"PolicyName": "TestPolicy01",

"CreateDate": "2015-02-14T12:44:45.973Z",

"AttachmentCount": 0,

"IsAttachable": true,

"PolicyId": “*************************",

"DefaultVersionId": "v1",

"Path": "/",

"Arn": "arn:aws:iam::************:policy/TestPolicy01",

"UpdateDate": "2015-02-14T12:44:45.973Z"

}

}2015/2/22 38

以降、PolicyはARNで指定します。

ポリシーのアタッチ

コマンド>> aws iam attach-user-policy

--user-name "TestUser01“

--policy-arn "arn:aws:iam::************:policy/TestPolicy01"

出力(なし)

2015/2/22 39

ポリシードキュメントの表示

コマンド>> aws iam get-policy-version

--policy-arn "arn:aws:iam::************:policy/TestPolicy01“

--version-id "v1"

出力{

"PolicyVersion": {

"CreateDate": "2015-02-14T12:44:45Z",

"VersionId": "v1",

"Document": {

(省略)

},

"IsDefaultVersion": true

}

}

2015/2/22 40

バージョンの指定は文字列です。

適用されているPolicyかどうかが確認できます。

ポリシードキュメントの更新

コマンド>> aws iam create-policy-version

--policy-arn "arn:aws:iam::************:policy/TestPolicy01“

--policy-document file://TestPolicy01.json

出力{

"PolicyVersion": {

"CreateDate": "2015-02-14T13:05:34.272Z",

"VersionId": "v2",

"IsDefaultVersion": false

}

}

2015/2/22 41

デフォルトではPolicyは適用されません。(前のバージョンが有効。Management Consoleとは違う。。。)

ポリシードキュメントの更新および即時適用

コマンド>> aws iam create-policy-version

--policy-arn "arn:aws:iam::************:policy/TestPolicy01“

--policy-document file://TestPolicy01.json

--set-as-default

出力{

"PolicyVersion": {

"CreateDate": "2015-02-14T13:07:24.243Z",

"VersionId": "v3",

"IsDefaultVersion": true

}

}

2015/2/22 42

“set-as-default”オプションを付けると、即時適用。

ポリシーのロールバック

コマンド>> aws iam set-default-policy-version

--policy-arn "arn:aws:iam::************:policy/TestPolicy01“

--version-id "v2"

出力(なし)

2015/2/22 43

適用先の一覧を表示

コマンド>> aws iam list-entities-for-policy

--policy-arn "arn:aws:iam::************:policy/TestPolicy01"

出力{

"PolicyGroups": [],

"PolicyUsers": [

{

"UserName": "TestUser01"

}

],

"PolicyRoles": [],

"IsTruncated": false

}

2015/2/22 44

まとめ

• 設計しやすくなった

• 現実の組織に則った Group 設計にしやすい

• Policy の作成が楽になりそう(コピペをしなくてよい)

• Policy の更新もしやすい(Attach先へ一括反映)

• バージョン管理もできる

• 5世代を超えるときは、古いPolicyを予め削除する必要がある。。。

• 世代数無制限マダァ-? (・∀・)っ/凵⌒☆チンチン

• Policy Document の適用には気をつけましょう

• 適用範囲やタイミングを確認せず、間違ったポリシーを即時適用なんてことも((( ;゜ Д ゜)))

• set-default-policy-versionコマンドは、特定の時間帯だけ権限を付与するような運用で使えそう(Data PipelineでCLIコマンドを実行、とか)

• 移行は・・・大変そうw

2015/2/22 45

Appendix

• AWS CLI

• http://docs.aws.amazon.com/cli/latest/index.html

• An Easier Way to Manage Your Policies(AWS Security Blog)

• http://blogs.aws.amazon.com/security/post/TxWY3VQC1NG45/An-Easier-Way-to-Manage-Your-Policies

• New – Managed Policies for AWS Identity & Access Management(Official Blog)

• https://aws.amazon.com/blogs/aws/new-managed-policies-for-aws-identity-access-management/

• Release: AWS Identity and Access Management on 2015-02-11

• https://aws.amazon.com/releasenotes/1597183568035418

2015/2/22 46

┼ヽ -|r‐、. レ |d⌒) ./| _ノ __ノ---------------制作・著作 UCD

2015/2/22 47