Skip to content

DEPLOYMENT SECURITY

Keep SSH private for GitHub Actions deployments with WireGuard

Connect GitHub-hosted runners to a dedicated WireGuard peer, restrict SSH at the right firewall and deploy with verified host keys.

14 min readPublished

A GitHub-hosted runner reaches a private SSH server through a WireGuard gateway while direct unapproved SSH is denied.
On this page

Connect your GitHub Actions runner to a dedicated WireGuard peer before it deploys over SSH. Give that peer a route to the deployment server, restrict its access at the firewall, and keep SSH key authentication and host-key verification enabled.

This lets you remove general public access to SSH while continuing to use GitHub-hosted runners. It also gives you a deployment access path that you can review, test and revoke independently of an administrator's VPN access.

This guide covers an Ubuntu runner connecting to an existing WireGuard endpoint and an SSH deployment target. You will need control of the relevant routing and firewall rules. Apply operating-system security updates and any required reboot as part of normal server maintenance: restricting SSH does not repair vulnerable software or protect other exposed services.

Why use a VPN for GitHub Actions deployments?

Standard GitHub-hosted runners do not give your deployment workflow a dedicated, stable source address. GitHub publishes broad runner IP ranges and updates the list weekly. GitHub also advises against using those ranges as allowlists for internal resources. See the GitHub-hosted runner networking reference.

WireGuard provides an authenticated network path from the runner to your deployment network. Your SSH firewall rules can then allow a dedicated peer address or a VPN gateway's egress address, depending on your topology. GitHub documents WireGuard as an option for connecting hosted runners to a private network.

An SSH allowlist reduces who can reach the service and attempt authentication. Its protection depends on covering every route to that service, including public IPv6, alternate addresses and port-forwarding rules. A compromised permitted peer can still reach whatever your rules allow, so keep its access narrow.

1. Choose the deployment network path

The example below uses a separate WireGuard gateway and a deployment server on a private network.

A GitHub-hosted runner connects through WireGuard to a VPN gateway and a private SSH deployment server. The firewall denies direct SSH from unapproved internet sources.

Your firewall rules must match the source address visible at the point where they are enforced.

Deployment topologySource seen by the SSH targetWhere to restrict SSH
Separate gateway with source NATThe gateway's translated egress address, which may be private or publicAllow that source at the target firewall. Restrict the original peer, destination and port on the gateway before translation.
Separate gateway with routing and no source NATThe deployment peer's tunnel addressAllow the peer's individual address on the target path. Configure forwarding and a return route through the gateway.
WireGuard runs on the SSH targetThe peer's tunnel address after decryptionDeny direct public SSH upstream. Allow the peer and SSH port on the target's WireGuard interface.

When WireGuard terminates on the target itself, the provider firewall sees encrypted UDP packets arriving at the VPN endpoint. The inner SSH connection becomes visible after decryption on the host. Consequently, a provider rule alone cannot distinguish the inner deployment peers; the host firewall must enforce that boundary. This follows from WireGuard's encapsulation model.

If several peers share one NAT egress address, the target's source allowlist cannot distinguish them either. Apply their individual access rules on the gateway. If the gateway reaches the target's public address, describe that arrangement as restricted public SSH access. A private target address or SSH on the target's WireGuard address gives you a private destination path.

Check which interfaces and traffic paths your provider firewall covers. Ubuntu's routing guidance and forwarding and source NAT example explain the distinction between routed and translated traffic.

2. Create a dedicated deployment peer

Create a WireGuard peer specifically for this deployment workflow. Give it its own key pair and tunnel address so you can revoke deployment access without affecting administrators or other repositories.

For a separate gateway, a minimal client configuration could look like this:

[Interface]
Address = 10.90.0.2/32
PrivateKey = <deployment-peer-private-key>

[Peer]
PublicKey = <vpn-gateway-public-key>
Endpoint = vpn.example.com:51820
AllowedIPs = 10.20.0.10/32

