Amazon holiday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

Connecting GitHub Actions Runners to a Private Network

Integrating GitHub Actions runners with a private network allows your CI/CD workflows to securely access internal resources, databases, or services that are not exposed to the public internet. This setup is essential for maintaining security, ensuring data privacy, and enabling seamless automation of tasks that require internal network access. Whether you’re deploying internal applications, testing against private environments, or automating infrastructure tasks, connecting your runners to a private network enhances your automation capabilities. Before starting, ensure you have administrative access to your GitHub repository, a private network environment (like a VPN, SSH tunnel, or private cloud), and the necessary credentials or keys to establish a secure connection.

What You’ll Need

  • GitHub repository with GitHub Actions enabled
  • Self-hosted runner or GitHub-hosted runner (preferably self-hosted for direct network access)
  • Access to your private network (VPN, SSH, or similar)
  • Appropriate credentials or keys for network access (e.g., SSH keys, VPN credentials)
  • Optional: Docker or other containerization tools if deploying within containers

Step-by-Step

  1. Set Up a Self-Hosted Runner
    First, decide whether to use a self-hosted runner or an existing GitHub-hosted runner. For secure private network access, self-hosted runners are recommended because they can be configured directly within your network environment. Follow GitHub’s documentation to install and register a self-hosted runner in your repository or organization.
  2. Configure Network Access on the Runner Host
    Ensure the machine where the runner is hosted can access your private network. This might involve installing a VPN client, configuring SSH tunnels, or setting up network routes. For example, if you’re using a VPN, install and connect the VPN client on the host machine.
  3. Establish Secure Connectivity
    Depending on your private network setup, establish a persistent secure connection. For VPNs, connect the VPN before starting the runner. For SSH tunnels, create a reverse or local port forwarding that allows the runner to connect to internal resources.
  4. Test Network Connectivity
    Verify that the runner host can reach internal resources. Use ping, curl, or SSH to confirm access. For example, run ping internal-service.local or ssh user@internal-server to ensure connectivity.
  5. Configure Your Workflow to Use the Runner
    In your GitHub Actions workflow, specify the runner label that matches your self-hosted runner. This ensures your jobs run on the machine with access to the private network.
  6. Add Network Access Commands in Your Workflow
    Within your workflow, include steps to initialize the secure connection if needed, such as starting a VPN or establishing an SSH tunnel. For example:
     - name: Connect to VPN   run: sudo openvpn --config myconfig.ovpn

    or

     - name: Create SSH Tunnel   run: ssh -N -L 8080:internal-service.local:80 user@jump-host
  7. Run Your Jobs
    Now, execute your workflow. Your jobs should be able to access private network resources through the established connection. Use commands like curl, ssh, or access internal databases/services as needed.
  8. Maintain and Secure the Connection
    Ensure your network connections are secure and monitored. Use encrypted tunnels, rotate keys regularly, and restrict access to only necessary resources.

Common Mistakes

  • Not establishing the secure connection before running jobs – ensure your VPN or SSH tunnel is active before workflow execution.
  • Using a GitHub-hosted runner without network access – GitHub-hosted runners run in a cloud environment without direct access to private networks.
  • Failing to test connectivity thoroughly before automating – always verify network access manually before integrating into workflows.
  • Neglecting security best practices – avoid hardcoding credentials, use secrets management, and restrict network access.
  • Misconfiguring firewall or network rules – ensure your network allows inbound connections from the runner host.

Tips

  • Use SSH keys with passphrases and store them securely in GitHub Secrets.
  • Automate VPN connection setup in your workflow for seamless operation.
  • Leverage Docker containers if needed to isolate network configurations.
  • Maintain a clear separation between public and private network access points.
  • Document your network setup for team transparency and future troubleshooting.

Troubleshooting

If your runner cannot access private network resources, follow these steps:

  • Check connectivity manually: Log into the runner host and test access to internal resources with ping, curl, or SSH.
  • Verify the secure connection: Ensure your VPN or SSH tunnel is active and correctly configured. Restart the connection if necessary.
  • Review network/firewall rules: Confirm that the network allows inbound connections from your runner host on required ports.
  • Inspect runner logs: Look for errors related to network connectivity, authentication, or tunnel establishment.
  • Test with alternative tools: Use manual commands to confirm the network path before automating within workflows.
  • Consult network administrators: If issues persist, get help from your network team to diagnose routing or security policies.

Frequently Asked Questions

  • Can I connect a GitHub-hosted runner directly to my private network?
    No, GitHub-hosted runners run in cloud environments without direct access to private networks. Use self-hosted runners for this purpose.
  • What is the best way to secure the connection?
    Use encrypted tunnels like VPNs or SSH, store credentials securely in GitHub Secrets, and restrict access to only necessary resources.
  • Can I automate VPN connection setup in my workflows?
    Yes, include commands to start VPN clients within your workflow steps, ensuring secure connectivity during job execution.
  • What are the risks of connecting to a private network from CI/CD pipelines?
    Potential security vulnerabilities include credential leaks, unauthorized access, and network exposure. Follow best practices to mitigate these risks.
  • How do I ensure my private network remains secure while allowing CI/CD access?
    Use strict access controls, encrypted tunnels, rotate keys regularly, and monitor network activity for suspicious behavior.
  • Is it possible to connect multiple runners to the same private network?
    Yes, but ensure each runner has secure and isolated access, and manage network policies to prevent unauthorized cross-access.

This comprehensive guide aims to help you securely connect your GitHub Actions runners to your private network, enabling seamless and safe automation workflows tailored to your internal infrastructure. Proper setup, security, and maintenance are key to successful integration.

Connecting GitHub Actions Runners to a Private Network
Scroll to top