all: run gofumpt (#652)
* all: run gofumpt https://github.com/mvdan/gofumpt The main appeal for me here is that my (and many other peoples') editors run this on save, so doing a single diff here keeps other diffs minimal. * .github/workflows: add gofumpt checker
This commit is contained in:
parent
6b9dbc3b05
commit
89ab72bee0
33 changed files with 63 additions and 145 deletions
34
.github/workflows/gofumpt.yml
vendored
Normal file
34
.github/workflows/gofumpt.yml
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
name: check gofumpt
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
gofumpt:
|
||||
name: Check gofumpt formatting
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Download gofumpt binary
|
||||
run: |
|
||||
curl -L https://github.com/mvdan/gofumpt/releases/download/v0.8.0/gofumpt_v0.8.0_linux_amd64 -o /tmp/gofumpt
|
||||
chmod +x /tmp/gofumpt
|
||||
|
||||
- name: Check gofumpt formatting
|
||||
run: |
|
||||
unformatted_files=$(/tmp/gofumpt -l .)
|
||||
if [ -n "$unformatted_files" ]; then
|
||||
echo "The following files are not gofumpt'd:"
|
||||
echo "$unformatted_files"
|
||||
echo
|
||||
echo "Please run: gofumpt -w ."
|
||||
exit 1
|
||||
fi
|
||||
echo "All files are properly formatted"
|
||||
|
|
@ -70,7 +70,6 @@ func (l *asciicastLogger) uphook(msg []byte) error {
|
|||
t := time.Since(l.starttime).Seconds()
|
||||
|
||||
_, err := fmt.Fprintf(f, "[%v,\"o\",\"%s\"]\n", t, jsonEscape(string(buf)))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -118,7 +117,6 @@ func (l *asciicastLogger) downhook(msg []byte) error {
|
|||
}
|
||||
case "shell", "exec":
|
||||
jsonEnvs, err := json.Marshal(l.envs)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -126,9 +124,8 @@ func (l *asciicastLogger) downhook(msg []byte) error {
|
|||
f, err := os.OpenFile(
|
||||
path.Join(l.recorddir, fmt.Sprintf("%s%s-channel-%d.cast", l.prefix, reqType, clientChannelID)),
|
||||
os.O_WRONLY|os.O_CREATE|os.O_TRUNC,
|
||||
0600,
|
||||
0o600,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -145,7 +142,6 @@ func (l *asciicastLogger) downhook(msg []byte) error {
|
|||
l.starttime.Unix(),
|
||||
string(jsonEnvs),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func generateSshKey(keyfile string) error {
|
|||
|
||||
privateKeyBytes := pem.EncodeToMemory(privateKeyPEM)
|
||||
|
||||
return os.WriteFile(keyfile, privateKeyBytes, 0600)
|
||||
return os.WriteFile(keyfile, privateKeyBytes, 0o600)
|
||||
}
|
||||
|
||||
func newDaemon(ctx *cli.Context) (*daemon, error) {
|
||||
|
|
@ -157,7 +157,6 @@ func newDaemon(ctx *cli.Context) (*daemon, error) {
|
|||
}
|
||||
case "dedup":
|
||||
config.UpstreamBannerCallback = func(downstream ssh.ServerPreAuthConn, banner string, ctx ssh.ChallengeContext) error {
|
||||
|
||||
meta, ok := ctx.Meta().(*plugin.PluginConnMeta)
|
||||
if !ok {
|
||||
// should not happen, but just in case
|
||||
|
|
@ -244,7 +243,6 @@ func (d *daemon) run() error {
|
|||
|
||||
go func() {
|
||||
p, err := ssh.NewSSHPiperConn(c, &d.config.PiperConfig)
|
||||
|
||||
if err != nil {
|
||||
errorc <- err
|
||||
return
|
||||
|
|
@ -288,7 +286,7 @@ func (d *daemon) run() error {
|
|||
uniqID := plugin.GetUniqueID(p.ChallengeContext())
|
||||
recorddir = path.Join(d.recorddir, uniqID)
|
||||
}
|
||||
err = os.MkdirAll(recorddir, 0700)
|
||||
err = os.MkdirAll(recorddir, 0o700)
|
||||
if err != nil {
|
||||
log.Errorf("cannot create screen recording dir %v: %v", recorddir, err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ func createNetGrpcPlugin(args []string) (grpcPlugin *plugin.GrpcPlugin, err erro
|
|||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
|
||||
var secopt grpc.DialOption
|
||||
if c.Bool("insecure") {
|
||||
secopt = grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ func (h *hookChain) append(hook ssh.PipePacketHook) {
|
|||
}
|
||||
|
||||
func (h *hookChain) hook() ssh.PipePacketHook {
|
||||
|
||||
if len(h.hooks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ func (cp *ChainPlugins) NextAuthMethods(conn ssh.ConnMetadata, challengeCtx ssh.
|
|||
}
|
||||
|
||||
func (cp *ChainPlugins) InstallPiperConfig(config *GrpcPluginConfig) error {
|
||||
|
||||
config.CreateChallengeContext = func(conn ssh.ServerPreAuthConn) (ssh.ChallengeContext, error) {
|
||||
ctx, err := cp.CreateChallengeContext(conn)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ func DialGrpc(conn *grpc.ClientConn) (*GrpcPlugin, error) {
|
|||
}
|
||||
|
||||
func (g *GrpcPlugin) InstallPiperConfig(config *GrpcPluginConfig) error {
|
||||
|
||||
cb, err := g.client.ListCallbacks(context.Background(), &libplugin.ListCallbackRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -206,7 +205,6 @@ func (g *GrpcPlugin) NextAuthMethodsRemote(conn ssh.ConnMetadata, challengeCtx s
|
|||
reply, err := g.client.NextAuthMethods(context.Background(), &libplugin.NextAuthMethodsRequest{
|
||||
Meta: meta,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -295,7 +293,6 @@ func (g *GrpcPlugin) createUpstream(conn ssh.ConnMetadata, challengeCtx ssh.Chal
|
|||
Netaddress: addr.String(),
|
||||
Key: key.Marshal(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -379,7 +376,6 @@ func (g *GrpcPlugin) createUpstream(conn ssh.ConnMetadata, challengeCtx ssh.Chal
|
|||
Address: addr,
|
||||
ClientConfig: config,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (g *GrpcPlugin) dialUpstream(uri string) (net.Conn, string, error) {
|
||||
|
|
@ -417,7 +413,6 @@ func (g *GrpcPlugin) NoClientAuthCallback(conn ssh.ConnMetadata, challengeCtx ss
|
|||
reply, err := g.client.NoneAuth(context.Background(), &libplugin.NoneAuthRequest{
|
||||
Meta: meta,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -431,7 +426,6 @@ func (g *GrpcPlugin) PasswordCallback(conn ssh.ConnMetadata, password []byte, ch
|
|||
Meta: meta,
|
||||
Password: password,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -445,7 +439,6 @@ func (g *GrpcPlugin) PublicKeyCallback(conn ssh.ConnMetadata, key ssh.PublicKey,
|
|||
Meta: meta,
|
||||
PublicKey: key.Marshal(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -454,7 +447,6 @@ func (g *GrpcPlugin) PublicKeyCallback(conn ssh.ConnMetadata, key ssh.PublicKey,
|
|||
}
|
||||
|
||||
func (g *GrpcPlugin) KeyboardInteractiveCallback(conn ssh.ConnMetadata, client ssh.KeyboardInteractiveChallenge, challengeCtx ssh.ChallengeContext) (*ssh.Upstream, error) {
|
||||
|
||||
stream, err := g.client.KeyboardInteractiveAuth(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -525,7 +517,6 @@ func (g *GrpcPlugin) DownstreamBannerCallback(conn ssh.ConnMetadata, challengeCt
|
|||
reply, err := g.client.Banner(context.Background(), &libplugin.BannerRequest{
|
||||
Meta: meta,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Debugf("failed to get banner: %v", err)
|
||||
return ""
|
||||
|
|
@ -606,13 +597,11 @@ func DialCmd(cmd *exec.Cmd) (*CmdPlugin, error) {
|
|||
conn, err := grpc.NewClient("127.0.0.1", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(func(_ context.Context, _ string) (net.Conn, error) {
|
||||
return cmdconn, nil
|
||||
}))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
g, err := DialGrpc(conn)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"golang.org/x/term"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// checkIfTerminal returns whether the given file descriptor is a terminal.
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ import (
|
|||
var mainver string = "(devel)"
|
||||
|
||||
func version() string {
|
||||
|
||||
var v = mainver
|
||||
v := mainver
|
||||
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
|
|
@ -79,7 +78,6 @@ func isValidLogFormat(logFormat string) bool {
|
|||
}
|
||||
|
||||
func main() {
|
||||
|
||||
app := &cli.App{
|
||||
Name: "sshpiperd",
|
||||
Usage: "the missing reverse proxy for ssh scp",
|
||||
|
|
@ -240,7 +238,6 @@ func main() {
|
|||
|
||||
log.Info("starting sshpiperd version: ", version())
|
||||
d, err := newDaemon(ctx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -288,7 +285,7 @@ func main() {
|
|||
if dir == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
pluginexe := filepath.Join(dir, pluginEnv)
|
||||
if _, err := os.Stat(pluginexe); err == nil {
|
||||
args = append(args, pluginexe)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
configs := map[string]string{
|
||||
"sshpiperd": "../../main.go",
|
||||
"workingdir": "../../../../plugin/workingdir/main.go",
|
||||
|
|
@ -40,9 +39,7 @@ func extractFlags(namespace, filePath string) {
|
|||
}
|
||||
|
||||
ast.Inspect(node, func(n ast.Node) bool {
|
||||
|
||||
if cl, ok := n.(*ast.CompositeLit); ok {
|
||||
|
||||
if t, ok := cl.Type.(*ast.SelectorExpr); ok {
|
||||
|
||||
o, ok := t.X.(*ast.Ident)
|
||||
|
|
@ -63,7 +60,6 @@ func extractFlags(namespace, filePath string) {
|
|||
|
||||
for _, v := range cl.Elts {
|
||||
if kv, ok := v.(*ast.KeyValueExpr); ok {
|
||||
|
||||
switch kv.Key.(*ast.Ident).Name {
|
||||
case "Name":
|
||||
flagName = strings.Trim(kv.Value.(*ast.BasicLit).Value, " \"")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func main() {
|
|||
if len(os.Args) > 1 && os.Args[1] == "generate" {
|
||||
flags = loadFromSnapctl()
|
||||
cache, _ := json.Marshal(flags)
|
||||
if err := os.WriteFile(configfile, cache, 0600); err != nil {
|
||||
if err := os.WriteFile(configfile, cache, 0o600); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ func loadFromSnapctl() map[string][][]string {
|
|||
v = "workingdir"
|
||||
|
||||
dir := path.Join(commondir, v)
|
||||
_ = os.MkdirAll(dir, 0700)
|
||||
_ = os.MkdirAll(dir, 0o700)
|
||||
flags["workingdir"] = append(flags["workingdir"], []string{"root", dir})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,25 +19,21 @@ type filePtyLogger struct {
|
|||
}
|
||||
|
||||
func newFilePtyLogger(outputdir string) (*filePtyLogger, error) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
filename := fmt.Sprintf("%d", now.Unix())
|
||||
|
||||
typescript, err := os.OpenFile(path.Join(outputdir, fmt.Sprintf("%v.typescript", filename)), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
|
||||
typescript, err := os.OpenFile(path.Join(outputdir, fmt.Sprintf("%v.typescript", filename)), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(typescript, "Script started on %v\n", now.Format(time.ANSIC))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
timing, err := os.OpenFile(path.Join(outputdir, fmt.Sprintf("%v.timing", filename)), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
|
||||
timing, err := os.OpenFile(path.Join(outputdir, fmt.Sprintf("%v.timing", filename)), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -50,7 +46,6 @@ func newFilePtyLogger(outputdir string) (*filePtyLogger, error) {
|
|||
}
|
||||
|
||||
func (l *filePtyLogger) loggingTty(msg []byte) error {
|
||||
|
||||
if msg[0] == msgChannelData {
|
||||
|
||||
buf := msg[9:]
|
||||
|
|
@ -65,7 +60,6 @@ func (l *filePtyLogger) loggingTty(msg []byte) error {
|
|||
l.oldtime = now
|
||||
|
||||
_, err := l.typescript.Write(buf)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
)
|
||||
|
||||
func TestBanner(t *testing.T) {
|
||||
|
||||
t.Run("args", func(t *testing.T) {
|
||||
piperaddr, piperport := nextAvailablePiperAddress()
|
||||
randtext := uuid.New().String()
|
||||
|
|
@ -22,7 +21,6 @@ func TestBanner(t *testing.T) {
|
|||
"--target",
|
||||
"host-password:2222",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -44,7 +42,6 @@ func TestBanner(t *testing.T) {
|
|||
"user",
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -56,7 +53,6 @@ func TestBanner(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("file", func(t *testing.T) {
|
||||
|
||||
piperaddr, piperport := nextAvailablePiperAddress()
|
||||
randtext := uuid.New().String()
|
||||
|
||||
|
|
@ -83,7 +79,6 @@ func TestBanner(t *testing.T) {
|
|||
"--target",
|
||||
"host-password:2222",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -105,7 +100,6 @@ func TestBanner(t *testing.T) {
|
|||
"user",
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -125,7 +119,6 @@ func TestBanner(t *testing.T) {
|
|||
"--target",
|
||||
"host-password:2222",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -147,7 +140,6 @@ func TestBanner(t *testing.T) {
|
|||
"user",
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ func TestConnMeta(t *testing.T) {
|
|||
"--",
|
||||
"/sshpiperd/plugins/testgetmetaplugin",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -46,7 +45,6 @@ func TestConnMeta(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ func TestDocker(t *testing.T) {
|
|||
piperport,
|
||||
"/sshpiperd/plugins/docker",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -45,7 +44,6 @@ func TestDocker(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
@ -60,7 +58,6 @@ func TestDocker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("key", func(t *testing.T) {
|
||||
|
||||
keyfiledir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create temp key file: %v", err)
|
||||
|
|
@ -68,11 +65,11 @@ func TestDocker(t *testing.T) {
|
|||
|
||||
keyfile := path.Join(keyfiledir, "key")
|
||||
|
||||
if err := os.WriteFile(keyfile, []byte(testprivatekey), 0400); err != nil {
|
||||
if err := os.WriteFile(keyfile, []byte(testprivatekey), 0o400); err != nil {
|
||||
t.Errorf("failed to write to test key: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile("/publickey_authorized_keys/authorized_keys", []byte(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRGTH325rDUp12tplwukHmR8ytbC9TPZ886gCstynP1`), 0400); err != nil {
|
||||
if err := os.WriteFile("/publickey_authorized_keys/authorized_keys", []byte(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRGTH325rDUp12tplwukHmR8ytbC9TPZ886gCstynP1`), 0o400); err != nil {
|
||||
t.Errorf("failed to write to authorized_keys: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +92,6 @@ func TestDocker(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ func TestFailtoban(t *testing.T) {
|
|||
"--max-failures",
|
||||
"3",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -74,7 +73,6 @@ func TestFailtoban(t *testing.T) {
|
|||
"user",
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
@ -90,7 +88,6 @@ func TestFailtoban(t *testing.T) {
|
|||
t.Errorf("expected connection closed by")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFailtobanPipeCreateFail(t *testing.T) {
|
||||
|
|
@ -107,7 +104,6 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
"--max-failures",
|
||||
"3",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -122,11 +118,11 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
userdir := path.Join(workingdir, "bypassword")
|
||||
|
||||
{
|
||||
if err := os.MkdirAll(userdir, 0700); err != nil {
|
||||
if err := os.MkdirAll(userdir, 0o700); err != nil {
|
||||
t.Errorf("failed to create working directory %s: %v", userdir, err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-password:2222"), 0400); err != nil {
|
||||
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-password:2222"), 0o400); err != nil {
|
||||
t.Errorf("failed to write upstream file: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -138,12 +134,11 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
"2222",
|
||||
"host-password",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run ssh-keyscan: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
|
||||
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0o400); err != nil {
|
||||
t.Errorf("failed to write known_hosts: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -166,7 +161,6 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -181,7 +175,6 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
|
||||
// run 5 times to trigger ban
|
||||
for i := 0; i < 3; i++ {
|
||||
c, stdin, stdout, err := runCmd(
|
||||
|
|
@ -197,7 +190,6 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
fmt.Sprintf("notexist_%v", i),
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("ssh fail")
|
||||
}
|
||||
|
|
@ -222,7 +214,6 @@ func TestFailtobanPipeCreateFail(t *testing.T) {
|
|||
"bypassword",
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -257,7 +248,6 @@ func TestFailtobanIgnoreIP(t *testing.T) {
|
|||
"--ignore-ip",
|
||||
"127.0.0.1",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -284,7 +274,6 @@ func TestFailtobanIgnoreIP(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -342,7 +331,6 @@ func TestFailtobanIgnoreIP(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -373,7 +361,6 @@ func TestFailtobanIgnoreCIDR(t *testing.T) {
|
|||
"--ignore-ip",
|
||||
"127.0.0.1/8",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -400,7 +387,6 @@ func TestFailtobanIgnoreCIDR(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -458,7 +444,6 @@ func TestFailtobanIgnoreCIDR(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
)
|
||||
|
||||
func TestOldSshd(t *testing.T) {
|
||||
|
||||
piperaddr, piperport := nextAvailablePiperAddress()
|
||||
|
||||
piper, _, _, err := runCmd("/sshpiperd/sshpiperd",
|
||||
|
|
@ -21,7 +20,6 @@ func TestOldSshd(t *testing.T) {
|
|||
"--target",
|
||||
"host-password-old:2222",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -63,7 +61,6 @@ func TestOldSshd(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo SSHREADY && sleep 1 && echo -n %v > /shared/%v"`, randtext, targetfie), // sleep 5 to cover https://github.com/tg123/sshpiper/issues/323
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
@ -81,7 +78,6 @@ func TestOldSshd(t *testing.T) {
|
|||
checkSharedFileContent(t, targetfie, randtext)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestHostkeyParam(t *testing.T) {
|
||||
|
|
@ -97,7 +93,6 @@ func TestHostkeyParam(t *testing.T) {
|
|||
"--target",
|
||||
"host-password:2222",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ func createRpcServer(r *rpcServer) net.Listener {
|
|||
}
|
||||
|
||||
func TestGrpcPlugin(t *testing.T) {
|
||||
|
||||
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to generate private key: %v", err)
|
||||
|
|
@ -180,7 +179,6 @@ func TestGrpcPlugin(t *testing.T) {
|
|||
"--testremotekey",
|
||||
base64.StdEncoding.EncodeToString(privKeyPem),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -196,7 +194,6 @@ func TestGrpcPlugin(t *testing.T) {
|
|||
},
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to connect to sshpiperd: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ func TestKubernetes(t *testing.T) {
|
|||
|
||||
for _, testcase := range pubkeycases {
|
||||
t.Run(testcase.title, func(t *testing.T) {
|
||||
|
||||
keyfiledir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create temp key file: %v", err)
|
||||
|
|
@ -52,11 +51,11 @@ func TestKubernetes(t *testing.T) {
|
|||
|
||||
keyfile := path.Join(keyfiledir, "key")
|
||||
|
||||
if err := os.WriteFile(keyfile, []byte(testprivatekey), 0400); err != nil {
|
||||
if err := os.WriteFile(keyfile, []byte(testprivatekey), 0o400); err != nil {
|
||||
t.Errorf("failed to write to test key: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile("/publickey_authorized_keys/authorized_keys", []byte(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRGTH325rDUp12tplwukHmR8ytbC9TPZ886gCstynP1`), 0400); err != nil {
|
||||
if err := os.WriteFile("/publickey_authorized_keys/authorized_keys", []byte(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRGTH325rDUp12tplwukHmR8ytbC9TPZ886gCstynP1`), 0o400); err != nil {
|
||||
t.Errorf("failed to write to authorized_keys: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +78,6 @@ func TestKubernetes(t *testing.T) {
|
|||
piperhost,
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
@ -115,7 +113,6 @@ func TestKubernetes(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, testcase := range passwordcases {
|
||||
|
||||
t.Run(testcase.title, func(t *testing.T) {
|
||||
randtext := uuid.New().String()
|
||||
targetfie := uuid.New().String()
|
||||
|
|
@ -134,7 +131,6 @@ func TestKubernetes(t *testing.T) {
|
|||
piperhost,
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
@ -147,7 +143,6 @@ func TestKubernetes(t *testing.T) {
|
|||
|
||||
checkSharedFileContent(t, targetfie, randtext)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -189,7 +184,6 @@ func TestKubernetes(t *testing.T) {
|
|||
piperhost,
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-fixed, %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@ func killCmd(c *exec.Cmd) {
|
|||
|
||||
func runAndGetStdout(cmd string, args ...string) ([]byte, error) {
|
||||
c, _, stdout, err := runCmd(cmd, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -167,7 +166,6 @@ func nextAvailablePiperAddress() (string, string) {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
if os.Getenv("SSHPIPERD_E2E_TEST") != "1" {
|
||||
log.Printf("skipping e2e test")
|
||||
os.Exit(0)
|
||||
|
|
|
|||
|
|
@ -9,14 +9,11 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "getmeta",
|
||||
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
|
||||
return &libplugin.SshPiperPluginConfig{
|
||||
PasswordCallback: func(conn libplugin.ConnMetadata, password []byte) (*libplugin.Upstream, error) {
|
||||
|
||||
target := conn.GetMeta("targetaddr")
|
||||
|
||||
host, port, err := libplugin.SplitHostPortForSSH(target)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "testplugin",
|
||||
Usage: "e2e test plugin only",
|
||||
|
|
@ -33,7 +32,6 @@ func main() {
|
|||
},
|
||||
},
|
||||
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
|
||||
rpcclient, err := rpc.DialHTTP("tcp", c.String("rpcserver"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "setmeta",
|
||||
Flags: []cli.Flag{
|
||||
|
|
@ -19,9 +18,7 @@ func main() {
|
|||
},
|
||||
CreateConfig: func(ctx *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
return &libplugin.SshPiperPluginConfig{
|
||||
|
||||
NoClientAuthCallback: func(conn libplugin.ConnMetadata) (*libplugin.Upstream, error) {
|
||||
|
||||
return &libplugin.Upstream{
|
||||
Auth: libplugin.CreateNextPluginAuth(map[string]string{
|
||||
"targetaddr": ctx.String("targetaddr"),
|
||||
|
|
|
|||
|
|
@ -14,14 +14,13 @@ import (
|
|||
const workingdir = "/shared/workingdir"
|
||||
|
||||
func ensureWorkingDirectory() {
|
||||
err := os.MkdirAll(workingdir, 0700)
|
||||
err := os.MkdirAll(workingdir, 0o700)
|
||||
if err != nil {
|
||||
log.Panicf("failed to create working directory %s: %v", workingdir, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkingDirectory(t *testing.T) {
|
||||
|
||||
piperaddr, piperport := nextAvailablePiperAddress()
|
||||
|
||||
piper, _, _, err := runCmd("/sshpiperd/sshpiperd",
|
||||
|
|
@ -31,7 +30,6 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
"--root",
|
||||
workingdir,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -46,11 +44,11 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
userdir := path.Join(workingdir, "bypassword")
|
||||
|
||||
{
|
||||
if err := os.MkdirAll(userdir, 0700); err != nil {
|
||||
if err := os.MkdirAll(userdir, 0o700); err != nil {
|
||||
t.Errorf("failed to create working directory %s: %v", userdir, err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-password:2222"), 0400); err != nil {
|
||||
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-password:2222"), 0o400); err != nil {
|
||||
t.Errorf("failed to write upstream file: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -62,12 +60,11 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
"2222",
|
||||
"host-password",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run ssh-keyscan: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
|
||||
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0o400); err != nil {
|
||||
t.Errorf("failed to write known_hosts: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +87,6 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -107,11 +103,11 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
|
||||
t.Run("bypublickey", func(t *testing.T) {
|
||||
userdir := path.Join(workingdir, "bypublickey")
|
||||
if err := os.MkdirAll(userdir, 0700); err != nil {
|
||||
if err := os.MkdirAll(userdir, 0o700); err != nil {
|
||||
t.Errorf("failed to create working directory %s: %v", userdir, err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-publickey:2222"), 0400); err != nil {
|
||||
if err := os.WriteFile(path.Join(userdir, "sshpiper_upstream"), []byte("user@host-publickey:2222"), 0o400); err != nil {
|
||||
t.Errorf("failed to write upstream file: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -122,12 +118,11 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
"2222",
|
||||
"host-publickey",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run ssh-keyscan: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0400); err != nil {
|
||||
if err := os.WriteFile(path.Join(userdir, "known_hosts"), b, 0o400); err != nil {
|
||||
t.Errorf("failed to write known_hosts: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -214,7 +209,6 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper-workingdir, %v", err)
|
||||
}
|
||||
|
|
@ -225,6 +219,5 @@ func TestWorkingDirectory(t *testing.T) {
|
|||
|
||||
checkSharedFileContent(t, targetfie, randtext)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,13 +83,12 @@ pipes:
|
|||
`
|
||||
|
||||
func TestYaml(t *testing.T) {
|
||||
|
||||
yamldir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
|
||||
yamlfile, err := os.OpenFile(path.Join(yamldir, "config.yaml"), os.O_RDWR|os.O_CREATE, 0400)
|
||||
yamlfile, err := os.OpenFile(path.Join(yamldir, "config.yaml"), os.O_RDWR|os.O_CREATE, 0o400)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp file: %v", err)
|
||||
}
|
||||
|
|
@ -192,7 +191,6 @@ func TestYaml(t *testing.T) {
|
|||
"2222",
|
||||
"host-publickey",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run ssh-keyscan: %v", err)
|
||||
}
|
||||
|
|
@ -203,7 +201,6 @@ func TestYaml(t *testing.T) {
|
|||
"2222",
|
||||
"host-password",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run ssh-keyscan : %v", err)
|
||||
}
|
||||
|
|
@ -241,7 +238,6 @@ func TestYaml(t *testing.T) {
|
|||
"--config",
|
||||
yamlfile.Name(),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to run sshpiperd: %v", err)
|
||||
}
|
||||
|
|
@ -267,7 +263,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -299,7 +294,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -331,7 +325,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -365,7 +358,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -397,7 +389,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -448,7 +439,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -482,7 +472,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -514,7 +503,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
@ -544,7 +532,6 @@ func TestYaml(t *testing.T) {
|
|||
"127.0.0.1",
|
||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to ssh to piper, %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ func TestDial(t *testing.T) {
|
|||
defer conn.Close()
|
||||
|
||||
go func() {
|
||||
|
||||
_, _ = conn.Write([]byte("hello"))
|
||||
}()
|
||||
buf := make([]byte, 5)
|
||||
|
|
|
|||
|
|
@ -164,7 +164,6 @@ func (s *server) Logs(req *StartLogRequest, stream SshPiperPlugin_LogsServer) er
|
|||
}
|
||||
|
||||
func (s *server) ListCallbacks(ctx context.Context, req *ListCallbackRequest) (*ListCallbackResponse, error) {
|
||||
|
||||
var cb []string
|
||||
|
||||
if s.config.NewConnectionCallback != nil {
|
||||
|
|
@ -362,7 +361,6 @@ func (s *server) KeyboardInteractiveAuth(stream SshPiperPlugin_KeyboardInteracti
|
|||
|
||||
return userInput.Answers[0], nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"go4.org/netipx"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
|
|
@ -13,6 +12,8 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"go4.org/netipx"
|
||||
|
||||
gocache "github.com/patrickmn/go-cache"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tg123/sshpiper/libplugin"
|
||||
|
|
@ -20,7 +21,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "failtoban",
|
||||
Usage: "failtoban plugin, block ip after too many auth failures",
|
||||
|
|
@ -51,7 +51,6 @@ func main() {
|
|||
},
|
||||
},
|
||||
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
|
||||
maxFailures := c.Int("max-failures")
|
||||
banDuration := c.Duration("ban-duration")
|
||||
logOnly := c.Bool("log-only")
|
||||
|
|
@ -133,7 +132,6 @@ func main() {
|
|||
}
|
||||
|
||||
func buildIPSet(cidrs []string) *netipx.IPSet {
|
||||
|
||||
var ipsetBuilder netipx.IPSetBuilder
|
||||
|
||||
for _, cidr := range cidrs {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "fixed",
|
||||
Usage: "sshpiperd fixed plugin, only password auth is supported",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "simplemath",
|
||||
Usage: "sshpiperd simplemath plugin, do math before ssh login",
|
||||
|
|
|
|||
|
|
@ -25,15 +25,12 @@ func parseTargetUser(raw string) (target string, username string, err error) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
|
||||
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
|
||||
Name: "username-router",
|
||||
Usage: "routing based on target inside username, format: 'target:port+realuser@sshpiper-host'",
|
||||
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
|
||||
|
||||
return &libplugin.SshPiperPluginConfig{
|
||||
PasswordCallback: func(conn libplugin.ConnMetadata, password []byte) (*libplugin.Upstream, error) {
|
||||
|
||||
address, user, err := parseTargetUser(conn.User())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid username format %q: %w", conn.User(), err)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func (p *plugin) checkPerm(filename string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if fi.Mode().Perm()&0077 != 0 {
|
||||
if fi.Mode().Perm()&0o077 != 0 {
|
||||
return fmt.Errorf("%v's perm is too open", filename)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,5 +54,4 @@ func TestYamlDecode(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Failed to unmarshal yaml: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue