Update SSH port from 22 to 2222 in Dockerfile, entrypoint, and Kubernetes configurations
All checks were successful
Build k8s-mgmt-pod image / Build & Push (push) Successful in 1m35s

This commit is contained in:
Michael Trip 2026-06-23 15:48:15 +02:00
parent b715b4bb59
commit 5584dc1f29
9 changed files with 31 additions and 24 deletions

View file

@ -31,7 +31,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
WEB_SSH_PORT=3000 \ WEB_SSH_PORT=3000 \
WEBSSH2_LISTEN_PORT=3001 \ WEBSSH2_LISTEN_PORT=3001 \
WEBSSH2_SSH_HOST=127.0.0.1 \ WEBSSH2_SSH_HOST=127.0.0.1 \
WEBSSH2_SSH_PORT=22 \ WEBSSH2_SSH_PORT=2222 \
SSH_PORT=2222 \
WEBSSH2_HEADER_TEXT=k8s-mgmt-pod \ WEBSSH2_HEADER_TEXT=k8s-mgmt-pod \
WEBSSH2_SSH_HOSTKEY_ENABLED=false WEBSSH2_SSH_HOSTKEY_ENABLED=false
@ -99,9 +100,9 @@ COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod 0755 /usr/local/bin/entrypoint.sh \ RUN chmod 0755 /usr/local/bin/entrypoint.sh \
&& chmod 0644 /etc/profile.d/20-k8s-tools-completion.sh && chmod 0644 /etc/profile.d/20-k8s-tools-completion.sh
EXPOSE 22 3000 EXPOSE 2222 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD nc -z 127.0.0.1 22 || exit 1 CMD nc -z 127.0.0.1 "${SSH_PORT:-2222}" || exit 1
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"] ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"]

View file

@ -7,7 +7,7 @@
- `helm` preinstalled from a pinned upstream binary release - `helm` preinstalled from a pinned upstream binary release
- `k9s` preinstalled from a pinned GitHub release tarball - `k9s` preinstalled from a pinned GitHub release tarball
- `kubectl` and `helm` bash autocompletion enabled for both `admin` and `user` - `kubectl` and `helm` bash autocompletion enabled for both `admin` and `user`
- local `openssh-server` on port `22` - local `openssh-server` on port `2222`
- a browser-based SSH client on port `3000` - a browser-based SSH client on port `3000`
- a custom ASCII-art MOTD on login - a custom ASCII-art MOTD on login
- two provisioned users: `admin` and `user` - two provisioned users: `admin` and `user`
@ -20,7 +20,7 @@ One caveat is worth stating clearly: browser-based SSH tools do not keep the pri
## Ports ## Ports
- `22`: native SSH into the container's local `sshd` - `2222`: native SSH into the container's local `sshd`
- `3000`: browser UI entrypoint; `/` and `/ssh` are forced to a fixed local WebSSH2 session for `127.0.0.1` and rewritten back to that host if changed in the URL - `3000`: browser UI entrypoint; `/` and `/ssh` are forced to a fixed local WebSSH2 session for `127.0.0.1` and rewritten back to that host if changed in the URL
## Runtime environment variables ## Runtime environment variables
@ -113,7 +113,7 @@ If `${HOME}/.kube/config` is missing on the host, the container logs that bootst
```bash ```bash
docker run --rm \ docker run --rm \
-p 2222:22 \ -p 2222:2222 \
-p 3000:3000 \ -p 3000:3000 \
-e ADMIN_SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \ -e ADMIN_SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \
-e USER_SSH_PUBKEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIexample user@example" \ -e USER_SSH_PUBKEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIexample user@example" \
@ -132,7 +132,7 @@ Or in a browser at `http://localhost:3000/`.
```bash ```bash
docker run --rm \ docker run --rm \
-p 2222:22 \ -p 2222:2222 \
-p 3000:3000 \ -p 3000:3000 \
-e ADMIN_PASSWORD='change-this-admin-password' \ -e ADMIN_PASSWORD='change-this-admin-password' \
-e USER_PASSWORD='change-this-user-password' \ -e USER_PASSWORD='change-this-user-password' \
@ -143,7 +143,7 @@ If that fails with a message like `unable to upgrade to tcp, received 500`, the
```bash ```bash
docker run -d --name k8s-mgmt-pod \ docker run -d --name k8s-mgmt-pod \
-p 2222:22 \ -p 2222:2222 \
-p 3000:3000 \ -p 3000:3000 \
-e ADMIN_PASSWORD='change-this-admin-password' \ -e ADMIN_PASSWORD='change-this-admin-password' \
-e USER_PASSWORD='change-this-user-password' \ -e USER_PASSWORD='change-this-user-password' \
@ -156,7 +156,7 @@ If Docker reports `bind: address already in use`, change the host-side ports or
```bash ```bash
docker run --rm \ docker run --rm \
-p 127.0.0.1::22 \ -p 127.0.0.1::2222 \
-p 127.0.0.1::3000 \ -p 127.0.0.1::3000 \
-e ADMIN_PASSWORD='change-this-admin-password' \ -e ADMIN_PASSWORD='change-this-admin-password' \
-e USER_PASSWORD='change-this-user-password' \ -e USER_PASSWORD='change-this-user-password' \
@ -167,7 +167,7 @@ docker run --rm \
```bash ```bash
docker run --rm \ docker run --rm \
-p 2222:22 \ -p 2222:2222 \
-p 3000:3000 \ -p 3000:3000 \
-e ADMIN_SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \ -e ADMIN_SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \
-e ADMIN_PASSWORD='change-this-admin-password' \ -e ADMIN_PASSWORD='change-this-admin-password' \
@ -184,7 +184,7 @@ If you omit both the public-key and password variables for a user, the container
```bash ```bash
docker run --rm \ docker run --rm \
-p 2222:22 \ -p 2222:2222 \
-p 3000:3000 \ -p 3000:3000 \
-e ADMIN_SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \ -e ADMIN_SSH_PUBKEY="$(cat ~/.ssh/id_ed25519.pub)" \
k8s-mgmt-pod:local k8s-mgmt-pod:local

