Skip to content

Restrict AWS SSM connection to ec2 instance from VPN servers.

0

I have an ec2 instance currently setup using aws ssm. Right now the connection is allowed from anywhere. I have to access ec2 instance using aws ssm via openvpn (server). I have created an inline policy attached to that ec2 server allowing vpn server ips and vpc end point also created. but as of now issue is without vpn also still am able to access server with aws ssm..

Policies attached:

  1. AmazonSSMManagedInstanceCore

  2. Restrict-SSM-VPN_Server (inline policy) { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ssm:StartSession", "ssm:ResumeSession" ], "Resource": [ "arn:aws:ec2:REGION:ACCOUNT_ID:instance/INSTANCE_ID" ], "Condition": { "IpAddress": { "aws:SourceIp": [ "VPN_IP_1/32", // Elastic ip of vpn server set here. "VPN_IP_2/32", "VPN_IP_3/32" ] } } }, { "Effect": "Allow", "Action": "ssm:TerminateSession", "Resource": [ "arn:aws:ssm:::session/${aws:userid}-*" ] } ] }

1 Answer
0
Accepted Answer

Attach the AmazonSSMManagedInstanceCore policy to the EC2

Attach the other policy to a user/group. you dont attach it to the EC2

What policy do you have assigned to your user? If your an administrator you will ALWAYS have access to the EC2. You will need to have a Deny instead applied to ALL users :-

I think this will only work too if you have the SSM VPC PrivateEndpoint and Private DNS Enabled along with your VPN pointing to the Route53 VPC resolver IP

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Action": [
                "ssm:StartSession",
                "ssm:ResumeSession"
            ],
            "Resource": [
                "arn:aws:ec2:REGION:ACCOUNT_ID:instance/INSTANCE_ID"
            ],
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": [
                        "VPN_IP_1/32",
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "ssm:TerminateSession",
            "Resource": [
                "arn:aws:ssm:::session/${aws:userid}-*"
            ]
        }
    ]
}
EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.