Skip to content

Commit 6a8863b

Browse files
authored
[sshd] Add GatewayPorts option (#1464)
add gatewayports option to sshd
1 parent c05bd45 commit 6a8863b

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

src/sshd/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Adds a SSH server into a container so that you can use an external terminal, sft
1515

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

2021
## Usage

src/sshd/devcontainer-feature.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "sshd",
3-
"version": "1.0.10",
3+
"version": "1.1.0",
44
"name": "SSH server",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/sshd",
66
"description": "Adds a SSH server into a container so that you can use an external terminal, sftp, or SSHFS to interact with it.",
@@ -12,6 +12,16 @@
1212
],
1313
"default": "latest",
1414
"description": "Currently unused."
15+
},
16+
"gatewayPorts": {
17+
"type": "string",
18+
"enum": [
19+
"no",
20+
"yes",
21+
"clientspecified"
22+
],
23+
"default": "no",
24+
"description": "Enable other hosts in the same network to connect to the forwarded ports"
1525
}
1626
},
1727
"entrypoint": "/usr/local/share/ssh-init.sh",

src/sshd/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SSHD_PORT="${SSHD_PORT:-"2222"}"
1313
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
1414
START_SSHD="${START_SSHD:-"false"}"
1515
NEW_PASSWORD="${NEW_PASSWORD:-"skip"}"
16+
GATEWAY_PORTS="${GATEWAYPORTS:-"no"}"
1617

1718
set -e
1819

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

test/sshd/scenarios.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"sshd_with_default_gateway_ports": {
3+
"image": "ubuntu:noble",
4+
"features": {
5+
"sshd": {
6+
"gatewayPorts": "no"
7+
}
8+
}
9+
},
10+
"sshd_with_pinned_gateway_ports_clientspecified": {
11+
"image": "ubuntu:noble",
12+
"features": {
13+
"sshd": {
14+
"gatewayPorts": "clientspecified"
15+
}
16+
}
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "correct default GatewayPorts" grep "GatewayPorts no" /etc/ssh/sshd_config
10+
11+
# Report result
12+
reportResults
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "correct default GatewayPorts" grep "GatewayPorts clientspecified" /etc/ssh/sshd_config
10+
11+
# Report result
12+
reportResults

0 commit comments

Comments
 (0)