From c594b93d08a3c7ac03f86a41c309476c0134a331 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Sat, 17 Aug 2024 02:49:31 +0800 Subject: [PATCH] Use TOML by default --- .github/workflows/build.yml | 2 +- .goreleaser.yaml | 2 +- Dockerfile | 1 + README.md | 2 +- etc/config.example.json | 22 ---------------------- etc/config.example.toml | 31 +++++++++++++++++++++++++++++++ etc/sshmux.service | 4 ++-- main.go | 2 +- sshmux_test.go | 2 +- 9 files changed, 39 insertions(+), 29 deletions(-) delete mode 100644 etc/config.example.json create mode 100644 etc/config.example.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c033be7..c04b9ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: uses: softprops/action-gh-release@v1 with: files: | - etc/config.example.json + etc/config.example.toml etc/sshmux.service docker: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4a68f35..429201d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -43,7 +43,7 @@ nfpms: contents: - src: README.md dst: /usr/share/doc/sshmux/ - - src: etc/config.example.json + - src: etc/config.example.toml dst: /etc/sshmux/ - src: etc/sshmux.service dst: /lib/systemd/system/ diff --git a/Dockerfile b/Dockerfile index 4c33391..2b18e29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,5 +7,6 @@ RUN go mod download RUN CGO_ENABLED=0 go build -o /go/bin/sshmux FROM gcr.io/distroless/static-debian12:nonroot +COPY ./etc/config.example.toml /etc/config.example.toml COPY --from=build /go/bin/sshmux / CMD ["/sshmux"] diff --git a/README.md b/README.md index e61201d..007cb9c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ You can perform unit tests with `go test` or `make test`. Enable verbose logging ## Config -`sshmux` requires a JSON configuration file to start up. By default it will look at `/etc/sshmux/config.json`, but you can also specify a custom configuration by passing `-c path/to/config.json` in the command line arguments. An [example](etc/config.example.json) file is provided. +`sshmux` requires a JSON configuration file to start up. By default it will look at `/etc/sshmux/config.toml`, but you can also specify a custom configuration by passing `-c path/to/config.toml` in the command line arguments. An [example](etc/config.example.toml) file is provided. The table below shows the available options for `sshmux`: diff --git a/etc/config.example.json b/etc/config.example.json deleted file mode 100644 index b797ef2..0000000 --- a/etc/config.example.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "address": "0.0.0.0:8022", - "proxy-protocol-allowed-cidrs": [ - "127.0.0.22/32" - ], - "host-keys": [ - "/tmp/sshmux/ssh_host_ed25519_key", - "/tmp/sshmux/ssh_host_ecdsa_key", - "/tmp/sshmux/ssh_host_rsa_key" - ], - "api": "http://127.0.0.1:5000/ssh", - "token": "token", - "recovery-token": "token", - "recovery-server": "172.30.0.101:2222", - "recovery-username": ["recovery", "console", "serial"], - "all-username-nopassword": true, - "username-nopassword": ["vlab", "ubuntu", "root"], - "invalid-username": ["用户名"], - "invalid-username-message": "Invalid username %s. Please check https://vlab.ustc.edu.cn/docs/login/ssh/#username for more information.", - "logger": "127.0.0.1:5556", - "banner": "Welcome to Vlab\n" -} diff --git a/etc/config.example.toml b/etc/config.example.toml new file mode 100644 index 0000000..edbc46a --- /dev/null +++ b/etc/config.example.toml @@ -0,0 +1,31 @@ +address = "0.0.0.0:8022" + +[ssh] +banner = "Welcome to Vlab\n" +host-keys = [ + "/tmp/sshmux/ssh_host_ed25519_key", + "/tmp/sshmux/ssh_host_ecdsa_key", + "/tmp/sshmux/ssh_host_rsa_key", +] + +[auth] +api = "http://127.0.0.1:5000/ssh" +token = "token" +# Legacy settings +all-username-nopassword = true +usernames-nopassword = ["vlab", "ubuntu", "root"] +invalid-usernames = ["用户名"] +invalid-username-message = "Invalid username %s. Please check https://vlab.ustc.edu.cn/docs/login/ssh/#username for more information." + +[logger] +enabled = true +address = "127.0.0.1:5556" + +[proxy-protocol] +enabled = true +networks = ["127.0.0.22/32"] + +[recovery] +address = "172.30.0.101:2222" +usernames = ["recovery", "console", "serial"] +token = "token" diff --git a/etc/sshmux.service b/etc/sshmux.service index e5aeb43..f1503c0 100644 --- a/etc/sshmux.service +++ b/etc/sshmux.service @@ -1,11 +1,11 @@ [Unit] Description=A reverse proxy for SSH StartLimitIntervalSec=0 -ConditionPathExists=/etc/sshmux/config.json +ConditionPathExists=/etc/sshmux/config.toml [Service] Type=exec -ExecStart=/usr/bin/sshmux -c /etc/sshmux/config.json +ExecStart=/usr/bin/sshmux -c /etc/sshmux/config.toml WorkingDirectory=/etc/sshmux/ Restart=on-failure RestartSec=5s diff --git a/main.go b/main.go index 3707f8e..1d41ab0 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,7 @@ func sshmuxServer(configFile string) { func main() { var configFile string - flag.StringVar(&configFile, "c", "/etc/sshmux/config.json", "config file") + flag.StringVar(&configFile, "c", "/etc/sshmux/config.toml", "config file") flag.Parse() sshmuxServer(configFile) } diff --git a/sshmux_test.go b/sshmux_test.go index ee701f0..f90674d 100644 --- a/sshmux_test.go +++ b/sshmux_test.go @@ -246,7 +246,7 @@ func TestSSHClientConnection(t *testing.T) { initEnv(t, baseDir) privateKeyPath := filepath.Join(baseDir, "example_rsa") - go sshmuxServer("etc/config.example.json") + go sshmuxServer("etc/config.example.toml") // sanity check testWithSSHClient(t, sshdServerAddr, "sanity check", false, baseDir, privateKeyPath)