Skip to content

Harden EC2 deploy workflow by granting ephemeral runner SSH ingress - #2

Merged
sanket-rajput merged 2 commits into
mainfrom
copilot/fix-deploy-production-ec2-job
Aug 25, 2026
Merged

sanket-rajput merged 2 commits into
mainfrom
copilot/fix-deploy-production-ec2-job

Conversation

Copilot AI commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

The Deploy to Production EC2 job was failing before deployment with an SSH timeout (dial tcp ...:22: i/o timeout). This change updates CD to open EC2 SSH access only for the active GitHub Actions runner, then remove it after deployment.

  • Root-cause aligned workflow change

    • Added AWS auth setup in .github/workflows/deploy.yml (aws-actions/configure-aws-credentials@v4).
    • Added pre-deploy step to detect runner public IP and authorize tcp/22 ingress for runner_ip/32 on the target security group.
    • Handles idempotency (InvalidPermission.Duplicate) to avoid failing on repeated runs.
  • Post-deploy security cleanup

    • Added always() cleanup step to revoke the temporary ingress rule.
    • Handles missing-rule cleanup safely (InvalidPermission.NotFound).
  • Operational robustness

    • Increased SSH action connection/command timeouts to better tolerate transient network delays during deploy.
  • Deployment docs alignment

    • Updated deploy/README.md to document CI/CD SSH behavior and required repo secrets:
      • AWS_ACCESS_KEY_ID
      • AWS_SECRET_ACCESS_KEY
      • AWS_REGION
      • EC2_SECURITY_GROUP_ID
- name: Allow GitHub Actions runner SSH access
  run: |
    RUNNER_IP="$(curl -fsSL https://checkip.amazonaws.com | tr -d '\n')"
    aws ec2 authorize-security-group-ingress \
      --group-id "$EC2_SECURITY_GROUP_ID" \
      --protocol tcp --port 22 --cidr "${RUNNER_IP}/32"

Co-authored-by: sanket-rajput <100849898+sanket-rajput@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job Deploy to Production EC2 Harden EC2 deploy workflow by granting ephemeral runner SSH ingress Aug 25, 2026
Copilot AI requested a review from sanket-rajput August 25, 2026 16:06
@sanket-rajput
sanket-rajput marked this pull request as ready for review August 25, 2026 16:11
@sanket-rajput
sanket-rajput merged commit 07fb7da into main Aug 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants