Skip to content

Commit

Permalink
Use TOML by default
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Aug 16, 2024
1 parent 928eb12 commit c594b93
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

Expand Down
22 changes: 0 additions & 22 deletions etc/config.example.json

This file was deleted.

31 changes: 31 additions & 0 deletions etc/config.example.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions etc/sshmux.service
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion sshmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c594b93

Please sign in to comment.