You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: LICENSE
-1
Original file line number
Diff line number
Diff line change
@@ -7,4 +7,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
7
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
9
9
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* On first start all IAM users are imported and local users are created
12
-
* The import also runs every 10 minutes (via cron - calls import_users.sh)
13
-
* You can control which users are given sudo access as:
11
+
* On first start, all IAM users are imported and local UNIX users are created
12
+
* The import also runs every 10 minutes (via cron - calls `import_users.sh`)
13
+
* You can control which IAM users get a local UNIX user and are therefore able to login
14
+
* all (default)
15
+
* only those in specific IAM groups
16
+
* You can control which IAM users are given sudo access
14
17
* none (default)
15
18
* all
16
-
* only those in a specific IAM group.
17
-
* On every SSH login the EC2 instance tries to fetch the public key(s) from IAM using sshd's `AuthorizedKeysCommand`
18
-
* You can restrict that the EC2 instance is only allowed to download public keys from certain IAM users instead of `*`. This way you can restrict SSH access within your account
19
+
* only those in a specific IAM group
20
+
* You can specify the local UNIX groups for the local UNIX users
21
+
* You can assume a role before contacting AWS IAM to get users and keys (e.g. if your IAM users are in another AWS account)
22
+
* On every SSH login, the EC2 instance tries to fetch the public key(s) from IAM using sshd's `AuthorizedKeysCommand`
19
23
* As soon as the public SSH key is deleted from the IAM user a login is no longer possible
20
24
21
-
##How to run this showcase (CloudFormation)
25
+
### Demo with CloudFormation
22
26
23
27
1. Upload your public SSH key to IAM:
24
28
1. Open the Users section in the [IAM Management Console](https://console.aws.amazon.com/iam/home#users)
25
29
1. Click the row with your user
26
-
1. Click the "Upload SSH public key" button at the bottom of the page
27
-
1. Paste your public SSH key into the textarea and click the "Upload SSH public key" button to save
28
-
1. Create a stack based on the `showcase.yaml` template
30
+
1. Select the **Security Credentials** tab
31
+
1. Click the **Upload SSH public key** button at the bottom of the page
32
+
1. Paste your public SSH key into the text-area and click the **Upload SSH public key** button to save
33
+
1. Create a CloudFormation stack based on the `showcase.yaml` template
29
34
1. Wait until the stack status is `CREATE_COMPLETE`
30
35
1. Copy the `PublicName` from the stack's outputs
31
-
1. Connect via ssh `ssh $Username@$PublicName`replace`$Username`with your IAM user and `$PublicName` with the stack's output
36
+
1. Connect to the EC2 instance via `ssh $Username@$PublicName`with`$Username`being your IAM user, and `$PublicName` with the stack's output
32
37
33
-
## How to integrate this system into your environment (non-CloudFormation)
38
+
## How to integrate this system into your environment
34
39
35
-
1. Upload your public SSH key to IAM as above
36
-
1. Make sure any instances you want to ssh into contain the correct IAM permissions
37
-
(usually based on IAM Profile, but also possibly based on an IAM user and their credentials).
38
-
Look at the `iam_ssh_policy.json` for an example policy that will permit login.
39
-
1. Make sure those instances automatically run a script similar to `install.sh` (note - that script assumes `git` is installed _and_ instances have access to the Internet; feel free to modify it to instead install from a tarball or using any other mechanism such as Chef or Puppet).
40
-
* If you want to control sudo access, you should modify the value of ‘SudoersGroup’ in import_users.sh
41
-
1. Connect to your instances now using `ssh $Username@$PublicName` with `$Username` being your IAM user, and `$PublicName` being your server's name or IP address.
42
-
43
-
## Limitations
44
-
45
-
* your EC2 instances need access to the AWS API either via an Internet Gateway + public IP or a Nat Gatetway / instance.
46
-
* it can take up to 10 minutes until a new IAM user can log in
47
-
* if you delete the IAM user / ssh public key and the user is already logged in, the SSH session will not be closed
48
-
* uid's and gid's across multiple servers might not line up correctly (due to when a server was booted, and what users existed at that time). Could affect NFS mounts or Amazon EFS.
49
-
* this solution will work for ~100 IAM users and ~100 EC2 instances. If your setup is much larger (e.g. 10 times more users or 10 times more EC2 instances) you may run into two issues:
50
-
* IAM API limitations
51
-
* Disk space issues
52
-
* not all IAM user names are allowed in Linux user names. See section [IAM user names and Linux user names](#iam-user-names-and-linux-user-names) for further details.
40
+
1. Upload your public SSH key to IAM:
41
+
1. Open the Users section in the [IAM Management Console](https://console.aws.amazon.com/iam/home#users)
42
+
1. Click the row with your user
43
+
1. Select the **Security Credentials** tab
44
+
1. Click the **Upload SSH public key** button at the bottom of the page
45
+
1. Paste your public SSH key into the text-area and click the **Upload SSH public key** button to save
46
+
1. Attach the IAM permissions defined in `iam_ssh_policy.json` to the EC2 instances (by creating an IAM role and an Instance Profile)
47
+
1. Run the `install.sh` script as `root` on the EC2 instances
48
+
1. Connect to your EC2 instances now using `ssh $Username@$PublicName` with `$Username` being your IAM user, and `$PublicName` being your server's name or IP address
53
49
54
-
###IAM user names and Linux user names
50
+
## IAM user names and Linux user names
55
51
56
52
Allowed characters for IAM user names are:
57
53
> alphanumeric, including the following common characters: plus (+), equal (=), comma (,), period (.), at (@), underscore (_), and hyphen (-).
@@ -69,3 +65,44 @@ This solution will use the following mapping for those special characters when c
69
65
*`@` => `.at.`
70
66
71
67
So instead of `[email protected]` you will need to use `name.at.email.com` when login via SSH.
68
+
69
+
## Using a multi account strategy with a central IAM user account
70
+
71
+
If you are using multiple AWS accounts you probably have one AWS account with all the IAM users (I will call it **users account**), and separate AWS accounts for your environments (I will call it **dev account**). Support for this is provided using the AssumeRole functionality in AWS.
72
+
73
+
### Setup users account
74
+
75
+
1. In the **users account**, create a new IAM role
76
+
1. Select Role Type **Role for Cross-Account Access** and select the option **Provide access between AWS accounts you own**
77
+
1. Put the **users account** number in **Account ID** and leave **Require MFA** unchecked
78
+
1. Skip attaching a policy (we will do this soon)
79
+
1. Review the new role and create it
80
+
1. Select the newly created role
81
+
1. In the **Permissions** tab, expand **Inline Policies** and create a new inline policy
82
+
1. Select **Custom Policy**
83
+
1. Paste the content of the `iam_ssh_policy.json` file and replace `<YOUR_USERS_ACCOUNT_ID_HERE>` with the AWS Account ID of the **users account**.
84
+
85
+
### Setup dev account
86
+
87
+
For your EC2 instances, you need a IAM role that allows the `sts:AssumeRole` action
88
+
89
+
1. In the **dev account**, create a new IAM role
90
+
1. Select ROle Type **AWS Service Roles** and select the option **Amazon EC2**
91
+
1. Skip attaching a policy (we will do this soon)
92
+
1. Review the new role and create it
93
+
1. Select the newly created role
94
+
1. In the **Permissions** tab, expand **Inline Policies** and create a new inline policy
95
+
1. Select **Custom Policy**
96
+
1. Paste the content of the `iam_crossaccount_policy.json` file and replace `<YOUR_USERS_ACCOUNT_ID_HERE>` with the AWS Account ID of the **users account** and `<YOUR_USERS_ACCOUNT_ROLE_NAME_HERE>` with the IAM rol name that you created in the **users account**
97
+
1. Replace the `ASSUMEROLE` placeholder with the ARN of the IAM role in `import_users.sh` and `authorized_keys_command.sh`
98
+
99
+
## Limitations
100
+
101
+
* your EC2 instances need access to the AWS API either via an Internet Gateway + public IP or a Nat Gatetway / instance.
102
+
* it can take up to 10 minutes until a new IAM user can log in
103
+
* if you delete the IAM user / ssh public key and the user is already logged in, the SSH session will not be closed
104
+
* uid's and gid's across multiple servers might not line up correctly (due to when a server was booted, and what users existed at that time). Could affect NFS mounts or Amazon EFS.
105
+
* this solution will work for ~100 IAM users and ~100 EC2 instances. If your setup is much larger (e.g. 10 times more users or 10 times more EC2 instances) you may run into two issues:
106
+
* IAM API limitations
107
+
* Disk space issues
108
+
* not all IAM user names are allowed in Linux user names. See section [IAM user names and Linux user names](#iam-user-names-and-linux-user-names) for further details.
0 commit comments