New AWS Systems Manager, including Session Manager is another step enhance security on Cloud. Here are step by step how to set up.
NOTE: There is NO need to require to have a Public IP on EC2 instance, and have network inbound rule setup with opened SSH port 22, and VPN connection.
You have ec2-user account on AWS EC2 instance. On localhost:
π ssh -i .ssh/aws-key.pem -l ec2-user ec2-3-121-69-96.ap-southeast-2.compute.amazonaws.com Last login: Fri Nov 22 01:17:33 2019 from 155.144.114.41
__| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___|
https://aws.amazon.com/amazon-linux-2/
NOTE: Need ROOT access key pair ASIANPOWERHOUSEBLAHBLAH above setup in session profile to run aws sts command.
NOTE: IAM role for EC2 instance need to have AmazonSSMManagedInstanceCore policy. So create a customised role CustomAmazonSSMManagedInstanceCore in AWS IAM including AmazonSSMManagedInstanceCore policy, and bind this IAM role with EC2 instance, also with security group and key pair.
Install all the dependencies
latest Systems Manager Agent on your EC2 instance; enabled βAgent auto updateβ under Managed Instances in AWS Systems Manager
Updated above solution and add a DIFFERENT user ssm-user, if SSM throws error βUnable to start shell: failed to start pty since RunAs user ssm-user does not existβ:
Without using scp, transferring files directly is not possible with the AWS Session Manager. You should use S3 bucket and the AWS CLI to exchange data.
Set up integrated OKTA authentication with session. Have you OKTA AWS CLI installed at first, and configure it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
π cat ~/.okta-aws [default] base-url = hello.paradise.org ## The remaining parameters are optional. ## You will be prompted for them, if they're not included here. username = terrence.miao@paradise.org # Current choices are: GOOGLE or OKTA factor = OKTA # AWS role name (match one of the options prompted for by "Please select the AWS role" when this parameter is not specified role = # Found in Okta's configuration for your AWS account. app-link = https://hello.paradise.org/home/amazon_aws/0oa1ch3l6/272 # duration in seconds to request a session token for, make sure your accounts (both AWS itself and the associated okta application) allow for large durations. default: 3600 duration = 28800
π bin/aws-azure-cli/aws-azure-cli --profile session --mode gui Logging in with profile 'session'... Using AWS SAML endpoint https://signin.aws.amazon.com/saml Looking in /Applications/Google Chrome.app/Contents/MacOS/Google Chrome Found browser in /Applications/Google Chrome.app/Contents/MacOS/Google Chrome Please complete the login in the opened window ? Role: arn:aws:iam::994385754915:role/federation/DeveloperPowerUser ? Session Duration Hours (up to 12): 12 Assuming role arn:aws:iam::994385754915:role/federation/DeveloperPowerUser Requesting session duration 43200s Session expires Sun Feb 19 2023 06:46:43 GMT+1100 (Australian Eastern Daylight Time)