Skip to content

Commit 7f476a8

Browse files
authored
feat: support GatewayPorts (#12)
1 parent 4a234f3 commit 7f476a8

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

README.ja.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ scp ./local.tgz ubuntu@job--batch.namespace--etl.context--dev.sshpod:/tmp/
4747
- 対象は `pod--<pod>``deployment--<deployment>``job--<job>` のいずれかで指定します。Deployment/Job は Ready な Pod を自動で選択します。
4848
- オプション: `container--<container>`(マルチコンテナ Pod では必須)、`namespace--<namespace>`(コンテキストに設定された namespace があればそれを、無い場合はクラスタのデフォルトを使用)、`context--<context>`(省略時は現在の `kubectl` コンテキスト)。
4949
- Pod が非 root で動いている場合、SSH ユーザはコンテナ内の実ユーザと一致させてください。root Pod であれば任意のユーザで接続できます。
50+
- リモートポートフォワードでは、クライアントが指定した bind address を尊重します。例えば `ssh -R 0.0.0.0:18000:127.0.0.1:8000 ...sshpod` は Pod ネットワーク上で `18000` を公開し、bind address を省略した場合は OpenSSH のデフォルトどおり localhost のみに留まります。
5051

5152
## 要件
5253
- ローカル: 対象クラスタに到達でき、`exec`/`port-forward` が許可された `kubectl`、OpenSSH クライアント (`ssh`/`scp`/`sftp`) と `ssh-keygen``~/.ssh/config``~/.cache/sshpod` への書き込み権限。

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ scp ./local.tgz ubuntu@job--batch.namespace--etl.context--dev.sshpod:/tmp/
4848
- Targets: `pod--<pod>`, `deployment--<deployment>`, `job--<job>`; deployments/jobs pick a ready Pod automatically.
4949
- Optional pieces: `container--<container>` (required for multi-container Pods), `namespace--<namespace>` (falls back to the namespace set on the context, otherwise the cluster default), `context--<context>` (defaults to your current `kubectl` context).
5050
- Pods running as non-root require you to SSH as that user; root Pods accept any SSH user.
51+
- Remote port forwarding honors the bind address requested by the client. For example, `ssh -R 0.0.0.0:18000:127.0.0.1:8000 ...sshpod` exposes port `18000` on the Pod network, while omitting the bind address keeps OpenSSH's loopback-only default.
5152

5253
## Requirements
5354
- Local: `kubectl` configured for the target cluster with permission to `exec` and `port-forward`; OpenSSH client tools (`ssh`/`scp`/`sftp`) and `ssh-keygen`; ability to write to `~/.ssh/config` and `~/.cache/sshpod`.

src/remote.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ ChallengeResponseAuthentication no
184184
PermitEmptyPasswords no
185185
AllowAgentForwarding yes
186186
AllowTcpForwarding yes
187+
GatewayPorts clientspecified
187188
X11Forwarding no
188189
Subsystem sftp internal-sftp
189190
LogLevel VERBOSE
@@ -238,4 +239,11 @@ mod tests {
238239
assert!(!START_SSHD_SCRIPT.contains("PermitUserEnvironment yes"));
239240
assert!(START_SSHD_SCRIPT.contains("append_setenv_arg PATH"));
240241
}
242+
243+
#[test]
244+
fn start_script_allows_client_requested_remote_forward_bind_addresses() {
245+
assert!(START_SSHD_SCRIPT.contains("\nAllowTcpForwarding yes\n"));
246+
assert!(START_SSHD_SCRIPT.contains("\nGatewayPorts clientspecified\n"));
247+
assert!(!START_SSHD_SCRIPT.contains("\nGatewayPorts yes\n"));
248+
}
241249
}

0 commit comments

Comments
 (0)