Skip to content
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
1 change: 1 addition & 0 deletions src/sshd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Adds a SSH server into a container so that you can use an external terminal, sft

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| gatewayPorts | Enable other hosts in the same network to connect to the forwarded ports | string | no
| version | Currently unused. | string | latest |

## Usage
Expand Down
12 changes: 11 additions & 1 deletion src/sshd/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "sshd",
"version": "1.0.10",
"version": "1.1.0",
"name": "SSH server",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/sshd",
"description": "Adds a SSH server into a container so that you can use an external terminal, sftp, or SSHFS to interact with it.",
Expand All @@ -12,6 +12,16 @@
],
"default": "latest",
"description": "Currently unused."
},
"gatewayPorts": {
"type": "string",
"enum": [
"no",
"yes",
"clientspecified"
],
"default": "no",
"description": "Enable other hosts in the same network to connect to the forwarded ports"
}
},
"entrypoint": "/usr/local/share/ssh-init.sh",
Expand Down
2 changes: 2 additions & 0 deletions src/sshd/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SSHD_PORT="${SSHD_PORT:-"2222"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
START_SSHD="${START_SSHD:-"false"}"
NEW_PASSWORD="${NEW_PASSWORD:-"skip"}"
GATEWAY_PORTS="${GATEWAYPORTS:-"no"}"

set -e

Expand Down Expand Up @@ -89,6 +90,7 @@ mkdir -p /var/run/sshd
sed -i 's/session\s*required\s*pam_loginuid\.so/session optional pam_loginuid.so/g' /etc/pam.d/sshd
sed -i 's/#*PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i -E "s/#*\s*Port\s+.+/Port ${SSHD_PORT}/g" /etc/ssh/sshd_config
sed -i "s/#GatewayPorts no/GatewayPorts ${GATEWAY_PORTS}/g" /etc/ssh/sshd_config
# Need to UsePAM so /etc/environment is processed
sed -i -E "s/#?\s*UsePAM\s+.+/UsePAM yes/g" /etc/ssh/sshd_config

Expand Down
18 changes: 18 additions & 0 deletions test/sshd/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sshd_with_default_gateway_ports": {
"image": "ubuntu:noble",
"features": {
"sshd": {
"gatewayPorts": "no"
}
}
},
"sshd_with_pinned_gateway_ports_clientspecified": {
"image": "ubuntu:noble",
"features": {
"sshd": {
"gatewayPorts": "clientspecified"
}
}
}
}
12 changes: 12 additions & 0 deletions test/sshd/sshd_with_default_gateway_ports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "correct default GatewayPorts" grep "GatewayPorts no" /etc/ssh/sshd_config

# Report result
reportResults
12 changes: 12 additions & 0 deletions test/sshd/sshd_with_pinned_gateway_ports_clientspecified.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "correct default GatewayPorts" grep "GatewayPorts clientspecified" /etc/ssh/sshd_config

# Report result
reportResults