move e2e piper process manager to go code
This commit is contained in:
parent
57a57e89ef
commit
5e9f689999
8 changed files with 88 additions and 65 deletions
14
Dockerfile
14
Dockerfile
|
|
@ -10,22 +10,20 @@ COPY go.mod go.sum /cache/
|
||||||
WORKDIR /cache
|
WORKDIR /cache
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
RUN mkdir -p /out/plugins
|
RUN mkdir -p /sshpiperd/plugins
|
||||||
ADD . /src/
|
ADD . /src/
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /out -ldflags "-X main.mainver=$VER" ./cmd/...
|
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /sshpiperd -ldflags "-X main.mainver=$VER" ./cmd/...
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /out/plugins -ldflags "-X main.mainver=$VER" ./plugin/...
|
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /sshpiperd/plugins -ldflags "-X main.mainver=$VER" ./plugin/...
|
||||||
|
ADD entrypoint.sh /sshpiperd
|
||||||
|
|
||||||
FROM busybox
|
FROM busybox
|
||||||
LABEL maintainer="Boshi Lian<farmer1992@gmail.com>"
|
LABEL maintainer="Boshi Lian<farmer1992@gmail.com>"
|
||||||
|
|
||||||
COPY --from=ep76/openssh-static:latest /usr/bin/ssh-keygen /bin/ssh-keygen
|
COPY --from=ep76/openssh-static:latest /usr/bin/ssh-keygen /bin/ssh-keygen
|
||||||
RUN mkdir /etc/ssh/
|
RUN mkdir /etc/ssh/
|
||||||
RUN mkdir /sshpiperd
|
|
||||||
|
|
||||||
ADD entrypoint.sh /sshpiperd
|
COPY --from=builder /sshpiperd/ /sshpiperd
|
||||||
COPY --from=builder /out/ /sshpiperd
|
|
||||||
EXPOSE 2222
|
EXPOSE 2222
|
||||||
|
|
||||||
ENTRYPOINT ["/sshpiperd/entrypoint.sh"]
|
CMD ["/sshpiperd/entrypoint.sh"]
|
||||||
CMD ["/sshpiperd/sshpiperd", "/sshpiperd/plugins/workingdir"]
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
FROM golang:1.18-bullseye as builder
|
|
||||||
|
|
||||||
ARG VER=devel
|
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
|
||||||
|
|
||||||
RUN mkdir -p /cache/crypto
|
|
||||||
COPY crypto /cache/crypto
|
|
||||||
COPY go.mod go.sum /cache/
|
|
||||||
WORKDIR /cache
|
|
||||||
RUN go mod download
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
version: '3'
|
version: '3.4'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
host-password:
|
host-password:
|
||||||
|
|
@ -19,50 +19,23 @@ services:
|
||||||
- shared:/shared
|
- shared:/shared
|
||||||
- sshconfig_publickey:/config
|
- sshconfig_publickey:/config
|
||||||
|
|
||||||
piper-fixed:
|
|
||||||
environment:
|
|
||||||
- SSHPIPERD_LOG_LEVEL=trace
|
|
||||||
build: ../
|
|
||||||
command:
|
|
||||||
- "/sshpiperd/sshpiperd"
|
|
||||||
- "/sshpiperd/plugins/fixed"
|
|
||||||
- "--target"
|
|
||||||
- "host-password:2222"
|
|
||||||
depends_on:
|
|
||||||
- host-password
|
|
||||||
|
|
||||||
piper-workingdir:
|
|
||||||
environment:
|
|
||||||
- SSHPIPERD_LOG_LEVEL=trace
|
|
||||||
- SSHPIPERD_WORKINGDIR_STRICTHOSTKEY=true
|
|
||||||
volumes:
|
|
||||||
- shared:/shared
|
|
||||||
build: ../
|
|
||||||
command:
|
|
||||||
- "/sshpiperd/sshpiperd"
|
|
||||||
- "/sshpiperd/plugins/workingdir"
|
|
||||||
- "--root"
|
|
||||||
- "/shared/workingdir"
|
|
||||||
depends_on:
|
|
||||||
- host-password
|
|
||||||
- host-publickey
|
|
||||||
|
|
||||||
testrunner:
|
testrunner:
|
||||||
environment:
|
environment:
|
||||||
|
- SSHPIPERD_LOG_LEVEL=trace
|
||||||
- SSHPIPERD_E2E_TEST=1
|
- SSHPIPERD_E2E_TEST=1
|
||||||
build:
|
build:
|
||||||
context: ../
|
context: ../
|
||||||
dockerfile: e2e/Dockerfile_e2e
|
target: builder
|
||||||
volumes:
|
volumes:
|
||||||
- ..:/src
|
- ..:/src
|
||||||
- shared:/shared
|
- shared:/shared
|
||||||
- sshconfig_publickey:/sshconfig_publickey
|
- sshconfig_publickey:/sshconfig_publickey
|
||||||
- sshconfig_password:/sshconfig_password
|
- sshconfig_password:/sshconfig_password
|
||||||
command: ["bash", "-c", "if [ \"${SSHPIPERD_DEBUG}\" == \"1\" ]; then sleep infinity; else go test -v; fi"]
|
command: ["./e2eentry.sh"]
|
||||||
working_dir: /src/e2e
|
working_dir: /src/e2e
|
||||||
depends_on:
|
depends_on:
|
||||||
- piper-fixed
|
- host-publickey
|
||||||
- piper-workingdir
|
- host-password
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
shared:
|
shared:
|
||||||
|
|
|
||||||
10
e2e/e2eentry.sh
Executable file
10
e2e/e2eentry.sh
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# use entrypoint.sh to generate the ssh_host_rsa_key
|
||||||
|
PLUGIN="dummy_badname/" bash /sshpiperd/entrypoint.sh 2>/dev/null
|
||||||
|
|
||||||
|
if [ "${SSHPIPERD_DEBUG}" == "1" ]; then
|
||||||
|
sleep infinity;
|
||||||
|
else
|
||||||
|
go test -v;
|
||||||
|
fi
|
||||||
|
|
@ -9,7 +9,24 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFixed(t *testing.T) {
|
func TestFixed(t *testing.T) {
|
||||||
waitForEndpointReady("piper-fixed:2222")
|
|
||||||
|
piperaddr, piperport := nextAvailablePiperAddress()
|
||||||
|
|
||||||
|
piper, _, _, err := runCmd("/sshpiperd/sshpiperd",
|
||||||
|
"-p",
|
||||||
|
piperport,
|
||||||
|
"/sshpiperd/plugins/fixed",
|
||||||
|
"--target",
|
||||||
|
"host-password:2222",
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to run sshpiperd: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer killCmd(piper)
|
||||||
|
|
||||||
|
waitForEndpointReady(piperaddr)
|
||||||
|
|
||||||
randtext := uuid.New().String()
|
randtext := uuid.New().String()
|
||||||
targetfie := uuid.New().String()
|
targetfie := uuid.New().String()
|
||||||
|
|
@ -22,10 +39,10 @@ func TestFixed(t *testing.T) {
|
||||||
"-o",
|
"-o",
|
||||||
"UserKnownHostsFile=/dev/null",
|
"UserKnownHostsFile=/dev/null",
|
||||||
"-p",
|
"-p",
|
||||||
"2222",
|
piperport,
|
||||||
"-l",
|
"-l",
|
||||||
"user",
|
"user",
|
||||||
"piper-fixed",
|
"127.0.0.1",
|
||||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -125,6 +126,20 @@ func runAndGetStdout(cmd string, args ...string) ([]byte, error) {
|
||||||
return io.ReadAll(stdout)
|
return io.ReadAll(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func nextAvaliablePort() int {
|
||||||
|
l, err := net.Listen("tcp", ":0")
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
defer l.Close()
|
||||||
|
return l.Addr().(*net.TCPAddr).Port
|
||||||
|
}
|
||||||
|
|
||||||
|
func nextAvailablePiperAddress() (string, string) {
|
||||||
|
port := strconv.Itoa(nextAvaliablePort())
|
||||||
|
return net.JoinHostPort("127.0.0.1", (port)), port
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
if os.Getenv("SSHPIPERD_E2E_TEST") != "1" {
|
if os.Getenv("SSHPIPERD_E2E_TEST") != "1" {
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,26 @@ func ensureWorkingDirectory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWorkingDirectory(t *testing.T) {
|
func TestWorkingDirectory(t *testing.T) {
|
||||||
|
|
||||||
|
piperaddr, piperport := nextAvailablePiperAddress()
|
||||||
|
|
||||||
|
piper, _, _, err := runCmd("/sshpiperd/sshpiperd",
|
||||||
|
"-p",
|
||||||
|
piperport,
|
||||||
|
"/sshpiperd/plugins/workingdir",
|
||||||
|
"--root",
|
||||||
|
workingdir,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to run sshpiperd: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer killCmd(piper)
|
||||||
|
|
||||||
|
waitForEndpointReady(piperaddr)
|
||||||
|
|
||||||
ensureWorkingDirectory()
|
ensureWorkingDirectory()
|
||||||
waitForEndpointReady("piper-workingdir:2222")
|
|
||||||
|
|
||||||
t.Run("bypassword", func(t *testing.T) {
|
t.Run("bypassword", func(t *testing.T) {
|
||||||
userdir := path.Join(workingdir, "bypassword")
|
userdir := path.Join(workingdir, "bypassword")
|
||||||
|
|
@ -67,10 +85,10 @@ func TestWorkingDirectory(t *testing.T) {
|
||||||
"-o",
|
"-o",
|
||||||
"UserKnownHostsFile=/dev/null",
|
"UserKnownHostsFile=/dev/null",
|
||||||
"-p",
|
"-p",
|
||||||
"2222",
|
piperport,
|
||||||
"-l",
|
"-l",
|
||||||
"bypassword",
|
"bypassword",
|
||||||
"piper-workingdir",
|
"127.0.0.1",
|
||||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -189,12 +207,12 @@ func TestWorkingDirectory(t *testing.T) {
|
||||||
"-o",
|
"-o",
|
||||||
"UserKnownHostsFile=/dev/null",
|
"UserKnownHostsFile=/dev/null",
|
||||||
"-p",
|
"-p",
|
||||||
"2222",
|
piperport,
|
||||||
"-l",
|
"-l",
|
||||||
"bypublickey",
|
"bypublickey",
|
||||||
"-i",
|
"-i",
|
||||||
path.Join(keydir, "id_rsa"),
|
path.Join(keydir, "id_rsa"),
|
||||||
"piper-workingdir",
|
"127.0.0.1",
|
||||||
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
fmt.Sprintf(`sh -c "echo -n %v > /shared/%v"`, randtext, targetfie),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -euo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
|
if [ -z "$SSHPIPERD_SERVER_KEY" ]; then
|
||||||
if [ ! -f /etc/ssh/ssh_host_rsa_key ];then
|
if [ ! -f /etc/ssh/ssh_host_rsa_key ];then
|
||||||
ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key
|
ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec "$@"
|
PLUGIN=${PLUGIN:-workingdir}
|
||||||
|
|
||||||
|
exec /sshpiperd/sshpiperd /sshpiperd/plugins/$PLUGIN
|
||||||
Loading…
Add table
Add a link
Reference in a new issue