Sub topic 8
How Session Manager works and why it needs no inbound port
This chapter assumes you know the basics of EC2 instances, security groups, and IAM roles. It also assumes the AWS CLI is configured with credentials. The earlier chapters covered SSH, where you connect to the instance. Session Manager reverses that direction.
What Session Manager is
Session Manager is a feature of AWS Systems Manager. It gives you a shell on an instance, or a forwarded port, without SSH. You authenticate with IAM instead of a key pair, so there is no .pem file to distribute or rotate.
Three parts take part in every session:
- SSM Agent is a program that runs on the instance. Recent Amazon Linux, Ubuntu, and Windows AMIs from AWS include it.
- The Systems Manager service is a regional AWS service. It authorizes you and relays traffic.
- Your client is the AWS CLI with the Session Manager plugin, or the AWS console.
Why no inbound port is needed
With SSH, your machine opens a connection to port 22 on the instance. The instance must be reachable and its security group must allow the traffic in.
With Session Manager, the instance makes the connection. SSM Agent opens an outbound HTTPS connection (port 443) to Systems Manager endpoints and keeps it open. It also polls the service for work. Your client connects to the same service, not to the instance. The service joins the two connections and passes data between them.
The security group needs no inbound rules. The instance needs no public IP address. A private subnet works if the instance can reach the endpoints through a NAT gateway or through VPC endpoints.
What happens when you start a session
Consider this command:
aws ssm start-session --target i-0123456789abcdef0- The CLI calls the
StartSessionAPI, signed with your IAM credentials. - Systems Manager checks that your identity may run
ssm:StartSessionon that instance. - Systems Manager tells the agent, over its open channel, to start a session.
- The service returns a stream URL and a one-time token to your client.
- The Session Manager plugin opens a TLS WebSocket to that URL. The agent starts a shell, and the service relays data in both directions.
On Linux the shell runs as ssm-user, a local account the agent creates. It is not ec2-user. That account has no password and no key.
What you get in return
| Concern | SSH | Session Manager |
|---|---|---|
| Inbound port | 22 must be open | None |
| Credential | Key pair | IAM identity |
| Who may connect | Anyone holding the key | Whoever IAM permits |
| Audit trail | Server logs you manage | CloudTrail records every `StartSession` |
| Public IP needed | Usually | No |
Session Manager can also record the session content. That is covered in a later chapter.
Common misunderstandings
- "No inbound port means no network needed." The instance needs outbound access on 443. If it has none, the agent cannot register and the instance never appears as managed.
- "The agent needs my IAM permissions." It does not. The instance profile grants the agent its own permissions. Your IAM identity decides who may start a session.
- "It replaces SSH completely." It does not. You can run SSH over a session, which a later chapter shows.
Exercise
An instance in a private subnet has a security group with no inbound rules at all. Session Manager works on it. Which direction does the connection to the Systems Manager service go from the instance, and why does the empty inbound rule set not matter?
Show answer
The instance's SSM Agent opens the connection outbound over HTTPS (port 443) to Systems Manager. Security groups are stateful, so replies on that connection are allowed back in. Your client also connects to the service, never directly to the instance, so no inbound rule is needed.