diff options
| author | dev <dev@example> | 2026-11-13 21:32:38 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-13 21:32:38 +0000 |
| commit | 47c9b98ea3fb91833d6d0847fa4345fa23593a97 (patch) | |
| tree | 3b68994aa774e9b758f8cb2296770a49adef87d7 /container/Dockerfile | |
| parent | 2b53cf54acd3d84bd6edfd0b98cf58794e30ec7d (diff) | |
| download | access-control-47c9b98ea3fb91833d6d0847fa4345fa23593a97.tar.gz access-control-47c9b98ea3fb91833d6d0847fa4345fa23593a97.zip | |
container: the host, built from the program's own install
The image is two stages: one compiles, runs the suite and installs into a
staging root, the other is the host and receives that staging root whole. The
reason for the copy-whole is that the paths in the image are then the paths
`make install` produces - including the hook symlink and its relative target -
rather than a second list of destinations kept in a Dockerfile, which is how an
image and a build start to disagree about where the hook is.
The build stage is Alpine so the binary is musl-linked like the rest of the
runtime image; a glibc binary would fail as "no such file" about a file that is
plainly there. `make test` runs in that stage, so an image built from a tree
whose tests fail does not get to exist.
The lighttpd config, sshd config, CGI shim, cgitrc and the two operator tools
come from the shell implementation, with the comments corrected: there is no
refcheck any more, and the hook the comments point at is now a symlink to this
binary. Nothing about the wiring changed, which is the point - the C program
drops into a host that was already built around one hook and one policy file.
Diffstat (limited to 'container/Dockerfile')
| -rw-r--r-- | container/Dockerfile | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/container/Dockerfile b/container/Dockerfile new file mode 100644 index 0000000..e73ed34 --- /dev/null +++ b/container/Dockerfile @@ -0,0 +1,96 @@ +# git-host on top of the C program. +# +# podman build -t git-host-c . +# +# Two stages, because the runtime image has no business carrying a compiler. +# The build stage compiles, runs the test suite, and installs into a staging +# root; the runtime stage copies that staging root wholesale, so the paths in +# the image are the paths `make install` produces - including the hook symlink +# and its relative target - rather than a second list of destinations kept here, +# which is how an image and a build start to disagree. +# +# The build stage is Alpine so that git-authz is musl-linked like everything +# else in the runtime image. A glibc binary built on the machine doing the +# building would not run in there, and would announce itself as "no such file" +# for a file that is plainly present. +# +# The build context is the program's directory, with this file in container/: +# +# podman build -t git-host-c -f container/Dockerfile . + +FROM alpine:3.22.4 AS build +RUN apk add --no-cache build-base +WORKDIR /src +COPY Makefile README authz.conf ./ +COPY src ./src +COPY build ./build +COPY tests ./tests +# The suite runs in the image it ships in, against the musl build: that is the +# only place the two are guaranteed to meet, and an image built from a tree +# whose tests fail should not exist. +RUN make -j2 && make test && make install DESTDIR=/install + + +FROM alpine:3.22.4 + +# git-daemon is not a typo: it is the package that ships git-http-backend and +# git-shell. +RUN apk add --no-cache \ + cgit \ + git \ + git-daemon \ + lighttpd \ + lighttpd-mod_auth \ + openssh-server \ + tini + +RUN addgroup -g 1000 -S git \ + && adduser -u 1000 -S -D -G git -h /var/lib/git -s /usr/bin/git-shell git \ + && adduser git tty \ + && passwd -u git \ + && mkdir -p \ + /etc/git-host/secrets \ + /usr/local/libexec \ + /var/lib/git \ + /run/git-host/secrets \ + /run/lighttpd \ + /run/sshd \ + /var/tmp/lighttpd \ + /var/www/localhost/htdocs \ + && chown -R git:git /var/lib/git + +# The binary, the hook symlink beside it, and the example policy, all placed by +# the program's own installer. +COPY --from=build /install/ / + +COPY container/create-repo /usr/local/bin/create-repo +COPY container/git-host-key /usr/local/bin/git-host-key +COPY container/entrypoint.sh /usr/local/bin/entrypoint.sh + +# lighttpd's mod_cgi dispatches by extension, so /git needs a *.cgi door. It +# only execs the stock backend, leaving REMOTE_USER for the hooks to find. +COPY container/git-http-backend.cgi /usr/local/libexec/git-http-backend.cgi + +COPY container/sshd_config /etc/ssh/sshd_config +COPY container/cgitrc /etc/cgitrc +COPY container/lighttpd.conf /etc/lighttpd/lighttpd.conf +COPY container/auth.conf /etc/lighttpd/auth.conf +COPY container/healthz /var/www/localhost/htdocs/healthz + +RUN chmod 0755 \ + /usr/local/bin/entrypoint.sh \ + /usr/local/bin/git-host-key \ + /usr/local/bin/create-repo \ + /usr/local/libexec/git-http-backend.cgi \ + && chmod 0644 /etc/git-host/authz.conf \ + && chown git:git /var/lib/git /run/lighttpd /var/tmp/lighttpd /var/www/localhost/htdocs \ + && chmod 0755 /run/git-host /run/git-host/secrets \ + && git config --file /etc/gitconfig core.hooksPath /usr/local/share/git-host/hooks \ + && grep -q "^git:" /etc/passwd \ + && lighttpd -tt -f /etc/lighttpd/lighttpd.conf \ + && /usr/local/bin/git-authz validate --no-host + +EXPOSE 8080 2222 +VOLUME ["/var/lib/git"] + +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"] |
