Skip to content

Commit

Permalink
set password to the ssh service on the fly (not in the Dockerfile) (#681
Browse files Browse the repository at this point in the history
)

* set password to the ssh service on the fly (not in the Dockerfile)
  • Loading branch information
shadeofblue authored Sep 27, 2021
1 parent 9b83c8a commit a101b56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions examples/ssh/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion examples/ssh/ssh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python3
import asyncio
import pathlib
import random
import sys
import string
from uuid import uuid4


Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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()

Expand Down

0 comments on commit a101b56

Please sign in to comment.