How SSM Session Manager connects you

Your IAM role is the key, and the instance connects out to AWS. Nothing connects in to the instance. The instance has no public IP, no open port 22, and no inbound security group rule. Use the steps under the diagram to follow one session.

Summary

Laptop, AWS Region services, and a private EC2 instance. All connections go from the laptop or the instance to AWS. AWS REGION (AWS-MANAGED) YOUR VPC · PRIVATE SUBNET Security group inbound: none Your laptop aws ssm start-session session-manager-plugin Credentials: temporary keys for your IAM role IAM Is ssm:StartSession allowed? Systems Manager API ssm.<region>.amazonaws.com Session Manager relay ssmmessages.<region>… Joins two WebSockets CloudTrail · S3 · CloudWatch Records who started each session NAT gateway or VPC endpoints EC2 instance No public IP SSM Agent Runs as root Opens all connections outbound, HTTPS 443 Shell user: ssm-user Instance role AmazonSSMManaged InstanceCore HTTPS WebSocket register control data

Each arrow points away from the side that opens the connection. Arrows go from your laptop to AWS and from the instance to AWS. No arrow goes in to the instance.

Why you need no key or password

SSH checks who you are on the instance. Session Manager checks who you are in IAM, before the instance does anything.

After IAM approves you, the agent starts the shell. The agent already runs as root, so the OS does not ask for a password. Your access is only as wide as your IAM policy.

What must be true

  • The SSM Agent runs on the instance. Many Amazon AMIs include it.
  • The instance role has AmazonSSMManagedInstanceCore.
  • The instance can reach ssm, ssmmessages and ec2messages on port 443, through a NAT gateway or VPC interface endpoints.
  • Your role allows ssm:StartSession on the instance.
  • Your laptop has the AWS CLI and the session-manager-plugin.

A minimal policy for you

{
  "Effect": "Allow",
  "Action": "ssm:StartSession",
  "Resource": [
    "arn:aws:ec2:*:*:instance/i-0abc123",
    "arn:aws:ssm:*:*:document/SSM-SessionManagerRunShell"
  ]
},
{
  "Effect": "Allow",
  "Action": "ssm:TerminateSession",
  "Resource": "arn:aws:ssm:*:*:session/${aws:userid}-*"
}

Other uses of the same tunnel

Port forwarding. AWS-StartPortForwardingSession sends a local port to a port on the instance. You can use it to reach a database, with no bastion host.

SSH over SSM. AWS-StartSSHSession carries SSH through the relay. Here SSM only carries the bytes, so SSH still needs a key.