All addresses, names and keys here are examples. Replace them with your own values and choose address ranges that do not overlap your existing networks. In this example, 10.90.0.2 identifies the runner's peer and 10.20.0.10 is the private SSH target. The endpoint's UDP port must be reachable from the runner.

On the gateway, add the deployment peer's public key and associate it with that client's address:

[Peer]
PublicKey = <deployment-peer-public-key>
AllowedIPs = 10.90.0.2/32

This is a peer entry for an existing gateway configuration, not a complete gateway configuration. The gateway also needs a route to the deployment server, forwarding enabled where required, and either a return route from the server or appropriately scoped source NAT.

The client's AllowedIPs sends only the target's /32 through the tunnel. This is split tunnelling: GitHub traffic and other destinations continue using the runner's ordinary network connection. Keep the VPN endpoint's public address outside that target route. If WireGuard runs on the deployment server itself, use its WireGuard address as the SSH target.

AllowedIPs associates addresses with WireGuard peers, and wg-quick normally derives routes from it. It does not independently enforce access to a particular TCP port. A client holding the private key can change its own configuration. Enforce the permitted destination and SSH port at the gateway or target firewall. See the WireGuard manual, wg-quick manual and Ubuntu's WireGuard security guidance.

3. Restrict SSH without losing administrative access

Start with a working administrative connection and a tested recovery method, such as your provider console or a separate restricted management VPN.

Apply these rules using the firewall system appropriate to your environment:

  • Allow the runner to reach the WireGuard endpoint's UDP port.
  • Allow the deployment peer to reach only the required target and SSH port. For the example, that is 10.20.0.10 on TCP 22.
  • On the target, allow the source address appropriate to your topology. Prefer an individual peer /32 or gateway address over an entire VPN subnet.
  • Deny direct SSH from unapproved public sources, covering IPv4 and IPv6 wherever applicable. Preserve other deliberately exposed services.

Use an upstream provider firewall or security group to reject unapproved public SSH traffic before it reaches the server, and host or gateway rules for the inner VPN traffic. Firewall implementations differ, so verify rule order, default policies and interface coverage rather than copying a generic ruleset over an existing configuration.

Test the VPN route and open a second administrative session before removing your temporary administrative rule. An existing SSH session remaining connected does not prove that a new connection will work.

If you are responding to a kernel vulnerability, follow the vendor's advisory for updates and mitigations. An SSH source restriction does not make a vulnerable TCP stack safe while other affected TCP services remain reachable. A host firewall is itself part of the host's network processing, so do not assume it provides the same boundary as upstream filtering.

4. Prepare the GitHub settings and SSH identity

Create a production GitHub environment before using the workflow. Configure its permitted deployment branches and any approval rules your release policy requires. Merely naming the environment in YAML does not establish those protections. Feature availability depends on your GitHub plan and repository visibility. See managing deployment environments.

Add these values to the deployment environment:

NameStore asValue
WIREGUARD_CONFIG_DEPLOYSecretThe complete dedicated client configuration.
DEPLOY_SSH_PRIVATE_KEYSecretA separate SSH private key for the deployment account.
DEPLOY_SSH_KNOWN_HOSTSSecretThe administrator-verified SSH host-key entry. The public host key is not confidential, but its integrity matters.
DEPLOY_SSH_HOSTVariableThe fixed private IPv4 target, such as 10.20.0.10.
DEPLOY_SSH_PORTVariableThe SSH port. The workflow defaults to 22.
DEPLOY_SSH_USERVariableA restricted deployment account, such as deploy.

Give the deployment account only the permissions its deployment procedure needs. Avoid sharing an administrator's SSH key. This example expects a key that can be used non-interactively; integrate your existing key-unlocking or certificate step if your authentication method requires one.

Verify the server's host key

Obtain the host public key through a trusted administrative connection or server console. For SSH on port 22, the DEPLOY_SSH_KNOWN_HOSTS value has this form:

