Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AWS CLIでCMKを沢山作ってみたら 困ったこと
Search
Yuki_Kurono
July 25, 2022
Programming
330
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWS CLIでCMKを沢山作ってみたら 困ったこと
Yuki_Kurono
July 25, 2022
More Decks by Yuki_Kurono
See All by Yuki_Kurono
Terraform(IaC)と実環境の乖離どうしていますか?
yuki_kurono
0
62
今年のre:inventから学ぶこと
yuki_kurono
0
120
re_invent 2023事前勉強会
yuki_kurono
0
110
CloudFormationの運用が 辛くならない方法を本気で考えてみた
yuki_kurono
0
390
CloudFormationで登場したForEachをちゃんと理解してみる
yuki_kurono
0
930
Turnstileのウィジェット モードとは何者か
yuki_kurono
0
750
CodeGuru Security ってなんだ?
yuki_kurono
0
1.2k
えるしってるか CloudFrontはWAFがあっても カスタムエラーレスポンスを返せる
yuki_kurono
0
470
Cloudflare初心者がIaCから基本構成を学んでみた
yuki_kurono
1
680
Other Decks in Programming
See All in Programming
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
1.9k
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
140
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
570
Event is what happens
moro
2
3.4k
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
510
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
400
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
870
AmebaブログはKMPから卒業します
kmars0605
0
320
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
200
Getting Started with Vibe Coding
miccheng
0
180
Performance Optimization With LLMs
xleitix
0
240
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
190
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Facilitating Awesome Meetings
lara
57
7.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
GraphQLとの向き合い方2022年版
quramy
50
15k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
600
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
760
Mobile First: as difficult as doing things right
swwweet
225
10k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
320
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
390
Transcript
AWS CLIでCMKを沢山作ってみたら 困ったこと 黒野 雄稀 JAWS-UG CLI専門支部 #270R 2022/07/24
自己紹介 名前 黒野 雄稀 AWS歴 ・約3年 ・2022 APN ALL
AWS Certifications Engineer 所属 アイレット株式会社 普段の業務 ・基幹系インフラ構築 ・システム運用構築
背景 CloudTrail皆さん使っていますか? 今回は複数のAWSアカウント(約16アカウント)でCloudTrailの有効化に伴い、 CMKの作成が必要となりました。 コンソールで作るのは流石に大変。。ということでAWS CLIを使ってCMKを作成 してみました。
対象となるリージョン • 東京 • バージニア北部 • シンガポール • フランクフルト •
北京
スクリプト概要
aws-vault設定 ここからスクリプトの中からポイントの部 分に解説を入れていきます。 ※スクリプト全体はQiitaに記載しておき ます。 #スイッチロールの設定を行う。 export SWICHROLE=$ROLE echo $SWICHROLE
shopt -s expand_aliases alias av='aws-vault exec $SWICHROLE --no-session --' #結果出力先ファイルの設定を行う。 export OUTPUT=./result-kms/create/${SWICHROLE}-kms-result-${NOW}.txt #アカウントIDの取得を行う。 ACCOUNT=$(av aws sts get-caller-identity | jq -r .Account) コマンド
キーポリシー ファイル作成 ベースとなるポリシーファイルを 用意して、固有情報(アカウントID、リー ジョン)だけ書き換えを行っています。 echo -e "\U2705KMSキーポリシー作成 " cp
./base-key-policy.json ./key-policy-${SWICHROLE}.json sudo sed -i -e "s/ap-northeast-1/${REGION}/" ./key-policy-${SWICHROLE}.json sudo sed -i -e "s/12345678910/${ACCOUNT}/" ./key-policy-${SWICHROLE}.json コマンド
CMK、エイリアスの 作成 上記で作成した、キーポリシーを元に CMKの作成とエイリアスの作成を行う。 #上記で作成したキーポリシーを使用して、 CKMの作成を行う。 echo -e "\U2705KMSキー作成" KEYID=$(av
aws kms create-key --key-usag ENCRYPT_DECRYPT \ --origin AWS_KMS --policy file://key-policy-${SWICHROLE}.json \ --region $REGION | jq -r .KeyMetadata.KeyId) echo -e "\U2705 KEYID:${KEYID}" #作成したCKMに対して、エイリアスの作成を行う。 echo -e "\U2705エイリアス作成" av aws kms create-alias --alias-name alias/$KEYNAME \ --target-key-id $KEYID --region $REGION コマンド
作成したCMK、 エイリアスの確認 最後に作成したCMKのエイリアスと設定 内容を確認する。 #作成したCKMにエイリアスが作成されて、適切な設定が行われているか確認する。 echo -e "\U2705KMSキー確認" av aws
kms list-aliases --key-id ${KEYID} > $OUTPUT コマンド 実行結果
しかしここで失敗する。。 ・フランクフルトリージョンまで上手くいっていたが、中国で何故かスクリプトが失 敗する。。 ・調べてみるとキーポリシーの作成で以下の様な記述がありました。 { "Version": "2012-10-17", "Id": "Key policy
created by CloudTrail", "Statement": [ { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456578910:root" }, "Action": "kms:*", "Resource": "*" },
馴染のある方、勘のいい方はお気づきかもしれません。 そう、AWS中国のARNはarn:awsではなくarn:aws-cnでした。 なので、以下の様な処理を追加する必要がありました。 if [ $REGION = "cn-north-1" ]; then
sudo sed -i -e "s/arn:aws/arn:aws-cn/" ./key-policy-${SWICHROLE}.json fi
まとめ • TerraformやCFnでも同じような、落とし穴があると思いますので注意が必要だったなと 思いました。 ◦ 中国など慣れない環境は事前調査大事 • シェルスクリプト自体の知識が浅く、エラーハンドリングが甘いので深堀し ていきた
い。
参考 Qiita: https://qiita.com/kurono/items/b 3362e16a3a396b9b2a7
おまけ 以下の様なコマンドを使用するとbashでユニコードを扱うことができます。 作業してるとテンションが上がります。 echo -e "\U2705KMSキー確認" コマンド 実行結果
ご清聴ありがとうございま した