Skip to content

Commit f94aebe

Browse files
committed
Add tutorial to access S3 by assuming role with MFA requirement.
1 parent 6a2cd64 commit f94aebe

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

protocols/s3/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ You might be interested in scripts maintained by third parties to facilitate man
231231

232232
- [Utilities for easy management of AWS MFA and role sessions and virtual MFA devices](https://github.com/vwal/awscli-mfa)
233233

234+
:::{admonition} Tutorial
235+
:class: tip
236+
237+
Follow the [step-by-step instructions](../../tutorials/s3_iam_role_mfa.md) to require MFA by assuming a role to access S3.
238+
:::
239+
234240
#### AWS IAM Identity Center
235241

236242
For a SSO connection authenticating with AWS IAM Identity Center (Successor to AWS Single Sign-On), the properties
130 KB
Loading

tutorials/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Tutorials
66
:titlesonly:
77
hidden_properties
88
custom_oauth_client_id
9+
s3_iam_role_mfa
910
iam
1011
vault_localdisk
1112
sftp_publickeyauth

tutorials/s3_iam_role_mfa.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
Configure a user in AWS IAM that is required to use MFA to connect to S3
2+
====
3+
4+
> You want an IAM user who cannot directly access S3, but instead must assume a role (with MFA required) to access S3 buckets in the same AWS account. Create a configuration for AWS CLI that is supported in Cyberduck and Mountain Duck using the [S3 (Credentials from AWS Command Line Interface) connection profile](../protocols/s3/index.md#connecting-using-credentials-from-aws-command-line-interface).
5+
6+
### Create a user with both access keys and a MFA device configured
7+
8+
1. In AWS [IAM console](https://console.aws.amazon.com/iam/) create a new user. Do *not* grant this user any permissions for S3.
9+
2. In the _Security credentials_ tab, choose _Create access key_. Copy the Access Key ID and Secret Access Key to a profile in `~/.aws/credentials`
10+
11+
```
12+
[<S3_USER>]
13+
aws_access_key_id=AKIA…
14+
aws_secret_access_key=…
15+
```
16+
17+
3. Assign a MFA device to the user in _Multi-factor authentication (MFA)_. Reference the MFA ARN as the value for the `mfa_serial` parameter in the `<S3-ROLE-NAME>` profile in `~/.aws/credentials`.
18+
19+
:::{tip}
20+
To allow entering the code in Cyberduck or Mountain Duck when connecting, make sure to choose _Authenticator app_ or _Hardware TOTP token_ as a MFA device. Using Passkey MFA does not allow getting a numeric MFA code.
21+
:::
22+
23+
4. Copy the MFA ARN and reference it in `mfa_serial` in the `<S3-ROLE-NAME>` profile in `~/.aws/credentials`
24+
25+
```
26+
[<S3-ROLE-NAME>]
27+
source_profile=<S3_USER>
28+
role_arn=arn:aws:iam::<Account ID>:role/<S3-ROLE-NAME>
29+
mfa_serial=arn:aws:iam::<Account ID>:mfa/<MFA-DEVICE-NAME>
30+
```
31+
32+
### Create IAM role allowing access to S3 enforcing the MFA requirement
33+
34+
1. In AWS [IAM console](https://console.aws.amazon.com/iam/) create a new IAM role that has S3 permissions and requires MFA. The IAM role must have the trusted entity set to the previously created user's ARN.
35+
36+
```
37+
{
38+
"Version": "2012-10-17",
39+
"Statement": [
40+
{
41+
"Effect": "Allow",
42+
"Principal": {
43+
"AWS": "arn:aws:iam::<ACCOUNT_ID>:user/<S3_USER>"
44+
},
45+
"Action": "sts:AssumeRole",
46+
"Condition": {
47+
"Bool": { "aws:MultiFactorAuthPresent": "true" }
48+
}
49+
}
50+
]
51+
}
52+
```
53+
54+
2. Copy the Role ARN and reference it in `role_arn` in the `<S3-ROLE-NAME>` profile in `~/.aws/credentials`
55+
```
56+
[<S3-ROLE-NAME>]
57+
source_profile=<S3_USER>
58+
role_arn=arn:aws:iam::<Account ID>:role/<S3-ROLE-NAME>
59+
mfa_serial=arn:aws:iam::<Account ID>:mfa/<MFA-DEVICE-NAME>
60+
```
61+
This will require the user to enter a MFA code when assuming a role with a S3 access policy attached when connecting.
62+
63+
3. Attach a permission policy to the role that grants access to S3, such as:
64+
65+
```
66+
{
67+
"Version": "2012-10-17",
68+
"Statement": [
69+
{
70+
"Effect": "Allow",
71+
"Action": [
72+
"s3:*"
73+
],
74+
"Resource": "*"
75+
}
76+
]
77+
}
78+
```
79+
80+
Restrict the permissions as necessary.
81+
82+
### Add inline policy to allow the user to assume the role with `sts:AssumeRole`
83+
84+
1. Navigate to the previously added IAM user to attach the `sts:AssumeRole` permission as an inline policy.
85+
2. Add a permission policy for the user by choosing _Add permissions → Create inline policy_ in the _Permissions_ tab. In the policy editor opened, add the action `sts:AssumeRole` for the resource ARN referencing the IAM role `<S3-ROLE-NAME>` created previously allowing access to S3 with MFA.
86+
87+
```
88+
{
89+
"Version": "2012-10-17",
90+
"Statement": [
91+
{
92+
"Effect": "Allow",
93+
"Action": "sts:AssumeRole",
94+
"Resource": "arn:aws:iam::<Account ID>:role/S3-ROLE-NAME"
95+
}
96+
]
97+
}
98+
```
99+
100+
101+
### Create a bookmark in Cyberduck or Mountain Duck
102+
103+
1. Add a new [Bookmark](../cyberduck/bookmarks.md) in Cyberduck or Mountain Duck.
104+
2. Choose *S3 (Credentials from AWS Command Line Interface) profile* in the protocol dropdown. If the [connection profile](../protocols/profiles/index.md) is not available, enable it by choosing _More Options…_.
105+
3. Enter the alias <S3-ROLE-NAME> for the role configuration from your AWS CLI configuration in _Server_.
106+
4. When connecting enter the MFA code from your device when prompted.
107+
108+
:::{image} _images/S3_MFA_Prompt.png
109+
:alt: MFA Prompt
110+
:width: 400px
111+
:::
112+
113+
114+
## References
115+

0 commit comments

Comments
 (0)