Skip to content

Commit

Permalink
Added support to enable a ssh-server.
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <[email protected]>
  • Loading branch information
Jack12816 committed Aug 19, 2024
1 parent 42314bb commit 9756b4b
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 5 deletions.
3 changes: 2 additions & 1 deletion 4.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ENV MDNS_HOSTNAME=neo4j.local
# Install system packages
RUN apt-get update -yqqq && \
apt-get install -y \
dbus avahi-daemon avahi-utils libnss-mdns haproxy supervisor
dbus avahi-daemon avahi-utils libnss-mdns haproxy supervisor \
openssh-server

# Copy custom scripts
COPY config/*.sh /usr/local/bin/
Expand Down
2 changes: 1 addition & 1 deletion 4.4/config/avahi.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

NSS_MDNS=$(dpkg -s libnss-mdns | grep Version: \
| cut -d: -f2 | cut -d- -f1 | tr -d ' ')
Expand Down
41 changes: 41 additions & 0 deletions 4.4/config/sshd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# We allow to start an SSH server inside the container to enable the
# programmatically access to neo4j tooling. This is disabled by default.
export SSHD_ENABLE=${SSHD_ENABLE:-'false'}
export SSHD_CUSTOM_CONIFG=${SSHD_CUSTOM_CONIFG:-'false'}
export SSHD_ROOT_PASSWORD=${SSHD_ROOT_PASSWORD:-'root'}

# When this feature is disabled, we just do nothing. Forever.
if [ "${SSHD_ENABLE}" != 'true' ]; then
tail -f /dev/null
exit $?
fi

# Prepare the environment for dbus
mkdir -p /run/sshd
chmod 0755 /run/sshd

# We allow our users to supply a custom sshd config,
# so we do not overwrite their file contents
if [ "${SSHD_CUSTOM_CONIFG}" = 'false' ]; then
cat >/etc/ssh/sshd_config <<'EOF'
UsePAM no
PermitRootLogin yes
PasswordAuthentication yes
ChallengeResponseAuthentication no
PermitEmptyPasswords yes
MaxAuthTries 20
StrictModes no
EOF
fi

# Preserve the current environment variables for ssh sessions
env | grep -P '(.+_|PATH)' | sed 's/^/export /g' >> /etc/environment
echo 'source /etc/environment' >> /root/.bashrc

# Change the root password to the configured one
echo "root:${SSHD_ROOT_PASSWORD}" | chpasswd

# Start the ssh daemon
exec /usr/sbin/sshd -D -e
14 changes: 14 additions & 0 deletions 4.4/config/supervisor/sshd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:sshd]
priority=10
startretries=20
directory=/tmp
command=/usr/local/bin/sshd.sh
user=root
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopsignal=KILL
stopwaitsecs=1
3 changes: 2 additions & 1 deletion 5.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ENV MDNS_HOSTNAME=neo4j.local
# Install system packages
RUN apt-get update -yqqq && \
apt-get install -y \
dbus avahi-daemon avahi-utils libnss-mdns haproxy supervisor
dbus avahi-daemon avahi-utils libnss-mdns haproxy supervisor \
openssh-server

# Copy custom scripts
COPY config/*.sh /usr/local/bin/
Expand Down
2 changes: 1 addition & 1 deletion 5.3/config/avahi.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

NSS_MDNS=$(dpkg -s libnss-mdns | grep Version: \
| cut -d: -f2 | cut -d- -f1 | tr -d ' ')
Expand Down
41 changes: 41 additions & 0 deletions 5.3/config/sshd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# We allow to start an SSH server inside the container to enable the
# programmatically access to neo4j tooling. This is disabled by default.
export SSHD_ENABLE=${SSHD_ENABLE:-'false'}
export SSHD_CUSTOM_CONIFG=${SSHD_CUSTOM_CONIFG:-'false'}
export SSHD_ROOT_PASSWORD=${SSHD_ROOT_PASSWORD:-'root'}

# When this feature is disabled, we just do nothing. Forever.
if [ "${SSHD_ENABLE}" != 'true' ]; then
tail -f /dev/null
exit $?
fi

# Prepare the environment for dbus
mkdir -p /run/sshd
chmod 0755 /run/sshd

# We allow our users to supply a custom sshd config,
# so we do not overwrite their file contents
if [ "${SSHD_CUSTOM_CONIFG}" = 'false' ]; then
cat >/etc/ssh/sshd_config <<'EOF'
UsePAM no
PermitRootLogin yes
PasswordAuthentication yes
ChallengeResponseAuthentication no
PermitEmptyPasswords yes
MaxAuthTries 20
StrictModes no
EOF
fi

# Preserve the current environment variables for ssh sessions
env | grep -P '(.+_|PATH)' | sed 's/^/export /g' >> /etc/environment
echo 'source /etc/environment' >> /root/.bashrc

# Change the root password to the configured one
echo "root:${SSHD_ROOT_PASSWORD}" | chpasswd

# Start the ssh daemon
exec /usr/sbin/sshd -D -e
14 changes: 14 additions & 0 deletions 5.3/config/supervisor/sshd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:sshd]
priority=10
startretries=20
directory=/tmp
command=/usr/local/bin/sshd.sh
user=root
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopsignal=KILL
stopwaitsecs=1
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ neo4j:
environment:
# Mind the .local suffix
- MDNS_HOSTNAME=neo4j.test.local
# We allow to start an SSH server inside the container to enable the
# programmatically access to neo4j tooling. This is disabled by default.
- SSHD_ENABLE=false
- SSHD_ROOT_PASSWORD=root
- SSHD_CUSTOM_CONIFG=false
ports:
# The ports are just for you to know when configure your
# container links, on depended containers
Expand Down
2 changes: 1 addition & 1 deletion config/avahi.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

NSS_MDNS=$(dpkg -s libnss-mdns | grep Version: \
| cut -d: -f2 | cut -d- -f1 | tr -d ' ')
Expand Down
41 changes: 41 additions & 0 deletions config/sshd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# We allow to start an SSH server inside the container to enable the
# programmatically access to neo4j tooling. This is disabled by default.
export SSHD_ENABLE=${SSHD_ENABLE:-'false'}
export SSHD_CUSTOM_CONIFG=${SSHD_CUSTOM_CONIFG:-'false'}
export SSHD_ROOT_PASSWORD=${SSHD_ROOT_PASSWORD:-'root'}

# When this feature is disabled, we just do nothing. Forever.
if [ "${SSHD_ENABLE}" != 'true' ]; then
tail -f /dev/null
exit $?
fi

# Prepare the environment for dbus
mkdir -p /run/sshd
chmod 0755 /run/sshd

# We allow our users to supply a custom sshd config,
# so we do not overwrite their file contents
if [ "${SSHD_CUSTOM_CONIFG}" = 'false' ]; then
cat >/etc/ssh/sshd_config <<'EOF'
UsePAM no
PermitRootLogin yes
PasswordAuthentication yes
ChallengeResponseAuthentication no
PermitEmptyPasswords yes
MaxAuthTries 20
StrictModes no
EOF
fi

# Preserve the current environment variables for ssh sessions
env | grep -P '(.+_|PATH)' | sed 's/^/export /g' >> /etc/environment
echo 'source /etc/environment' >> /root/.bashrc

# Change the root password to the configured one
echo "root:${SSHD_ROOT_PASSWORD}" | chpasswd

# Start the ssh daemon
exec /usr/sbin/sshd -D -e
14 changes: 14 additions & 0 deletions config/supervisor/sshd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:sshd]
priority=10
startretries=20
directory=/tmp
command=/usr/local/bin/sshd.sh
user=root
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopsignal=KILL
stopwaitsecs=1

0 comments on commit 9756b4b

Please sign in to comment.