Lesson 3 of 6 Compute Security: EC2, Containers and Lambda

Administering Instances Without Open Ports

This lesson explains how to administer instances with no inbound ports, using AWS services that control every session through IAM and log it, instead of open SSH or RDP ports, shared keys and bastion hosts.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how Session Manager provides access without inbound ports.
  • Describe how EC2 Instance Connect replaces long-lived SSH keys.
  • Explain how standing access is removed and open administrative ports detected.
  • Restrict Session Manager access by tag and log every session.

Session Manager

Traditional administrative access to instances uses SSH or RDP, which requires inbound ports, bastion hosts and key or password management, each of which can be attacked or mishandled. AWS Systems Manager Session Manager replaces these. The SSM Agent on the instance opens an outbound connection to Systems Manager, and administrators start sessions through the console, the CLI or the SDK, authenticated and authorised by IAM. Every session can be logged for audit. The following list describes its principal features.

  • Shell access and port forwarding through the SSM Agent's outbound HTTPS connection: no inbound ports, bastions or SSH keys.
  • Controlled by IAM, for example only instances with a given tag.
  • Sessions logged to S3 and CloudWatch Logs, KMS-encrypted; session starts recorded in CloudTrail.
  • Private subnets need interface endpoints for ssm, ssmmessages and ec2messages, or NAT.

The following diagram shows the access path for database administrators who use Session Manager, and where session output goes.

Database administrator access through Session Manager. The IAM policy allows ssm:StartSession only on instances tagged team=dba and lets users end only their own sessions; sessions are KMS-encrypted and their output goes to an encrypted CloudWatch Logs group and S3 bucket. Port 22 stays closed everywhere.
The scenario is illustrative.
True or false

Session Manager

Exam skills 3.2.5

Check how Session Manager provides administrative access.

Log in to try this activity Interactive activities are free with an account.

EC2 Instance Connect

EC2 Instance Connect replaces long-lived SSH keys with access controlled by IAM. When an authorised user connects, EC2 Instance Connect pushes a one-time SSH public key to the instance metadata, valid for 60 seconds, so there are no permanent keys to distribute or revoke, and every connection is authorised by IAM and logged in CloudTrail. It still requires network access to the instance's SSH port. An EC2 Instance Connect Endpoint removes that requirement: it provides SSH or RDP access to instances in private subnets, with no public IP addresses and no bastion hosts. The following table summarises the two options.

OptionHow it works
EC2 Instance ConnectPushes a one-time SSH public key valid for 60 seconds, controlled by IAM
EC2 Instance Connect EndpointSSH or RDP to instances in private subnets without public IPs or bastions

60s

Validity of the one-time SSH key pushed by EC2 Instance Connect

Scenario questions

Choosing the access method

Exam skills 3.2.5

Choose the administrative access method for each requirement.

Log in to try this activity Interactive activities are free with an account.

Removing standing access

With Session Manager or Instance Connect Endpoint in place, security groups can close ports 22 and 3389 entirely, and an AWS Config rule or Security Hub control flags any group that reopens them. Access can be time-limited further by granting the IAM permission only through a temporary elevated-access workflow.

Select all that apply

No standing access

Exam skills 3.2.5

Pick the steps that remove standing administrative access.

Log in to try this activity Interactive activities are free with an account.
Worked example

Session Manager access limited by tag and fully logged

Database administrators may open sessions only on instances tagged team=dba, and every keystroke must be recorded. The IAM policy restricts ssm:StartSession by resource tag and lets users terminate only their own sessions:

{
  "Version": "2012-10-17",
  "Statement": [
    { "Effect": "Allow", "Action": "ssm:StartSession",
      "Resource": "arn:aws:ec2:*:111111111111:instance/*",
      "Condition": { "StringEquals": { "ssm:resourceTag/team": "dba" } } },
    { "Effect": "Allow", "Action": "ssm:StartSession",
      "Resource": "arn:aws:ssm:*::document/AWS-StartInteractiveCommand" },
    { "Effect": "Allow", "Action": ["ssm:TerminateSession", "ssm:ResumeSession"],
      "Resource": "arn:aws:ssm:*:111111111111:session/${aws:userid}-*" }
  ]
}

Session Manager preferences send session output to an encrypted CloudWatch Logs group and S3 bucket and encrypt the session itself with a KMS key. Port 22 is closed in every security group, and an AWS Config rule flags any group that reopens it.

Check yourself

Session Manager fails for instances in a private subnet. What is usually missing?

Show answer

The Systems Manager VPC endpoints.

Exam Tips

Remember for the exam

  • To close port 22 but keep audited shell access, use Session Manager.
  • To SSH to private instances without a bastion, use EC2 Instance Connect Endpoint.
  • If Session Manager fails in a private subnet, add the SSM VPC endpoints.
  • To record every administrative command, log Session Manager sessions to S3 or CloudWatch.
  • Restrict Session Manager access with IAM conditions on instance tags.