Skip to content

Harden CD deploy job by adding ephemeral runner-scoped SSH ingress - #3

Draft
sanket-rajput with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-deploy-to-production-ec2
Draft

sanket-rajput with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-deploy-to-production-ec2

Conversation

Copilot AI commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

The Deploy to Production EC2 job was failing before deployment logic executed because the GitHub-hosted runner could not establish SSH to EC2 (port 22 timeout). This change updates the CD workflow to grant runner-scoped SSH access just-in-time and always clean it up after deployment.

  • Root-cause alignment: runner could not reach EC2 over SSH

    • Capture runner public IP at runtime (/32) and use it as the only temporary ingress source.
    • Keep deployment behavior unchanged once SSH connectivity is available.
  • Workflow hardening in .github/workflows/deploy.yml

    • Add pre-deploy ingress authorization step:
      • aws ec2 authorize-security-group-ingress --port 22 --cidr "$RUNNER_IP"
    • Add post-deploy cleanup step with if: always():
      • aws ec2 revoke-security-group-ingress --port 22 --cidr "$RUNNER_IP"
    • Handle idempotent edge cases (InvalidPermission.Duplicate / InvalidPermission.NotFound) without masking real failures.
  • Operational documentation update

    • Update deploy/README.md to document that CD opens SSH only for the active runner IP and revokes it afterward.
- name: Get GitHub Runner Public IP
  run: echo "RUNNER_IP=$(curl -s https://checkip.amazonaws.com)/32" >> "$GITHUB_ENV"

- name: Authorize temporary SSH access for GitHub Runner
  run: aws ec2 authorize-security-group-ingress --group-id "$EC2_SECURITY_GROUP_ID" --protocol tcp --port 22 --cidr "$RUNNER_IP"

# ... existing SSH deploy step ...

- name: Revoke temporary SSH access for GitHub Runner
  if: always()
  run: aws ec2 revoke-security-group-ingress --group-id "$EC2_SECURITY_GROUP_ID" --protocol tcp --port 22 --cidr "$RUNNER_IP"

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 CD deploy job by adding ephemeral runner-scoped SSH ingress Aug 25, 2026
Copilot AI requested a review from sanket-rajput August 25, 2026 16:12

This branch has not been deployed

No deployments
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