Author | Jakob Wakeling <[email protected]> |
Date | 2025-01-04 04:24:50 |
Commit | de239c08420f9e6dec68d1283f3ebf03c639ee5b |
Parent | 77702b3600a7874e489fd943eeb51a85ea9fc0cb |
Update Containerfile for SSH support
Diffstat
M | Containerfile | | | 21 | ++++++++++++++++++--- |
M | src/goit/ssh.go | | | 4 | ++++ |
2 files changed, 22 insertions, 3 deletions
diff --git a/Containerfile b/Containerfile index 5ae7b6f..cb29de6 100644 --- a/Containerfile +++ b/Containerfile @@ -10,10 +10,25 @@ RUN VERSION=$version make build FROM alpine:latest RUN apk update RUN apk upgrade -RUN apk add --no-cache git +RUN apk add --no-cache git openssh COPY --from=build /app/bin /app/bin -RUN mkdir -p /run/user/0 +RUN ln -s /app/bin/goit-shell /usr/local/bin/goit-shell +RUN ssh-keygen -A +RUN sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config +RUN addgroup -g 973 -S git +RUN adduser -g git -s /bin/sh -G git -S -u 973 git +RUN sed -i 's/^git:!:/git:*:/' /etc/shadow +RUN mkdir -p /home/git/.config /home/git/.local/share /home/git/.local/state +RUN chown -R git:git /home/git/.config /home/git/.local WORKDIR /app EXPOSE 8080 +EXPOSE 22 VOLUME /etc/goit /var/lib/goit /var/log/goit -ENTRYPOINT ["/app/bin/goit"] + +RUN cat <<EOF > /app/bin/launch.sh +#!/bin/sh +/usr/sbin/sshd -D & +su -c /app/bin/goit git +EOF + +ENTRYPOINT ["sh", "/app/bin/launch.sh"] diff --git a/src/goit/ssh.go b/src/goit/ssh.go index 5de11d0..f4adb1c 100644 --- a/src/goit/ssh.go +++ b/src/goit/ssh.go @@ -20,6 +20,10 @@ func UpdateAuthorizedKeys() error { log.Println("Updating SSH authorized keys file") + if err := os.MkdirAll(filepath.Join(os.Getenv("HOME"), ".ssh"), 0700); err != nil { + return err + } + f, err := os.Create(filepath.Join(os.Getenv("HOME"), ".ssh", "authorized_keys")) if err != nil { return err