Skip to content

Commit

Permalink
Add SSH support for root user to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
blechschmidt committed May 31, 2024
1 parent 11a9d5d commit 9f4c8e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ jobs:
- name: Prepare environment
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
run: mkdir -p ~/.ssh && echo "$SSH_KEY" >> ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa && sudo systemctl stop systemd-resolved && sudo bash -c 'rm /etc/resolv.conf; echo "nameserver 1.1.1.1" > /etc/resolv.conf' && sudo iptables -P FORWARD ACCEPT && sudo ip6tables -P FORWARD ACCEPT
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
sudo mkdir -p /root/.ssh
sudo cp ~/.ssh/id_rsa /root/.ssh/id_rsa
sudo chmod 600 /root/.ssh/id_rsa
sudo systemctl stop systemd-resolved
sudo bash -c 'rm /etc/resolv.conf
echo "nameserver 1.1.1.1" > /etc/resolv.conf'
sudo iptables -P FORWARD ACCEPT
sudo ip6tables -P FORWARD ACCEPT
#- name: Setup upterm session
# uses: lhotari/action-upterm@v1
- name: Populate .env
Expand Down
6 changes: 3 additions & 3 deletions pallium/hops/socksapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ def connect(self):
process = self.popen(self.cmd, **kwargs)
self._proc_pid = process.pid
# Wait for the SOCKS listener to appear
self.log_debug('Waiting for SSH socks endpoint to appear at %s.' % str(self._socks_endpoint))
self.log_debug('Waiting for SOCKS endpoint to appear at %s.' % str(self._socks_endpoint))

def ssh_error():
returncode = process.poll()
if returncode is not None and returncode != 0:
# TODO: Include SSH output in exception.
raise ConnectionError('SSH exited with code %d' % returncode)
# TODO: Include command output in exception.
raise ConnectionError('SOCKS app command exited with code %d' % returncode)

if not wait_for_listener(self._socks_endpoint, exception_function=ssh_error):
raise TimeoutError
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def check_connectivity():
pallium.hops.ssh.SshHop(machine.get_ssh_destination(), ssh_args=ssh_args, dns=dns)
]
),
run=config.Run(quiet=True)
run=config.Run()
)
) as session:
result = session.execute(check_connectivity)
Expand Down

0 comments on commit 9f4c8e4

Please sign in to comment.