From 8f83c971c8cc7ba67ada9bba03c96c637a16a788 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Fri, 24 Sep 2021 15:23:24 +0200 Subject: [PATCH 1/2] set password to the ssh service on the fly (not in the Dockerfile) --- examples/ssh/Dockerfile | 3 --- examples/ssh/ssh.py | 9 ++++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/ssh/Dockerfile b/examples/ssh/Dockerfile index fc4f76481..035f77396 100644 --- a/examples/ssh/Dockerfile +++ b/examples/ssh/Dockerfile @@ -4,6 +4,3 @@ RUN apk add --no-cache --update bash openssh iproute2 tcpdump net-tools screen RUN echo "UseDNS no" >> /etc/ssh/sshd_config && \ echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \ echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config - -# set the password to some known value so that we can test the successful SSH connection later -RUN echo -e "pass.123\npass.123" | passwd diff --git a/examples/ssh/ssh.py b/examples/ssh/ssh.py index ad823b212..85fe540f9 100755 --- a/examples/ssh/ssh.py +++ b/examples/ssh/ssh.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 import asyncio import pathlib +import random import sys +import string from uuid import uuid4 @@ -32,7 +34,7 @@ class SshService(Service): @staticmethod async def get_payload(): return await vm.repo( - image_hash="ea233c6774b1621207a48e10b46e3e1f944d881911f499f5cbac546a", + image_hash="1e06505997e8bd1b9e1a00bd10d255fc6a390905e4d6840a22a79902", min_mem_gib=0.5, min_storage_gib=2.0, # we're adding an additional constraint to only select those nodes that @@ -44,9 +46,12 @@ async def run(self): connection_uri = self.network_node.get_websocket_uri(22) app_key = self.cluster._engine._api_config.app_key + password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) + script = self._ctx.new_script() script.run("/bin/bash", "-c", "syslogd") script.run("/bin/bash", "-c", "ssh-keygen -A") + script.run("/bin/bash", "-c", f"echo -e \"{password}\n{password}\" | passwd") script.run("/bin/bash", "-c", "/usr/sbin/sshd") yield script @@ -57,6 +62,8 @@ async def run(self): f"{TEXT_COLOR_DEFAULT}" ) + print(f"{TEXT_COLOR_RED}password: {password}{TEXT_COLOR_DEFAULT}") + # await indefinitely... await asyncio.Future() From c92d1a508b62ae420a268690cbe1a7458e84d443 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Sat, 25 Sep 2021 05:54:42 +0200 Subject: [PATCH 2/2] black --- examples/ssh/ssh.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ssh/ssh.py b/examples/ssh/ssh.py index 85fe540f9..b9c7b9fda 100755 --- a/examples/ssh/ssh.py +++ b/examples/ssh/ssh.py @@ -46,12 +46,12 @@ async def run(self): connection_uri = self.network_node.get_websocket_uri(22) app_key = self.cluster._engine._api_config.app_key - password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) + password = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) script = self._ctx.new_script() script.run("/bin/bash", "-c", "syslogd") script.run("/bin/bash", "-c", "ssh-keygen -A") - script.run("/bin/bash", "-c", f"echo -e \"{password}\n{password}\" | passwd") + script.run("/bin/bash", "-c", f'echo -e "{password}\n{password}" | passwd') script.run("/bin/bash", "-c", "/usr/sbin/sshd") yield script