Linux Bastion Hosts on AWS

Partner Solution Deployment Guide

QS

December 2022
Santiago Cardenas, AWS Serverless Partners
Tony Vattathil, Ian Hill, and Troy Lindsay, AWS Integration & Automation team

Refer to the GitHub repository to view source files, report bugs, submit feature ideas, and post feedback about this Partner Solution. To comment on the documentation, refer to Feedback.

This Partner Solution was created by Amazon Web Services (AWS). Partner Solutions are automated reference deployments that help people deploy popular technologies on AWS according to AWS best practices. If you’re unfamiliar with AWS Partner Solutions, refer to the AWS Partner Solution General Information Guide.

Overview

This Partner Solution deploys Linux bastion hosts on the AWS Cloud. This guide covers the steps necessary to deploy this Partner Solution.

Costs and licenses

There is no cost to use this Partner Solution, but you will be billed for any AWS services or resources that this Partner Solution deploys. For more information, refer to the AWS Partner Solution General Information Guide.

Architecture

Deploying this Partner Solution with default parameters builds the following Linux Bastion Hosts environment in the AWS Cloud.

The bastion host no longer has a public IP address assigned for remote access by default. You can connect to your Linux instance using Session Manager, a capability of AWS Systems Manager. If a remote-access CIDR block is configured for the deployment, an Elastic IP address is assigned, and inbound SSH (Secure Shell) access is permitted.
Architecture
Figure 1. Partner Solution architecture for Linux Bastion Hosts on AWS

As shown in Figure 1, this Partner Solution sets up the following:

  • A highly available architecture that spans two Availability Zones.*

  • A virtual private cloud (VPC) configured with public and private subnets, according to AWS best practices, to provide you with your own virtual network on AWS.*

  • In the public subnets:

    • Managed network address translation (NAT) gateways to allow outbound internet access for resources in the private subnets.*

    • 1–4 Linux bastion hosts in an Amazon Elastic Compute Cloud (Amazon EC2) Auto Scaling group for connecting to Amazon EC2 instances and other resources deployed in public and private subnets.**

  • An Amazon CloudWatch log group to hold the Linux bastion host shell history logs.

  • AWS Systems Manager for access to the bastion host.

* The template that deploys this Partner Solution into an existing VPC skips the components marked by asterisks and prompts you for your existing VPC configuration.
** On-demand, spot, and combinations thereof are supported.

Deployment options

This Partner Solution provides the following deployment options:

This Partner Solution provides separate templates for these options. It also lets you configure Classless Inter-Domain Routing (CIDR) blocks, instance types, and Linux Bastion Hosts settings.

Predeployment steps

(Optional) Create a key pair

If you want to access your Linux bastion host using SSH, you must create a key pair. If you only want to access your bastion host using AWS Systems Manager Session Manager, a key pair is not required. For details, refer to Amazon EC2 key pairs and Linux instances and Create a key pair using Amazon EC2.

(Optional) Customize the Linux bastion host banner

This Partner Solution provides a banner for the Linux bastion hosts, as illustrated in Figure 2.

To enable the banner, you set the Bastion banner parameter to true during deployment. The banner is disabled by default. We recommend that you enable it during deployment to notify users that all their actions will be monitored and recorded.

To customize the banner, create an ASCII text file with your own banner content. Then upload the file to an S3 bucket or other publicly accessible location, and verify that it is accessible from the host.

Deployment steps

  1. Sign in to your AWS account, and launch this Partner Solution, as described under Deployment options. The AWS CloudFormation console opens with a prepopulated template.

  2. Choose the correct AWS Region, and then choose Next.

  3. On the Create stack page, keep the default setting for the template URL, and then choose Next.

  4. On the Specify stack details page, change the stack name if needed. Review the parameters for the template. Provide values for the parameters that require input. For all other parameters, review the default settings and customize them as necessary. When you finish reviewing and customizing the parameters, choose Next.

    Unless you’re customizing the Partner Solution templates or are instructed otherwise in this guide’s Predeployment section, don’t change the default settings for the following parameters: QSS3BucketName, QSS3BucketRegion, and QSS3KeyPrefix. Changing the values of these parameters will modify code references that point to the Amazon Simple Storage Service (Amazon S3) bucket name and key prefix. For more information, refer to the AWS Partner Solutions Contributor’s Guide.
  5. On the Configure stack options page, you can specify tags (key-value pairs) for resources in your stack and set advanced options. When you finish, choose Next.

  6. On the Review page, review and confirm the template settings. Under Capabilities, select all of the check boxes to acknowledge that the template creates AWS Identity and Access Management (IAM) resources that might require the ability to automatically expand macros.

  7. Choose Create stack. The stack takes about 5 minutes to deploy.

  8. Monitor the stack’s status, and when the status is CREATE_COMPLETE, the Linux Bastion Hosts deployment is ready.

  9. To view the created resources, choose the Outputs tab.

