Cloud9のデフォルト設定での権限確認(AWS managed temporary credentials)
2021/06/20
Cloud9の環境を作成した際のデフォルトアクセス権限は、環境を作成したIAMユーザーの認証が設定されると思うのですが、はっきり試したことがなかったので試しました。
目次
デフォルト環境の確認
Cloud9の環境直後の状態です。
右上の歯車からPreferences-[AWS Settings]を確認すると、Credentialsでは、AWS managed temporary credentialsがONになっています。
1 2 3 4 5 6 7 8 |
$ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************XMOB shared-credentials-file secret_key ****************fovR shared-credentials-file region us-east-1 config-file ~/.aws/config |
ターミナルでaws configure listコマンドで確認すると、credentialファイルに記録されているようです。
1 2 3 4 5 6 7 8 9 10 11 |
cat ~/.aws/credentials # Do not modify this file, if this file is modified it will not be updated. If the file is deleted, it will be recreated on Sun Jun 20 2021 06:39:58 GMT+0000 (Coordinated Universal Time). # 8220f463d27c92d456e0ed80ea067a64888dfe3e4870771adbdb039064ecfeda # [default] aws_access_key_id=****************XMOB aws_secret_access_key=****************************nfovR aws_session_token=IQoJb3JpZ2luX2Vj ~省略~ |
credentialsファイルを確認すると、設定されています。
このCloud9環境を作成したIAMユーザーには、以下のAWS管理ポリシーをアタッチしています。
- AWSCloud9User
- AmazonEC2ReadOnlyAccess
1 2 3 4 5 6 7 8 9 10 |
$ aws ec2 describe-regions { "Regions": [ { "OptInStatus": "opt-in-not-required", "Endpoint": "ec2.eu-north-1.amazonaws.com", "RegionName": "eu-north-1" ~省略~ |
ec2 describe-regionsは許可されました。
1 2 3 4 |
$ aws s3 ls An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied |
s3 lsコマンドは拒否されました。
IAMユーザーにAmazonS3ReadOnlyAccessポリシーを追加して再度試しました。
1 2 3 |
$ aws s3 ls 2021-06-17 07:26:28 aws-sam-cli-managed-default-samclisourcebucket-12ozax7uk7jjy |
許可されました。
AWS managed temporary credentials(AWS管理一時認証情報)をオフにする
[AWS Settings]のCredentialsで、AWS managed temporary credentialsをOFFにしてみました。
1 2 3 |
$ aws ec2 describe-regions You must specify a region. You can also configure your region by running "aws configure". |
認証以前に、デフォルトリージョンまでなくなったようです。
1 2 3 |
$ aws ec2 describe-regions --region=us-east-1 Unable to locate credentials. You can configure credentials by running "aws configure". |
リージョン指定すると、credentialsがない、となりました。
1 2 3 4 5 6 7 8 |
$ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key <not set> None None secret_key <not set> None None region <not set> None None |
やっぱりないのですね。
この状態でCloud9環境のEC2にIAMロールを設定すれば、その権限が使えますね。
.aws/credentialsを残したまま、IAMロールを設定しても、CLIやSDKは.aws/credentialsを優先するので要注意ですね。
再度、[AWS Settings]のCredentialsで、AWS managed temporary credentialsをONにしてみました。
1 2 3 4 5 6 7 8 |
$ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************P766 shared-credentials-file secret_key ****************LtjI shared-credentials-file region us-east-1 config-file ~/.aws/config |
先ほどとは違う認証情報が設定されました。
1 2 3 4 5 6 7 |
$ aws sts get-caller-identity { "Account": "123456789012", "UserId": "*****************", "Arn": "arn:aws:iam::123456789012:user/Cloud9AmTest" } |
Cloud9の環境を構築したIAMユーザーの認証が使われていることが明確になりました。
AWS managed temporary credentialsの自動更新の確認
AWS managed temporary credentials (AWS 管理の一時認証情報)
こちらのユーザーガイドを見ていると、以下の記述がありました。
AWS 管理の一時認証情報は、以下のいずれかの条件の下で更新されます。
* 一定の時間が経過するたび。現在、これは5分ごとです。
* 環境の IDE を表示する Web ブラウザタブを再ロードするたび。
これは試してみよう。
5分後ぐらいに更新されるか
1 2 3 4 5 6 7 8 9 10 |
$ ls -la ~/.aws -rw-r--r-- 1 ec2-user ec2-user 1594 Jun 20 07:51 credentials $ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************LGKU shared-credentials-file secret_key ****************i1FE shared-credentials-file region us-east-1 config-file ~/.aws/config |
まずは今時点の確認
1 2 3 4 5 6 7 8 9 10 |
$ ls -la ~/.aws -rw-r--r-- 1 ec2-user ec2-user 1594 Jun 20 07:59 credentials $ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************M5I4 shared-credentials-file secret_key ****************NAsC shared-credentials-file region us-east-1 config-file ~/.aws/config |
5分ちょい後、credentialsファイルのタイムスタンプが更新されてアクセスキーIDもシークレットアクセスキーも更新されました。
8分ぐらい経ってるぽいですが、まあそこは良しと。
ブラウザのリロード
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ ls -la ~/.aws total 8 drwxr-xr-x 2 ec2-user ec2-user 25 Jun 20 08:02 . drwx------ 12 ec2-user ec2-user 4096 Jun 20 06:35 .. -rw-r--r-- 1 ec2-user ec2-user 1594 Jun 20 08:02 credentials Cloud9AmTest:~/environment $ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************VHLQ shared-credentials-file secret_key ****************hFZ1 shared-credentials-file region us-east-1 config-file ~/.aws/config |
ブラウザをリロードしてすぐに確認したら更新されてました。
AWS managed temporary credentials、本当に一時的な認証情報でした。
最後までお読みいただきましてありがとうございました!
「AWS認定資格試験テキスト&問題集 AWS認定ソリューションアーキテクト - プロフェッショナル 改訂第2版」という本を書きました。
![](https://www.sbcr.jp/wp-content/uploads/2023/01/9784815617929-1-407x596.jpg)
「AWS認定資格試験テキスト AWS認定クラウドプラクティショナー 改訂第3版」という本を書きました。
![](https://www.sbcr.jp/wp-content/uploads/2024/01/9784815625382-3-420x596.jpg)
「ポケットスタディ AWS認定 デベロッパーアソシエイト [DVA-C02対応] 」という本を書きました。
![](https://www.shuwasystem.co.jp//images/book/637791.jpg)
「要点整理から攻略するAWS認定ソリューションアーキテクト-アソシエイト」という本を書きました。
![](https://book.mynavi.jp/files/topics/135344_ext_06_0.jpg?v=1673514682)
「AWSではじめるLinux入門ガイド」という本を書きました。
![](https://www.yamamanx.com/wp-content/uploads/2023/12/81Rp5O9We6L._SY522_.jpg)
![@yamamanx](https://www.yamamanx.com/wp-content/plugins/lazy-load/images/1x1.trans.gif)
開発ベンダー5年、ユーザ企業システム部門通算9年、ITインストラクター5年目でプロトタイプビルダーもやりだしたSoftware Engineerです。
質問はコメントかSNSなどからお気軽にどうぞ。
出来る限りなるべく答えます。
このブログの内容/発言の一切は個人の見解であり、所属する組織とは関係ありません。
このブログは経験したことなどの共有を目的としており、手順や結果などを保証するものではありません。
ご参考にされる際は、読者様自身のご判断にてご対応をお願いいたします。
また、勉強会やイベントのレポートは自分が気になったことをメモしたり、聞いて思ったことを書いていますので、登壇者の意見や発表内容ではありません。
ad
ad
関連記事
-
-
AWSルートユーザーのパスワード復旧
AWSルートユーザーのパスワード最設定は、メールアドレスだけでいいのですね。 M …
-
-
AWS Lambdaで「Process exited before completing request」
AWS lambdaで「Process exited before comple …
-
-
DS18B20センサー+Raspberry Piで取得した温度をAmazon Kinesis FirehoseからS3へ格納してAthenaでクエリーしたのをQuickSightで可視化する
JAWS DAYS 2017でやりますハンズオンの「[IoTハンズオン] Ras …
-
-
Cloud9 Python3でpipも3にする
このブログは、2019/10/20に書いた、 Cloud9のAMIがCloud9 …
-
-
ちょっとしたCLI作業にEC2起動テンプレート
CLIでちょっとした作業したいだけのときに、Cloud9を使うまでもないなあと思 …
-
-
AWS Certificate Manager証明書とAmazon Route 53でAmazon API GatewayのAPIのカスタムドメイン名前解決する
AWS Certificate ManagerとAmazon Route 53と …
-
-
AWS Lambda Layersのアーカイブファイルをダウンロードする
Cloud9にLambda Layersをダウンロードしたかったので検索してみた …
-
-
共有AMIのコピー時にエラー「You do not have permission to access the storage of this ami」
他アカウントから共有されたAMIをコピーする際に、「You do not hav …
-
-
JAWS-UG関西IoT専門支部 ✕ SORACOM UG 関西「Wio LTE + 絶対圧センサーで遊ぼう!」ワークショップにいってきた
JAWS-UG関西IoT専門支部 ✕ SORACOM UG 関西「Wio LTE …
-
-
Amazon Pollyを使って覚えたい資料を耳から身体に染み込ませる
Amazon Pollyを使うとソースコードを一切かかなくても、テキストを音声に …