10.20.0.10 ssh-ed25519 <full-server-public-host-key>

For a non-default port such as 2222:

[10.20.0.10]:2222 ssh-ed25519 <full-server-public-host-key>

Use the key type and full public key supplied by your server. A fingerprint alone is not a valid known_hosts entry. The address or hostname must match what SSH connects to. See the OpenSSH known-hosts format.

Do not fetch a fresh key during every deployment and automatically trust it. ssh-keyscan cannot authenticate the keys it retrieves. Keep the verified entry under controlled change, and investigate unexpected host-key changes.

5. Connect the runner and deploy

The WireGuard SSH action in our truecms/sentinel-actions repository connects the runner, checks that every initially resolved target IPv4 address routes through its WireGuard interface, and requires TCP reachability and a recent handshake before succeeding.

Use an Ubuntu virtual-machine runner, such as ubuntu-24.04, without a job container. The action needs passwordless sudo to configure networking. Do not use ubuntu-slim, which runs in an unprivileged container. GitHub describes these distinctions in its runner reference.

The action accepts four inputs:

InputPurpose
configRequired. Complete WireGuard client configuration from a secret.
target-hostRequired. Deployment IPv4 address or hostname.
target-portTCP port to check. Defaults to 22.
timeout-secondsSetup and connectivity timeout, from 1 to 300 seconds. Defaults to 30. Required-tool installation happens before this timeout starts.

Warning

This example has not been tested end to end against a live WireGuard gateway and SSH target. Verify it on non-production infrastructure before adopting it.

The following complete example is manually triggered and restricted to main. It assumes a reviewed deployment command already exists on the server at /usr/local/bin/deploy-site. Replace that command with your own deployment procedure. When integrating these steps into an automated release pipeline, keep the deployment job dependent on the required tests and release gates.

Save it as .github/workflows/deploy.yml on the repository's default branch. If your deployment branch has another name, adjust the branch condition and environment rules together. Run it from the repository's Actions tab, following GitHub's manual workflow instructions.

name: Deploy over a private WireGuard route

on:
  workflow_dispatch:

permissions: {}

concurrency:
  group: production-deployment-vpn
  cancel-in-progress: false

jobs:
  deploy:
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-24.04
    environment: production
    timeout-minutes: 15
    steps:
      - name: Connect to the deployment VPN
        uses: truecms/sentinel-actions/wireguard-ssh@411865987b0e9fb82fb1ef4246323161a3176472
        with:
          config: ${{ secrets.WIREGUARD_CONFIG_DEPLOY }}
          target-host: ${{ vars.DEPLOY_SSH_HOST }}
          target-port: ${{ vars.DEPLOY_SSH_PORT || '22' }}
          timeout-seconds: '30'

      - name: Deploy with verified SSH
        shell: bash
        env:
          DEPLOY_SSH_HOST: ${{ vars.DEPLOY_SSH_HOST }}
          DEPLOY_SSH_PORT: ${{ vars.DEPLOY_SSH_PORT || '22' }}
          DEPLOY_SSH_USER: ${{ vars.DEPLOY_SSH_USER }}
          DEPLOY_SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
          DEPLOY_SSH_KNOWN_HOSTS: ${{ secrets.DEPLOY_SSH_KNOWN_HOSTS }}
        run: |
          set -euo pipefail
          umask 077
          deploy_ssh_dir="$(mktemp -d "$RUNNER_TEMP/deploy-ssh.XXXXXX")"
          trap 'rm -rf -- "$deploy_ssh_dir"' EXIT

          printf '%s\n' "$DEPLOY_SSH_PRIVATE_KEY" > "$deploy_ssh_dir/key"
          printf '%s\n' "$DEPLOY_SSH_KNOWN_HOSTS" > "$deploy_ssh_dir/known_hosts"

          ssh -4 -F /dev/null \
            -i "$deploy_ssh_dir/key" \
            -o BatchMode=yes \
            -o IdentitiesOnly=yes \
            -o StrictHostKeyChecking=yes \
            -o UserKnownHostsFile="$deploy_ssh_dir/known_hosts" \
            -o GlobalKnownHostsFile=/dev/null \
            -o ConnectTimeout=10 \
            -p "$DEPLOY_SSH_PORT" \
            -l "$DEPLOY_SSH_USER" \
            "$DEPLOY_SSH_HOST" \
            '/usr/local/bin/deploy-site'

