Skip to content

Commit e9206e0

Browse files
author
Chris Gilmer
authored
Merge pull request #67 from trussworks/cg_update_profiles
Managing AWS profiles
2 parents f422a95 + 62a9dbf commit e9206e0

14 files changed

+1037
-329
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin/
22
dist/
3+
coverage.out

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# goreleaser removes the `v` prefix when building and this does too
2-
VERSION = 0.0.1
2+
VERSION = 0.5.0
33

44
ifdef CIRCLECI
55
UNAME_S := $(shell uname -s)
@@ -19,6 +19,11 @@ bin/setup-new-aws-user: ## Build setup-new-aws-user
1919
test:
2020
go test -v ./cmd/...
2121

22+
.PHONY: test_coverage
23+
test_coverage:
24+
go test -v -coverprofile=coverage.out -covermode=count ./cmd/...
25+
go tool cover -html=coverage.out
26+
2227
.PHONY: clean
2328
clean:
2429
rm -f .*.stamp

README.md

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,65 @@ brew tap trussworks/tap
1515
brew install setup-new-aws-user
1616
```
1717

18-
## Usage
19-
20-
### Prerequisites
18+
### Dependencies
2119

22-
#### Dependencies
20+
This tool requires aws-vault be installed. You can install via homebrew:
2321

2422
```shell
2523
brew cask install aws-vault
2624
```
2725

26+
## Usage
27+
28+
This tool has several subcommands. Read each section to learn more.
29+
30+
### setup-new-aws-user setup
31+
2832
Before running this tool, you will need to following pieces of information
2933

34+
* IAM user name - This is your IAM username. Use the flag `--iam-user` with this value.
3035
* IAM role name - This is the IAM Role with permissions allowing access to AWS APIs
3136
and services. This is usually something like `admin` or `engineer`. Use the flag
3237
`--iam-role` with this value.
33-
* IAM user name - This is your IAM username. Use the flag `--iam-user` with this value.
34-
* AWS profile - This is the name that populates your `~/.aws/config` profile
35-
name. It is usually the name of the aws account alias you are trying to access.
36-
Use the flag name `--aws-profile` with this value.
37-
* AWS account Id - This is the 12-digit account number of the AWS account you
38-
are trying to access. Use the flag `--aws-account-id` with this value.
38+
* AWS Profiles and Account IDs - This is the set of aws profile names you wish to
39+
add along with the corresponding AWS account ID. They are referenced as
40+
`<AWS_PROFILE>:<AWS_ACCOUNT_ID>`. Use the flag name `--aws-profile-account`
41+
with each set you wish to add.
3942
* Temporary AWS access keys - These should be given to you by an administrator
4043
of the AWS account you are trying to access. The tool will prompt you for
4144
the access key id and secret access key.
4245

43-
## Running the tool
46+
1. Run the setup-new-user script
47+
48+
```sh
49+
setup-new-aws-user setup \
50+
--iam-user <USER> \
51+
--iam-role <ROLE> \
52+
--aws-profile-account <AWS_PROFILE1>:<AWS_ACCOUNT_ID1> \
53+
--aws-profile-account <AWS_PROFILE2>:<AWS_ACCOUNT_ID2>
54+
```
4455

45-
1. Run the setup-new-user script - `setup-new-aws-user setup --iam-role <IAM_ROLE> --iam-user <USER> --aws-profile=<AWS_PROFILE> --aws-account-id=<AWS_ACCOUNT_ID>`
4656
2. Enter the access keys generated when prompted.
4757
3. The script will open a window with a QR code, which you will use to configure a temporary one time password (TOTP).
4858
4. You'll then need to create a new entry in your 1Password account configure it with a TOTP field.
4959
5. Use 1Password to scan the QR code and hit save. New TOTP tokens should generate every 30 seconds.
5060
6. From here the tool will prompt you for 3 unique TOTP tokens. **NOTE Take care not to use the same token more than once, as this will cause the process to fail.**
51-
7. Once the tool has completed, you should be able to access the AWS account. You can run the following command filling in the AWS_PROFILE value
61+
7. Once the tool has completed, you should be able to access the AWS account. You can run the following command filling in the `AWS_PROFILE` value
5262
53-
```shell
54-
aws-vault exec $AWS_PROFILE -- aws sts get-session
55-
```
63+
```sh
64+
aws-vault exec $AWS_PROFILE -- aws sts get-session
65+
```
5666
57-
## How this tool modifies your ~/.aws/config
67+
#### How `setup` modifies your ~/.aws/config
5868
5969
While your AWS access keys are stored in a password protected keychain managed by `aws-vault`, the configuration for
60-
how you should access AWS accounts lives in ~/.aws/config. The setup-new-aws-user tool creates two profiles your
70+
how you should access AWS accounts lives in ~/.aws/config. The `setup-new-aws-user setup` tool creates new profiles in
6171
`~/.aws/config`. The first is the base profile containing your long lived AWS Access Keys and is tied to your IAM user
6272
and MFA device. Since these keys are long lived, you should be rotating them regularly with `aws-vault rotate`.
6373
The second profile is the IAM role granting you elevated access to the AWS account. Typically these IAM roles are
6474
named `admin` or `engineer` and only uses temporary credentials leveraging AWS's Security Token Service (STS).
65-
Below is an example config generated from this tool.
75+
Below is an example config generated from this tool. Additional profiles will be similarly added and reference the
76+
base profile.
6677

6778
```ini
6879
[profile corp-id-base]
@@ -78,7 +89,7 @@ region=us-west-2
7889
output=json
7990
```
8091

81-
### MFA Management
92+
#### MFA Management
8293

8394
This tool will help create and enable a virtual MFA device. The interface for the MFA device is a QR code
8495
which will be shown to the user during setup. This QR code can be used with a password manager to provide the
@@ -88,6 +99,71 @@ In the case where the user has a virtual MFA device already set up they can choo
8899
This is done by issuing the `--no-mfa` flag on the command line in conjunction with the regular command from
89100
above.
90101

102+
### setup-new-aws-user add-profile
103+
104+
Before running this tool, you will need to following pieces of information
105+
106+
* IAM role name - This is the IAM Role with permissions allowing access to AWS APIs
107+
and services. This is usually something like `admin` or `engineer`. Use the flag
108+
`--iam-role` with this value.
109+
* AWS profile - This is the name of the profile in your `~/.aws/config` profile
110+
that you wish to use as the basis for adding new profiles. The `source_profile`
111+
and `mfa_serial` is pulled from this profile.
112+
Use the flag name `--aws-profile` with this value.
113+
* AWS Profiles and Account IDs - This is the set of aws profile names you wish to
114+
add along with the corresponding AWS account ID. They are referenced as
115+
`<AWS_PROFILE>:<AWS_ACCOUNT_ID>`. Use the flag name `--aws-profile-account`
116+
with each set you wish to add.
117+
118+
1. Run the setup-new-user script -
119+
120+
```sh
121+
setup-new-aws-user add-profile \
122+
--aws-profile <AWS_PROFILE> \
123+
--iam-role <IAM_ROLE> \
124+
--aws-profile-account <AWS_PROFILE1>:<AWS_ACCOUNT_ID1> \
125+
--aws-profile-account <AWS_PROFILE2>:<AWS_ACCOUNT_ID2>
126+
```
127+
128+
2. Once the tool has completed, you should be able to access the AWS account. You can run the following command filling in the `AWS_PROFILE` value
129+
130+
```sh
131+
aws-vault exec $AWS_PROFILE -- aws sts get-session
132+
```
133+
134+
#### How `add-profile` modifies your ~/.aws/config
135+
136+
While your AWS access keys are stored in a password protected keychain managed by `aws-vault`, the configuration for
137+
how you should access AWS accounts lives in ~/.aws/config. The `setup-new-aws-user add-profile` tool creates new profiles in
138+
`~/.aws/config`. New profiles reference the `source_profile` and `mfa_serial` of the `--aws-profile` used in
139+
the command and uses the IAM role granting you elevated access to the AWS account. Typically these IAM roles are
140+
named `admin` or `engineer` and only uses temporary credentials leveraging AWS's Security Token Service (STS).
141+
Below is an example config generated from this tool. Additional profiles will be similarly added and reference the
142+
base profile.
143+
144+
```ini
145+
[profile corp-new]
146+
source_profile=corp-id-base
147+
mfa_serial=arn:aws:iam::123456789012:mfa/alice
148+
role_arn=arn:aws:iam::123456789012:role/engineer
149+
region=us-west-2
150+
output=json
151+
```
152+
153+
**NOTE:** If you supply an aws-profile name that already exists in '~/.aws/config` this script will rewrite
154+
that profile in your config.
155+
156+
### setup-new-aws-user version
157+
158+
To get the version of the tool run:
159+
160+
```sh
161+
setup-new-aws-user version
162+
```
163+
164+
In development mode you may see the word `development` returned. Otherwise you should see the version of the tool
165+
as it was built by the release pipeline.
166+
91167
## Development setup
92168
93169
1. First, install these packages: `brew install pre-commit direnv go`
@@ -119,7 +195,7 @@ use the real AWS account ID.
119195
Example:
120196
121197
```shell
122-
go run ./cmd setup --iam-role engineer --iam-user testuser --aws-profile test-profile-name --aws-account-id 123456789012
198+
go run ./cmd setup --iam-role engineer --iam-user testuser --aws-profile-account test-profile-name:123456789012
123199
```
124200
125201
After running the script, try a command to ensure the new profile works as

0 commit comments

Comments
 (0)