View file

@ -6,7 +6,7 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: k8s-mgmt-pod container_name: k8s-mgmt-pod
ports: ports:
- "${HOST_SSH_PORT:-2222}:22" - "${HOST_SSH_PORT:-2222}:2222"
- "${HOST_WEBSSH_PORT:-3000}:3000" - "${HOST_WEBSSH_PORT:-3000}:3000"
environment: environment:
ADMIN_PASSWORD: ${ADMIN_PASSWORD:-change-this-admin-password} ADMIN_PASSWORD: ${ADMIN_PASSWORD:-change-this-admin-password}

View file

@ -1,4 +1,3 @@
Port 22
Protocol 2 Protocol 2
PermitRootLogin no PermitRootLogin no
PubkeyAuthentication yes PubkeyAuthentication yes

View file

@ -10,6 +10,12 @@ WEBSSH2_PID=""
NGINX_PID="" NGINX_PID=""
BOOTSTRAP_KUBECONFIG="${BOOTSTRAP_KUBECONFIG:-/bootstrap/kubeconfig/config}" BOOTSTRAP_KUBECONFIG="${BOOTSTRAP_KUBECONFIG:-/bootstrap/kubeconfig/config}"
ENABLE_BOOTSTRAP_KUBECONFIG="${ENABLE_BOOTSTRAP_KUBECONFIG:-false}" ENABLE_BOOTSTRAP_KUBECONFIG="${ENABLE_BOOTSTRAP_KUBECONFIG:-false}"
SSH_PORT="${SSH_PORT:-2222}"
if [[ -z "${WEBSSH2_SSH_PORT:-}" ]]; then
WEBSSH2_SSH_PORT="${SSH_PORT}"
fi
export WEBSSH2_SSH_PORT
ensure_host_keys() { ensure_host_keys() {
if [[ ! -f "${STATE_DIR}/ssh_host_rsa_key" ]]; then if [[ ! -f "${STATE_DIR}/ssh_host_rsa_key" ]]; then
@ -187,6 +193,7 @@ render_sshd_auth_config() {
fi fi
cat > "${SSH_DYNAMIC_CONFIG}" <<EOF cat > "${SSH_DYNAMIC_CONFIG}" <<EOF
Port ${SSH_PORT}
PasswordAuthentication ${password_value} PasswordAuthentication ${password_value}
KbdInteractiveAuthentication ${keyboard_interactive_value} KbdInteractiveAuthentication ${keyboard_interactive_value}
EOF EOF
@ -212,7 +219,7 @@ start_services() {
nginx -g 'daemon off;' & nginx -g 'daemon off;' &
NGINX_PID=$! NGINX_PID=$!
log "sshd started on port 22." log "sshd started on port ${SSH_PORT}."
log "WebSSH2 started on port ${WEBSSH2_LISTEN_PORT}." log "WebSSH2 started on port ${WEBSSH2_LISTEN_PORT}."
log "nginx redirect/proxy started on port ${WEB_SSH_PORT}." log "nginx redirect/proxy started on port ${WEB_SSH_PORT}."

View file

@ -62,7 +62,7 @@ If you prefer individual files, apply `namespace.yaml`, `serviceaccount.yaml`, `
Port-forward the service instead of exposing it externally by default: Port-forward the service instead of exposing it externally by default:
```bash ```bash
kubectl -n k8s-mgmt-pod port-forward svc/k8s-mgmt-pod 2222:22 3000:3000 kubectl -n k8s-mgmt-pod port-forward svc/k8s-mgmt-pod 2222:2222 3000:3000
``` ```
Then connect with: Then connect with:

View file

@ -25,7 +25,7 @@ spec:
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- name: ssh - name: ssh
containerPort: 22 containerPort: 2222
protocol: TCP protocol: TCP
- name: webssh - name: webssh
containerPort: 3000 containerPort: 3000
@ -64,20 +64,20 @@ spec:
memory: 512Mi memory: 512Mi
readinessProbe: readinessProbe:
tcpSocket: tcpSocket:
port: 22 port: 2222
initialDelaySeconds: 5 initialDelaySeconds: 5
periodSeconds: 10 periodSeconds: 10
livenessProbe: livenessProbe:
tcpSocket: tcpSocket:
port: 22 port: 2222
initialDelaySeconds: 15 initialDelaySeconds: 15
periodSeconds: 20 periodSeconds: 20
volumeMounts: volumeMounts:
- name: state - name: state
mountPath: /var/lib/k8s-mgmt-pod mountPath: /var/lib/k8s-mgmt-pod
securityContext: securityContext:
# sshd still runs as root here because it needs to bind port 22 and switch to the authenticated user session. # sshd still runs as root to switch to authenticated user sessions.
# The tradeoff is deliberate: keep the container functional, then narrow capabilities instead of forcing a fragile rootless sshd setup. # Binding uses a non-privileged port, so NET_BIND_SERVICE is not required.
runAsUser: 0 runAsUser: 0
runAsGroup: 0 runAsGroup: 0
runAsNonRoot: false runAsNonRoot: false
@ -85,7 +85,7 @@ spec:
readOnlyRootFilesystem: false readOnlyRootFilesystem: false
capabilities: capabilities:
drop: ["ALL"] drop: ["ALL"]
add: ["CHOWN", "DAC_OVERRIDE", "FOWNER", "NET_BIND_SERVICE", "SETGID", "SETUID"] add: ["CHOWN", "DAC_OVERRIDE", "FOWNER", "SETGID", "SETUID"]
volumes: volumes:
- name: state - name: state
emptyDir: {} emptyDir: {}

View file

@ -19,6 +19,6 @@ spec:
k8s-mgmt-pod-access: "true" k8s-mgmt-pod-access: "true"
ports: ports:
- protocol: TCP - protocol: TCP
port: 22 port: 2222
- protocol: TCP - protocol: TCP
port: 3000 port: 3000

View file

@ -8,7 +8,7 @@ spec:
app.kubernetes.io/name: k8s-mgmt-pod app.kubernetes.io/name: k8s-mgmt-pod
ports: ports:
- name: ssh - name: ssh
port: 22 port: 2222
targetPort: ssh targetPort: ssh
protocol: TCP protocol: TCP
- name: webssh - name: webssh
@ -27,7 +27,7 @@ spec:
# app.kubernetes.io/name: k8s-mgmt-pod # app.kubernetes.io/name: k8s-mgmt-pod
# ports: # ports:
# - name: ssh # - name: ssh
# port: 22 # port: 2222
# targetPort: ssh # targetPort: ssh
# - name: webssh # - name: webssh
# port: 3000 # port: 3000