FS#67173 - [gitlab] systemd sandboxing breaks secret file creation, prevents puma from starting
Attached to Project:
Community Packages
Opened by Matt Stickney (mtstickney) - Thursday, 02 July 2020, 06:09 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:01 GMT
Opened by Matt Stickney (mtstickney) - Thursday, 02 July 2020, 06:09 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:01 GMT
|
Details
Description:
The gitlab-puma service uses ProtectSystem=full, which means that /usr and /etc are mounted read-only for the puma server. If gitlab-puma needs to write secret files (like gitlab_workhorse_secret), which are linked from /usr/share/webapps/gitlab/ to /etc/webapps/gitlab, this will fail with a "read-only FS" error, and gitlab-puma will fail to start. I've verified that starting gitlab-puma manually (as the gitlab user, using the environment file, etc.) is able to write the files without issue. If the file exists, and has valid content in it (i.e. not an empty file), gitlab-puma won't try to create it, and you won't run into the problem. This is probably how it's gone under the radar until now. Initially I thought using ProtectSystem=true would be better option (since /etc would then be writable), but my testing shows that writing to a symlink in a read-only fs will fail, even if the link points to a writable fs, so I'm not sure that any version of ProtectSystem can be used. Additional info: Package version: 13.1.1-1 Log entries of the failure (journalctl -u gitlab-puma): Jul 02 01:51:10 palladium gitlab-puma[1336081]: {"timestamp":"2020-07-02T05:51:10.458Z","pid":1336081,"message":"! Unable to load application: Errno::EROFS: Read-only file system @ rb_sysopen - /usr/share/webapps/gitlab/.gitlab_workhorse_secret"} Jul 02 01:51:10 palladium gitlab-puma[1336081]: bundler: failed to load command: puma (/usr/share/webapps/gitlab/vendor/bundle/ruby/2.7.0/bin/puma) Jul 02 01:51:10 palladium gitlab-puma[1336081]: Errno::EROFS: Read-only file system @ rb_sysopen - /usr/share/webapps/gitlab/.gitlab_workhorse_secret Steps to reproduce: 1. Attempt to start the gitlab-puma service 2. Have service fail to start after several attempts, see failure messages in journal |
This task depends upon
Closed by Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:01 GMT
Reason for closing: Moved
Additional comments about closing: https://gitlab.archlinux.org/archlinux/p ackaging/packages/gitlab/issues/2
Saturday, 25 November 2023, 20:01 GMT
Reason for closing: Moved
Additional comments about closing: https://gitlab.archlinux.org/archlinux/p ackaging/packages/gitlab/issues/2
Opening /etc for writing to a service opens up an avenue for possible security breaches. I would much prefer to keep /etc read-only.
Actually it reminds me one packaging thing that itches me for a while. /etc is suppose to be kind of an input "administrator->service". Services should not really keep any service data/transnational data in /etc. There is /var/ directory for it.
So my question is do files like "gitlab_workhorse_secret secret secrets.yml" really belong to "/etc/webapps/gitlab/". Are these files something that is managed by an administrator? If not I would move the files to /var/lib/gitlab instead.
I'm just noticing that systemd has ReadWritePaths, which would presumably let us make /usr/share/webapps/gitlab writable for gitlab-puma. I _think_ that's all we need, since gitlab-shell isn't doing filesystem-protection stuff, /usr/share/webapps/gitlab-shell should be writable for it anyway.
[1] This is actually problematic itself, because it means everybody who installs a particular build of this package is using the same encryption keys. I couldn't find where in their code they generate this, so I don't know if it can be done at install-time or not.
Users of the Arch package have to manually create /etc/webapps/gitlab/secrets.yml, /etc/webapps/gitlab/secret and /etc/webapps/gitlab-shell/secret anyway (see https://wiki.archlinux.org/index.php/GitLab#Secret_strings), so I don't think adding more files to this list is a considerable hassle. But if you decide that some file should be writable by gitlab, I'd prefer moving it to /var/lib/gitlab instead of making some subdirs in /etc or /usr/share writable.
gitlab_workhorse_secret and secret really are just auth tokens (see https://gitlab.com/gitlab-org/gitlab-foss/-/blob/6ff3eb60e3ddbfe7450b760efe57112ddacbdb69/doc/development/internal_api.md#authentication); the only reason an admin would need to set them is if they're running several instances of the rails server on separate machines that all need to talk to the same gitlab-shell/gitlab-gitaly instances (see https://gitlab.com/gitlab-org/gitlab-foss/-/blob/082b24b03bbb9dca7edf1341aa7b0a51c9aeb18b/doc/administration/high_availability/gitlab.md#extra-configuration-for-additional-gitlab-application-servers). If they're in /var/lib, an admin can still set those by creating the file, but that's a pretty specialty case. Also note they're not intended to be included in backups, unlike secrets.yml, so they're not quite like regular config data.
The good news is that I was mistaken with my earlier tests: you _can_ write to a symlink in a read-only fs, so we don't need ReadWritePaths, and changing the symlinks to /var/lib would be sufficient for secret and gitlab_workhorse_secret.
The bad news is that apparently gitlab will attempt to generate/write to secrets.yml -- see https://gitlab.com/gitlab-org/gitlab-foss/-/blob/d081e00aa79079792b040af3323883f1f43830c5/config/initializers/01_secret_token.rb#L38 and discussion at https://gitlab.com/gitlab-org/gitlab/-/issues/222690 -- if I read it right, this happens whenever a secret the app wants is missing. That means the server might fail to start after an upgrade, but I don't think there's a big problem with requiring the user to create new secrets if necessary. It'd be great if upstream had a way to do that in a postinstall step, but...
The only "secret" file contained in the Arch packages is /etc/webapps/gitlab-shell/secret, but it is empty by default (the user has to set the secret string, see the previous link to the wiki).
https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/gitlab-shell#n78
I disagree about ReadWritePaths (or rather, about using symlinks): altering the config file is only useful for new installs, and doesn't do anything for upgraded systems (i.e. the fix requires user intervention). Fixing the symlinks works for both. I agree that having to use symlinks for those files is kind of ridiculous, but that's due to upstream badness.
gitlab-shell appears to be doing both things? It's creating a symlink from /usr/share/webapp/gitlab-shell/.gitlab_shell_secret to /etc/webapps/gitlab-shell/secret (https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/gitlab-shell#n82), but then it alters the config to use 'secret_file: /var/lib/gitlab/gitlab-shell/.gitlab_shell_secret' (https://git.archlinux.org/svntogit/community.git/tree/trunk/configs.patch?h=packages/gitlab-shell#n49), so that wiki step isn't actually doing anything for gitlab-shell. Whatever we do, we should definitely pick _one_ approach.
https://wiki.archlinux.org/index.php/System_maintenance#Deal_promptly_with_new_configuration_files
About gitlab-shell: all paths actually lead to the same file in /etc/webapps/gitlab-shell/secret, because /var/lib/gitlab/gitlab-shell is actually a symlink to /usr/share/webapps/gitlab-shell ...