The action repository example is maintained alongside this guide.

The action is pinned to a specific merged commit. Review that source before adoption and update the pin deliberately. Follow GitHub's guidance for securing action dependencies.

The SSH step explicitly uses IPv4 to match the action's checks. Strict host-key checking verifies the server against the stored key, while the separate deployment key authenticates the account. BatchMode=yes prevents an interactive authentication prompt. See the OpenSSH client options.

The example calls a command already on the server, so it does not check out repository code or need GitHub token permissions. Add only the permissions and build or artefact steps your actual deployment requires.

Prevent overlapping uses of one peer

WireGuard updates a peer's endpoint when authenticated packets arrive from a new address. Two runners using the same peer key can therefore interfere with each other's connections. Give concurrent jobs separate keys and tunnel addresses, or serialise every use of a shared peer.

The example's concurrency group prevents overlapping runs using that group within the repository. Use the same group for any other workflow sharing that peer. It does not coordinate other repositories. GitHub's default pending-run behaviour can replace an older waiting run, so check concurrency semantics if every queued release must run.

Protect secrets and clean up

Keep VPN and SSH credentials available only to trusted deployment code. Build and test untrusted contributions separately from the job with production access. Do not accept VPN configuration from pull-request content or print it for debugging. GitHub warns that secret redaction is not guaranteed for structured or transformed values.

The action rejects PreUp, PostUp, PreDown, PostDown and SaveConfig. Keep the client configuration minimal. The hook directives are executable shell snippets in wg-quick; this action runs that tool with elevated privileges.

The action registers a post-job step to remove the tunnel and temporary VPN configuration. The shell trap removes the SSH files when the SSH step exits. Neither mechanism guarantees cleanup after abrupt runner loss. Also, ending the job does not revoke the peer registered on the gateway. Remove that peer and rotate the SSH credential if they are exposed or no longer needed. See the action implementation and GitHub's post-job metadata.

6. Verify the allowed path and the blocked path

Test on a non-production target first. Use your deployment procedure's documented no-op mode, or temporarily replace the remote command with true if the account and key have no forced command. Check that server-side restrictions will not turn the connection test into a deployment. OpenSSH's forced-command option can override the command requested by the client.

Verify these outcomes separately:

  1. The route uses WireGuard. On the connected runner, ip -4 route get 10.20.0.10 should name the action's scwg-... interface. The action also checks this before succeeding.
  2. The configured port is reachable. Confirm that the connection action succeeds. This establishes TCP reachability through the checked route, not the identity of the service.
  3. SSH verifies both identities. The SSH step must accept the pinned host key and authenticate the deployment account. Then test the actual deployment and its normal application checks.
  4. Unapproved public access fails. From an independent external source outside the allowlist, test every relevant public SSH address and port, including IPv6 where configured. You should not reach an SSH banner or authentication prompt. Corroborate the result with the applicable firewall rules or logs.
  5. Recovery and cleanup work. Open a new session through the independent administrative path and check the job's post-cleanup result.

Only then remove the temporary public administrative rule. Keep the recovery path documented and restricted.

If the VPN fails later, use the provider console or independent management path to repair it. Where a temporary SSH exception is necessary, limit it to a verified administrator source and remove it after recovery.

Troubleshooting

