Github Action connect to a vps over ssh via cloudflare tunnel

112 views Asked by At

In brief. I have a vps that is only accessible by connecting through the Cloudflared tunnel. On local I have cloudflare installed and configured the .ssh/config something like this

Host XXXXX HostName XXXXX User user IdentityFile path/a/privateKey ProxyCommand C:\cloudflared.exe access ssh --hostname %h

And it works correctly. But in github action it doesn't. What I want to do is that when a push is done, it connects to the vps, does a pull, and launches the docker that has the project. I understand that this is possible, isn't it?

This is my .yml

name: Cloudflared Tunnel

on:
  push:
    branches:
      - main  # Cambia esto segĂșn la rama que desees monitorizar

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: install cloudflared
      run: |
        curl -L https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-archive-keyring.gpg >/dev/null
        echo "deb [signed-by=/usr/share/keyrings/cloudflare-archive-keyring.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
        sudo apt update
        sudo apt-get install cloudflared

    - name: Configure SSH key
      run: |
        echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/id_rsa
        chmod 600 ~/id_rsa

    - name: SSH into VPS using Cloudflared Tunnel
      run: |
        ssh -i ~/id_rsa -o ProxyCommand="cloudflared access ssh --hostname ${{ secrets.VPS_HOST }}" ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} "echo 'Connected via Cloudflared Tunnel'"

The error I get from github action in the logs.

Run ssh -i ~/id_rsa -o ProxyCommand="cloudflared access ssh --hostname ***" ***@*** "echo 'Connected via Cloudflared Tunnel'"
  ssh -i ~/id_rsa -o ProxyCommand="cloudflared access ssh --hostname ***" ***@*** "echo 'Connected via Cloudflared Tunnel'"
  shell: /usr/bin/bash -e {0}
  
Host key verification failed.
Error: Process completed with exit code 255.

I tried to connect to my vps via cloudflared tunnel and it doesn't work. I have also tried different actions already created and it doesn't work either. I hope to be able to connect and execute commands inside the vps.

0

There are 0 answers