When I configured forgejo-actions
I used a docker-compose.yaml
file to execute the runner
and a dind
container
configured to run using privileged mode to be able to build images with it; as mentioned on my
post about my
setup, the use of the privileged mode is not a big issue for my use case, but reduces the overall security of the
installation.
On a work chat the other day someone mentioned that the GitLab documentation about
using kaniko says it is no longer maintained (see the kaniko
issue
#3348) so we should look into alternatives for kubernetes
clusters.
I never liked kaniko
too much, but it works without privileged mode and does not need a daemon, which is a good reason
to use it, but if it is deprecated it makes sense to look into alternatives, and today I looked into some of them to use
with my forgejo-actions
setup.
I was going to try buildah and podman but it seems that they need to adjust things on the systems running them:
- When I tried to use
buildah
inside adocker
container in Ubuntu I found the problems described on thebuildah
issue #1901 so I moved on. - Reading the
podman
documentation I saw that I need to export thefuse
device to run it inside a container and, as I found other option, I also skipped it.
As my runner
was already configured to use dind
I decided to look into sysbox
as a way of removing the privileged
flag to make things more secure but have the same functionality.
Installing the sysbox
package
As I use Debian and Ubuntu systems I used the .deb
packages distributed from the sysbox
release page to install
it (in my case I used the one from the 0.6.7 version).
On the machine running forgejo
(a Debian 12 server) I downloaded the package, stopped the running containers (it is
needed to install the package and the only ones running where the ones started by the docker-compose.yaml
file) and
installed the sysbox-ce_0.6.7.linux_amd64.deb
package using dpkg
.
Updating the docker-compose.yaml
file
To run the dind
container without setting the privileged
mode we set sysbox-runc
as the runtime
on the dind
container definition and set the privileged flag to false
(it is the same as removing the key, as it defaults to
false
):
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,7 +2,9 @@ services:
dind:
image: docker:dind
container_name: 'dind'
- privileged: 'true'
+ # use sysbox-runc instead of using privileged mode
+ runtime: 'sysbox-runc'
+ privileged: 'false'
command: ['dockerd', '-H', 'unix:///dind/docker.sock', '-G', '$RUNNER_GID']
restart: 'unless-stopped'
volumes:
Testing the changes
After applying the changes to the docker-compose.yaml
file we start the containers and to test things we re-run
previously executed jobs to see if things work as before.
In my case I re-executed the build-image-from-tag
workflow
#18 from the oci
project and everything worked as expected.
Conclusion
For my current use case (docker
+ dind
) seems that sysbox
is a good solution but I’m not sure if I’ll be
installing it on kubernetes anytime soon
unless I find a valid reason to do it (last time we talked about it my co workers said that they are evaluating
buildah
and podman
for kubernetes and probably we will use them to replace kaniko
in our gitlab-ci
pipelines and
for those tools the use of sysbox
seems an overkill).