Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stop Whitelisting Port 22: SSH into Private EC2 from GitHub Actions via AWS SSM ๐Ÿ”

๐Ÿ˜ฉ The part of CI/CD nobody enjoys You want a GitHub Actions job to rsync a build onto an EC2 box and restart a service. Simple, right? Then reality shows up: ๐Ÿ”‘ The key. You generate an SSH key pair, paste the private half into secrets.SSH_PRIVATE_KEY , and append the public half to ~/.ssh/authorized_keys on the instance. That key now lives forever. It never rotates. Anyone who can read repoโ€ฆ

GitHub Actions jobs often need to transfer build artifacts to EC2 instances for further processing. Traditionally, this involves generating an SSH key pair, storing the private key as a secret and the public key in the instance's authorized_keys file. This approach has several drawbacks: the key never rotates, anyone who can access the secret can access the production instance, and the port 22 must be opened to allow inbound connections.

A more secure solution is provided by AWS Systems Manager Session Manager (SSM). Session Manager allows SSH into EC2 instances without the need to open port 22 or manage keys. The SSM Agent running on the instance establishes an outbound HTTPS connection to AWS, creating a secure session that can be used to open a direct, encrypted tunnel for SSH. This approach eliminates the need for inbound security group rules, public IPs, bastion hosts, and key rotation.

The provided GitHub Action, ankurk91/setup-ssh-over-ssm-action, simplifies the process of setting up SSH via SSM. It automatically generates a short-lived SSH key, pushes it to the instance using EC2 Instance Connect, configures SSH to use SSM for the session, and cleans up after itself. All that's required is the instance ID, the user to log in as, and the AWS credentials with the necessary permissions.

The action handles generating and managing the SSH key, so there's no need to maintain any secrets or keys in your workflow.

Written by urgent.news from Dev.to's reporting โ€” not their text. Machine-written โ€” may contain errors; check the original before relying on it.

Read the original at dev.to โ†’

More in Tech

Java Concurrency & Multithreading: 40 Interview Questions

1. Process vs Thread A process has its own memory space and OS resources; threads live inside a process and share its heap and file handles but keep their own stack and program counter.

  • Threads share process memory but have separate stacks and program counters.
  • Java provides platform threads (expensive) and lightweight virtual threads (Project Loom).
  • Java Memory Model ensures visibility guarantees for shared state between threads.

Your daily reminder needs three states, not a boolean

I built a checklist that opens itself at 8 am. The hard part wasn't opening it. It was working out when to stop. The version that fails The obvious model is a boolean.

  • The author builds a checklist app opening at 8 am.
  • Initially uses boolean flag to track window state.
  • Introduces third state for answered but not closed windows.

More from Sunday 20 September โ†’