diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 6f54df93..e6f68794 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,7 +10,7 @@ builds: - CGO_ENABLED=0 goos: - linux - # - windows + - windows # - darwin goarch: - amd64 @@ -36,11 +36,11 @@ builds: - CGO_ENABLED=0 goos: - linux + - windows + # - darwin goarch: - amd64 - arm64 - # - windows - # - darwin main: ./plugin/workingdir binary: plugins/workingdir tags: @@ -50,10 +50,11 @@ builds: - CGO_ENABLED=0 goos: - linux + - windows + # - darwin goarch: - amd64 - arm64 - # - windows # - darwin main: ./plugin/yaml binary: plugins/yaml @@ -64,11 +65,11 @@ builds: - CGO_ENABLED=0 goos: - linux + # - windows + # - darwin goarch: - amd64 - arm64 - # - windows - # - darwin main: ./plugin/docker binary: plugins/docker tags: @@ -78,11 +79,11 @@ builds: - CGO_ENABLED=0 goos: - linux + # - windows + # - darwin goarch: - amd64 - arm64 - # - windows - # - darwin main: ./plugin/kubernetes binary: plugins/kubernetes tags: @@ -92,11 +93,11 @@ builds: - CGO_ENABLED=0 goos: - linux + - windows + # - darwin goarch: - amd64 - arm64 - # - windows - # - darwin main: ./plugin/fixed binary: plugins/fixed tags: @@ -106,11 +107,11 @@ builds: - CGO_ENABLED=0 goos: - linux + - windows + # - darwin goarch: - amd64 - arm64 - # - windows - # - darwin main: ./plugin/failtoban binary: plugins/failtoban tags: @@ -118,6 +119,7 @@ builds: archives: - format: tar.gz + allow_different_binary_count: true # this name template makes the OS and Arch compatible with the results of uname. name_template: >- sshpiperd_with_plugins_ @@ -130,9 +132,14 @@ archives: format_overrides: - goos: windows format: zip - # builds: - # - sshpiperd - # - plugin_workingdir + builds: + - sshpiperd + - plugin_workingdir + - plugin_yaml + - plugin_fixed + - plugin_failtoban + - plugin_docker + - plugin_kubernetes dockers: - image_templates: - "farmer1992/sshpiperd:{{ .Version }}-amd64" diff --git a/cmd/sshpiperd/cmd_dummy.go b/cmd/sshpiperd/cmd_dummy.go index 07c0d675..a6620850 100644 --- a/cmd/sshpiperd/cmd_dummy.go +++ b/cmd/sshpiperd/cmd_dummy.go @@ -1,4 +1,4 @@ -//go:build !linux +//go:build !linux && !windows package main @@ -6,3 +6,7 @@ import "os/exec" func setPdeathsig(cmd *exec.Cmd) { } + +func addProcessToJob(cmd *exec.Cmd) error { + return nil +} diff --git a/cmd/sshpiperd/cmd_linux.go b/cmd/sshpiperd/cmd_linux.go index ba2e85d0..0debc0d6 100644 --- a/cmd/sshpiperd/cmd_linux.go +++ b/cmd/sshpiperd/cmd_linux.go @@ -10,3 +10,7 @@ import ( func setPdeathsig(cmd *exec.Cmd) { cmd.SysProcAttr = &syscall.SysProcAttr{Pdeathsig: syscall.SIGTERM} } + +func addProcessToJob(cmd *exec.Cmd) error { + return nil +} diff --git a/cmd/sshpiperd/cmd_windows.go b/cmd/sshpiperd/cmd_windows.go new file mode 100644 index 00000000..3a1074b0 --- /dev/null +++ b/cmd/sshpiperd/cmd_windows.go @@ -0,0 +1,35 @@ +//go:build windows + +package main + +import ( + "os/exec" + + log "github.com/sirupsen/logrus" + "github.com/tg123/jobobject" +) + +func setPdeathsig(cmd *exec.Cmd) { +} + +func addProcessToJob(cmd *exec.Cmd) error { + if jobObject == nil { + return nil + } + + if cmd.Process == nil { + return nil + } + + return jobObject.AddProcess(cmd.Process) +} + +var jobObject *jobobject.JobObject + +func init() { + var err error + jobObject, err = jobobject.Create() + if err != nil { + log.Warnf("failed to create job object: %v", err) + } +} diff --git a/cmd/sshpiperd/main.go b/cmd/sshpiperd/main.go index 1cbdc7ed..f3a64854 100644 --- a/cmd/sshpiperd/main.go +++ b/cmd/sshpiperd/main.go @@ -62,6 +62,10 @@ func createCmdPlugin(args []string) (*plugin.CmdPlugin, error) { return nil, err } + if err := addProcessToJob(cmd); err != nil { + return nil, err + } + p.Name = exe return p, nil diff --git a/go.mod b/go.mod index a9bc5797..52d0b35e 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pires/go-proxyproto v0.6.2 github.com/sirupsen/logrus v1.9.3 + github.com/tg123/jobobject v0.1.0 github.com/tg123/remotesigner v0.0.1 github.com/urfave/cli/v2 v2.25.7 golang.org/x/crypto v0.12.0 diff --git a/go.sum b/go.sum index 48383dfa..4e8c1a58 100644 --- a/go.sum +++ b/go.sum @@ -157,6 +157,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tg123/jobobject v0.1.0 h1:deOWVH+SvsnFtT/M+HFhtZ7t9GMYPzYMvvF25IIMRRE= +github.com/tg123/jobobject v0.1.0/go.mod h1:TtbMLKdmTPY6eMo4aqDXiQWv0yTfAgDt1mxv6J9pM8o= github.com/tg123/remotesigner v0.0.1 h1:fFCKgpBOv0nfpWOuuWMke9vECKQu6PTrm4iktDwwMMM= github.com/tg123/remotesigner v0.0.1/go.mod h1:leliuGRH9ayYYwRo6JO8yg+KyWcltK69XJdLv1x7slM= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= @@ -202,6 +204,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210611083646-a4fc73990273/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=