SymptomWhat to check
WireGuard setup failsCheck the client configuration, endpoint DNS, UDP reachability and runner privileges. Use the Ubuntu VM directly without a job container.
The target is not routed through WireGuardCheck its IPv4 address against AllowedIPs, overlapping networks and route settings. Use the supported split-tunnel configuration.
A handshake succeeds but SSH is unreachableCheck gateway forwarding, target firewall rules, return routing or source NAT, and whether SSH listens on the intended address and port.
A hostname fails or behaves inconsistentlyStart with a fixed private IPv4 address. Every IPv4 address resolved during setup must use the tunnel. SSH can resolve a hostname again later, so the initial check is not continuous route enforcement.
Host-key verification failsCheck the trusted key, target address and [host]:port format. Verify a legitimate key rotation through your administrative channel before changing the stored value.
Deployments disrupt each otherCheck whether concurrent jobs share a peer key or tunnel address. Use separate peers or consistent concurrency control.
Idle NAT mappings expireConsider PersistentKeepalive = 25 when the network needs it. It preserves an idle mapping; it is not an SSH timeout or a universal requirement. See the WireGuard quick start.
Cleanup reports an errorInspect the post-step result. On a persistent runner, confirm the interface and secret files are removed before reuse.

Use targeted diagnostics such as routes, latest-handshake timestamps and transfer counters. Avoid logging the client configuration, wg showconf, or wg show ... dump, which can expose private or preshared keys. The wg manual documents those output formats.

Keep deployment access narrow

Review the deployment peer, firewall rules, SSH account and workflow together. Recheck access after changing addresses, IPv6 settings, gateways or deployment credentials. Remove unused peers and keep the action pin and operating system maintained.

The intended result is straightforward: authorised deployment jobs can reach and authenticate to the required SSH service, unapproved public sources cannot, and administrators retain a tested recovery path.

Frequently asked questions

Can GitHub Actions deploy over SSH without opening SSH to the public?

Yes. A GitHub-hosted runner can connect to a private deployment address through a WireGuard peer, then authenticate with SSH. Restrict the gateway and target firewalls, verify the host key and test that unapproved public IPv4 and IPv6 access fails.

Does WireGuard replace SSH authentication or host-key verification?

No. WireGuard provides an authenticated network path; SSH still needs a restricted deployment identity and a host key verified through a trusted channel.

Can several deployment jobs share one WireGuard peer?

A shared peer can be disrupted when concurrent runners use its key from different endpoints. Give concurrent jobs separate peers, or serialise every use of the shared peer. A GitHub concurrency group does not coordinate across repositories.

Does AllowedIPs restrict the deployment peer to the SSH port?

No. AllowedIPs associates addresses with peers and normally determines routes. Enforce the allowed destination and TCP port with gateway or target firewall rules.

For a broader view of Drupal release monitoring, read how to monitor security updates across many Drupal sites.

More guides

  • Security updates

    Get alerted when a Drupal security release affects your sites

    Drupal security releases land on Wednesday US time, which is Thursday morning in Australia. Learn how release-day alerts reach the right people by email and Slack, and how to choose who gets them.

    5 min readUpdated

  • Security updates

    How to monitor security updates across many Drupal sites

    Compare Update Status, Composer audit, cron scripts, self-hosted dashboards and hosted services for tracking Drupal security updates across a fleet, then connect an eligible SentinelConnector site in three steps.

    14 min readUpdated

  • Security updates

    Drupal update monitoring behind a WAF

    Check Drupal update coverage and freshness behind a WAF, assess temporary controls and verify fixes in production.

    3 min readUpdated

All guides

Put this guide to work

Example: five Drupal sites are checked for updates. Most are up to date, one has two updates and one has a security update, which is then patched.

Monitoring

Track security updates across your Drupal fleet

Connect your sites to see installed versions, available updates and known advisories for each organisation, then set patching targets and share monthly reports.*

Example: by hand, a security update means reading, updating, testing, reviewing, deploying and reporting, done hours later. With Sentinel, the update is read, updated and tested for you, then waits for your review before it is deployed.

Free savings calculator

What do Drupal updates really cost you?

Seven short questions, then a report with your own numbers to share with your team.