Postdeployment steps

Confirm that you can log in to the bastion host

Log in to the bastion host. Use one of the following user names, depending on your choice of Linux distribution:

  • Amazon Linux / SUSE Linux Enterprise Server (SLES): ec2-user

  • CentOS: centos

  • Ubuntu: ubuntu

The Linux distribution is specified in the Bastion AMI operating system parameter when you deploy the templates.

Additional information

Bastion logging

The bastion hosts deployed by this Partner Solution provide a command logger in the /var/log/audit/audit.log file. This log file contains the date, SSH client connection IP address, user name, working directory, and the commands issued.

For added security, the contents of the /var/log/audit/audit.log file is also stored in a CloudWatch Logs log group in the AWS Cloud and remains available in case the bastion hosts fail.

The log includes a history of the commands that are run when you log in. Figure 3 shows an example.

Logging
Figure 3. Bastion logging

The bastion.log file is an immutable file that cannot be easily deleted or tampered with. However, in case this happens, there is a shadow file with a copy of bastion.log located in /var/log/audit/audit.log. The Partner Solution also stores the contents of bastion.log remotely using the CloudWatch Logs service. Log files can be found under CloudWatch Logs using the instance ID as the log stream name.

Remote access

This Partner Solution provisions one Linux bastion host in each Availability Zone with a single security group as a virtual firewall. This security group is required for remote access from the Internet if a remote access CIDR block was configured for the deployment. The security group is configured as follows:

Inbound

Source Protocol Ports

Remote access CIDR

TCP

22

Remote access CIDR

ICMP

N/A

Outbound

Destination Protocol Ports

0.0.0.0/0

All

All

For more information, refer to Internetwork traffic privacy in Amazon VPC.

Troubleshooting

For troubleshooting common Partner Solution issues, refer to the AWS Partner Solution General Information Guide and Troubleshooting CloudFormation.

I encountered a CREATE_FAILED error when I launched the Partner Solution

If AWS CloudFormation fails to create the stack, relaunch the template with Rollback on failure set to Disabled. This setting is under Advanced in the AWS CloudFormation console on the Configure stack options page. With this setting, the stack’s state is retained, and you can troubleshoot the issue.

When you set Rollback on failure to Disabled, you continue to incur AWS charges for this stack. Ensure that you delete stack after troubleshooting.

For more information, refer to Troubleshooting CloudFormation.

I encountered a size-limitation error when I deployed the AWS CloudFormation templates

Launch the Partner Solution templates from the links in this guide or from another S3 bucket. If you deploy the templates from a local copy on your computer or from a location other than an S3 bucket, you might encounter template-size limitations. For more information, refer to AWS CloudFormation quotas.

I changed the instance type parameter after deployment and updated the stack, but the instance types did not change or the Elastic IP addresses were not reassociated after the stack update

Terminate your bastion host instances. They will be replaced by Auto Scaling. A bootstrap action is performed on the new instances to configure security settings and CloudWatch logs and associate Elastic IP addresses.

Resources

Customer responsibility

After you deploy a Partner Solution, confirm that your resources and services are updated and configured—including any required patches—to meet your security and other needs. For more information, refer to the Shared Responsibility Model.

Feedback

To submit feature ideas and report bugs, use the Issues section of the GitHub repository for this Partner Solution. To submit code, refer to the Partner Solution Contributor’s Guide. To submit feedback on this deployment guide, use the following GitHub links:

Notices

This document is provided for informational purposes only. It represents current AWS product offerings and practices as of the date of issue of this document, which are subject to change without notice. Customers are responsible for making their own independent assessment of the information in this document and any use of AWS products or services, each of which is provided "as is" without warranty of any kind, whether expressed or implied. This document does not create any warranties, representations, contractual commitments, conditions, or assurances from AWS, its affiliates, suppliers, or licensors. The responsibilities and liabilities of AWS to its customers are controlled by AWS agreements, and this document is not part of, nor does it modify, any agreement between AWS and its customers.

The software included with this paper is licensed under the Apache License, version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at https://aws.amazon.com/apache2.0/ or in the accompanying "license" file. This code is distributed on an "as is" basis, without warranties or conditions of any kind, either expressed or implied. Refer to the License for specific language governing permissions and limitations.