Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set password to the ssh service on the fly (not in the Dockerfile) #681

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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