Overview
The Bastion Host Module provides secure, SSH-key-free access to Amazon EKS clusters deployed in private subnets. By leveraging AWS Systems Manager (SSM) Session Manager, this module eliminates the need for traditional bastion hosts with SSH access, providing a more secure and auditable solution for cluster administration.Key Features
- SSH-Free Access: Connect to your EKS cluster without managing SSH keys or opening inbound ports
- SSM Session Manager: Use AWS Systems Manager for secure, logged, and auditable access
- Private Subnet Deployment: Bastion host runs in private subnets with no direct internet access
- Pre-configured Tools: Automatically installs kubectl, AWS CLI, and other essential tools
- EKS Integration: Full permissions for cluster management using eksctl and kubectl
- Encrypted Storage: EBS volumes encrypted at rest for enhanced security
Use Cases
- EKS Cluster Administration: Manage Kubernetes workloads and configurations
- Troubleshooting: Debug applications running in private EKS clusters
- Database Management: Access RDS instances in private subnets
- Secure Operations: Perform operational tasks without exposing infrastructure to the internet
Architecture Components
Core Resources
1. EC2 Instance (Bastion Host)
The bastion host is a lightweight EC2 instance (default:t3.micro) running Amazon Linux 2023. It serves as a secure jump host for accessing resources in private subnets.
Key Characteristics:
- Deployed in private subnet (no public IP)
- Encrypted EBS root volume (GP3)
- Pre-installed with kubectl, AWS CLI, and git
- Configured for SSM Session Manager access
- Automatic tool installation via user data script
2. Security Group
The security group controls network traffic to and from the bastion host, following the principle of least privilege. Egress Rules (Outbound Traffic):
Security Features:
- No inbound rules (access via SSM only)
- Restricted egress to specific AWS services
- VPC endpoint integration for S3 and other services
- Optional GitHub access for development environments
Production Security: The default configuration includes broad S3 access for development convenience. For production deployments, restrict S3 access to specific buckets containing required binaries and tools.
3. IAM Role and Policies
The IAM role provides the bastion host with necessary permissions while maintaining least-privilege access. Attached Managed Policies:AmazonSSMManagedInstanceCore- Enables SSM Session Manager access
- Cluster read operations (DescribeCluster, ListClusters)
- Kubernetes API access (AccessKubernetesApi)
- Node group and addon management
- eksctl operations support
- Create/delete IAM roles and policies
- Manage OIDC providers for service accounts
- Attach/detach role policies
- Tag management
- Stack creation and management (required by eksctl)
- Stack resource inspection
- Template operations
- Read secrets from namespaced paths
- Support for application configuration retrieval
- Download kubectl binary from specified S3 bucket
- Optional: Development access to all S3 buckets
- Decrypt S3 objects and Secrets Manager values
- Conditional based on KMS key ARN configuration
4. SSM Session Manager Integration
AWS Systems Manager Session Manager provides secure, auditable access to the bastion host without requiring SSH keys or open inbound ports. Benefits:- No SSH Keys: Eliminates key management overhead and security risks
- Audit Logging: All session activity logged to CloudWatch Logs
- IAM-Based Access: Uses AWS IAM for authentication and authorization
- No Inbound Ports: No need to open port 22 or manage security groups for SSH
- Session Recording: Optional session recording for compliance requirements
scripts/connect-bastion.sh can also be used to connect to the bastion server. This is the preferred method.
5. User Data Script
The user data script automatically configures the bastion host on first boot. Installation Tasks:- System updates via yum/dnf
- SSM Agent verification and installation
- kubectl binary installation from S3 bucket
- AWS CLI v2 installation
- Git installation (development environments)
- Helper script creation for EKS configuration
Configuration Variables
Required Variables
Optional Variables
Module Usage
Basic Deployment
Production Deployment with kubectl from S3
Development Environment
Module Outputs
The module provides the following outputs for integration with other resources:Connecting to the Bastion Host
Prerequisites
- AWS CLI: Install and configure AWS CLI v2
- Session Manager Plugin: Install the Session Manager plugin
- IAM Permissions: Ensure your IAM user/role has
ssm:StartSessionpermission
Connect via SSM
Port Forwarding to RDS
Security Best Practices
1. Network Isolation
- Private Subnet Deployment: Always deploy bastion hosts in private subnets
- VPC Endpoints: Use VPC endpoints for AWS services to avoid NAT gateway traffic
- Security Group Restrictions: Limit egress to only required destinations
2. IAM Access Control
3. Session Logging and Monitoring
Enable CloudWatch Logs for session activity:4. Automated Compliance Checks
Monitor bastion host compliance:Troubleshooting
Common Issues
1. Unable to Connect via SSM
Symptoms:TargetNotConnected error when starting session
Solutions:
2. kubectl Not Installed
Symptoms:kubectl: command not found
Solutions:
3. EKS API Access Denied
Symptoms:error: You must be logged in to the server (Unauthorized)
Solutions:
4. Cannot Access RDS
Symptoms: Connection timeout to database Solutions:Operational Tasks
Installing Additional Tools
Creating EKS Service Accounts
Related Modules
- EKS Module - Amazon Elastic Kubernetes Service configuration
- VPC Module - Virtual Private Cloud and networking setup
- RDS Module - Relational Database Service configuration
- IAM Module - Identity and Access Management roles and policies
- Monitoring Module - CloudWatch monitoring and alerting
Module Maintenance: This module is actively maintained and tested with Terraform 1.0+ and AWS Provider 5.x. For questions or issues, contact the infrastructure team or refer to the internal Terraform documentation.