Skip to content

Commit 876e5c6

Browse files
author
XUANHE ZHOU
committed
1.conversion assume-role to cs 2.encryped secret access key 3. indicate encryption in read me 3. add tests for aws-cs-assume-role and delete test for aws serverless-raw
1 parent cf21741 commit 876e5c6

File tree

23 files changed

+1092
-91
lines changed

23 files changed

+1092
-91
lines changed

aws-cs-assume-role/README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# AWS Resources Using AssumeRole
2+
3+
This example shows how to use the AssumeRole functionality of the AWS provider to create resources in the security context of an IAM Role assumed by the IAM User running the Pulumi programs.
4+
5+
## Deploying the Example
6+
7+
### Part 1: Privileged Components
8+
9+
The Pulumi program in `create-role` requires credentials with permissions to create an IAM User, an IAM Role, and assign
10+
an AWS Access Key to the user. The program creates a new, unprivileged user with no policies attached, and a role which
11+
specifies a trust policy allowing assumption by the unprivileged user. The role allows the `s3:*` actions on all
12+
resources.
13+
14+
You'll need to set the `create-role:unprivilegedUsername` configuration variable to the name of the unprivilged user, as
15+
well as the AWS region in which to operate.
16+
17+
```bash
18+
$ cd create-role
19+
$ pulumi stack init assume-role-create
20+
$ pulumi config set create-role:unprivilegedUsername [email protected]
21+
$ pulumi config set aws:region us-east-1
22+
$ pulumi up
23+
```
24+
25+
The program can then be run with `pulumi up`. The outputs of the program tell you the ARN of the Role, and the Access
26+
Key ID and Secret associated with the User:
27+
28+
29+
```
30+
$ pulumi stack output --json
31+
{
32+
"accessKeyId": "AKIAI7JE74TLY2LOEIJA",
33+
"secretAccessKey": "[secret]",
34+
"roleArn": "arn:aws:iam::<redacted>:role/allow-s3-management-ad477e6"
35+
}
36+
```
37+
If we just use the above command then the secretAccessKey would not be shown. In order to show the secret value use this
38+
39+
```
40+
$ pulumi stack output --json --show-secrets
41+
{
42+
"accessKeyId": "AKIAYJ7EUPHL3DSDH4CX",
43+
"secretAccessKey": "[plain text value]",
44+
"roleArn": "arn:aws:iam::571173272023:role/allow-s3-management-fcc71c0"
45+
}
46+
```
47+
48+
### Part 2: Assuming the Role
49+
50+
The Pulumi program in `assume-role` creates an S3 bucket after assuming the Role created in Part 1. It should be run
51+
with the unprivileged user credentials created in Part 1. This can be configured as follows, from the `assume-role`
52+
directory, replacing `{YOUR_STACK_PATH/assume-role-create}` with the full name of your stack from Part 1. Full name of your stack is available at [`app.pulumi.com`][app]
53+
54+
```bash
55+
$ cd assume-role
56+
$ npm install
57+
$ export AWS_ACCESS_KEY_ID="$(pulumi stack output --stack {YOUR_STACK_PATH/assume-role-create} accessKeyId)"
58+
$ export AWS_SECRET_ACCESS_KEY="$(pulumi stack output --stack {YOUR_STACK_PATH/assume-role-create} --show-secrets secretAccessKey)"
59+
```
60+
61+
The configuration variable `roleToAssumeARN` must be set to the ARN of the role allowing S3 access, and the AWS region
62+
must be set to the region in which you wish to operate:
63+
64+
```bash
65+
$ pulumi stack init assume-role-assume
66+
$ pulumi config set roleToAssumeARN "$(pulumi stack output --stack {YOUR_STACK_PATH/assume-role-create} roleArn)"
67+
$ pulumi config set aws:region us-east-1
68+
```
69+
70+
Unset the AWS_SESSION_TOKEN or any additional credential setting if you have set for previous access
71+
72+
```bash
73+
$ unset AWS_SESSION_TOKEN
74+
```
75+
76+
The program can then be run with `pulumi up`. You can verify that the role is indeed assumed by looking at the
77+
CloudTrail logs of the bucket creation operation, or by commenting out the `assumeRole` configuration in the provider
78+
and ensuring creation is not successful.
79+
80+
### Clean up
81+
82+
To clean up your resources, run `pulumi destroy` and respond yes to the
83+
confirmation prompt.
84+
85+
[app]: https://app.pulumi.com/

0 commit comments

Comments
 (0)