How to Build a Near‑Impenetrable Host Security & Audit System on AWS
This guide explains how to replace traditional bastion hosts with AWS Systems Manager Session Manager and CloudWatch Agent, detailing IAM role setup, session logging, and log collection to achieve key‑less, port‑free access, fine‑grained permissions, and centralized, tamper‑proof audit logs for EC2 instances.
Introduction: The “last mile” challenge of host security
In operations and security, firewalls, WAF, DDoS protection form the first line, but the host itself is the decisive “last mile”. Compliance standards like PCI‑DSS and ISO 27001 require controlled access, traceable actions, and non‑loss of logs.
Traditional approaches and their drawbacks
Typical solutions rely on bastion hosts and third‑party agents, which add complexity, cost, and introduce a single point of failure.
Native AWS solution: SSM + CloudWatch
Using AWS Systems Manager (SSM) together with Amazon CloudWatch provides a native, elegant way to build a robust host security and audit system.
Key tool 1: AWS Systems Manager Session Manager
Session Manager eliminates the need for SSH keys and open ports. It works for both Linux and Windows EC2 instances.
How it solves core problems
No public exposure All access goes through an encrypted SSM channel, allowing instances to reside in private subnets and reducing attack surface.
Fine‑grained permission control Combined with IAM, you can specify who can start a session, which instances they can access, and under which OS user (e.g., ssm-user ) the commands run.
Complete session audit Every input and output of a session is recorded and automatically sent to Amazon S3 or CloudWatch Logs, providing undeniable evidence of administrator actions.
Key tool 2: Amazon CloudWatch Agent
While Session Manager audits command execution, CloudWatch Agent collects system, security, and application logs.
Features
Log centralization Collects logs from specified files (e.g., /var/log/secure , /var/log/messages on Linux or Windows Event Logs) and forwards them.
Near‑real‑time transmission Logs are pushed to CloudWatch Logs almost instantly, making tampering difficult.
Unified analysis platform CloudWatch Logs Insights enables powerful queries, alerts, and you can stream logs to S3 or Amazon OpenSearch for deeper analysis.
Practical walkthrough: Three steps to a secure, auditable EC2 instance
Step 1 – Create an IAM role with required policies
Open the AWS IAM console and create a new role.
Select “AWS service” as the trusted entity and choose “EC2”.
Attach the managed policies AmazonSSMManagedInstanceCore (for SSM Agent) and CloudWatchAgentServerPolicy (for CloudWatch Agent).
Name the role, e.g., EC2-SSM-CloudWatch-Role, and create it.
Step 2 – Configure Session Manager session logging
Open the AWS Systems Manager console.
Navigate to “Session Manager” → “Preferences”.
Enable logging and choose a CloudWatch Log Group (or an S3 bucket). Best practice is to enable both for real‑time analysis and long‑term immutable storage.
Step 3 – Deploy and start CloudWatch Agent
Launch the EC2 instance with the IAM instance profile created above; ensure the SSM Agent is running.
Create a CloudWatch Agent configuration and store it in Parameter Store under a name such as AmazonCloudWatch-Linux-Config. The JSON should specify collection of /var/log/secure and the target log group /ec2/security/secure-logs.
Install the agent on the instance via Session Manager: sudo yum install -y amazon-cloudwatch-agent Start the agent using the stored configuration :
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c ssm:AmazonCloudWatch-Linux-ConfigConclusion
By following these three steps you obtain:
Key‑less, port‑free secure access
Immutable, complete command audit logs
Centralized collection of system security logs
The solution relies almost entirely on native AWS services, reducing operational complexity and cost while leveraging AWS’s built‑in reliability and security. It addresses the initial challenges of privileged access, auditability, and log integrity for any critical workloads running on AWS.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development & AI Practice
DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
