Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFE] pesign.service: run as separate user #57

Open
dvzrv opened this issue Apr 26, 2020 · 2 comments
Open

[RFE] pesign.service: run as separate user #57

dvzrv opened this issue Apr 26, 2020 · 2 comments

Comments

@dvzrv
Copy link

dvzrv commented Apr 26, 2020

Hi! I'm currently maintaining pesign for Arch Linux.

When taking over the package from my predecessor I started to wonder about the pesign.service setup.
In its current state it is not possible to enable the service (#50) and its stdout/stderr is not sent to the journal (#49).

More puzzling for me is the pesign-authorize script though, as it sets ACLs

update_subdir() {
subdir=$1 && shift
setfacl -bk "${subdir}"
setfacl "${dirusers[@]}" "${dirgroups[@]}" "${subdir}"
for x in "${subdir}"* ; do
if [ -d "${x}" ]; then
setfacl -bk ${x}
setfacl "${dirusers[@]}" "${dirgroups[@]}" ${x}
update_subdir "${x}/"
elif [ -e "${x}" ]; then
setfacl -bk ${x}
setfacl "${fileusers[@]}" "${filegroups[@]}" ${x}
else
:;
fi
done
}

for arbitrary users
for user in $(cat /etc/pesign/users); do

and groups
for group in $(cat /etc/pesign/groups); do

on the runtime dir and config dir
for x in /var/run/pesign/ /etc/pki/pesign*/ ; do
if [ -d "${x}" ]; then
update_subdir "${x}"
else
:;
fi

This introduces the two following culprits:

  • pesign.service can not be run as a non-root user
  • users (or users in specific groups) can add more users or groups to the allowed set of users or groups (due to the /etc/pki/pesign*/ match) (whoops, those are set in /etc/pesign/)

From a security perspective this is rather suboptimal.

Maybe I'm not understanding the specific use-cases that you had in mind when creating the service, but in its current state it does not make sense for me to package the configuration files or the service, but rather to create a service file myself.

When looking at this from a classic sysadmin perspective, I'd assume that I would create a system user/group that runs the service and that I then either add any user of a system to said group to have access to what the service creates and that I optionally have a socket unit, that gives access to the socket, that the service creates/uses if this is a requirement for e.g. pesign-client (the latter is seemingly discussed in another context in #35).

Any suggestions or explanations in regards to my assumptions would be highly appreciated! :)

@dvzrv dvzrv changed the title calling pesign-authorize in pesign.service prevents it from running as a separate user and makes setup unsafe to use calling pesign-authorize in pesign.service prevents it from running as a separate user Apr 26, 2020
@dvzrv
Copy link
Author

dvzrv commented Apr 26, 2020

As a follow up, I was looking into the code-base (again, my understanding of this service might be insufficient) and found, that daemon.c prevents itself from being started by non-root users:

pesign/src/daemon.c

Lines 1162 to 1165 in cbc37d9

if (getuid() != 0) {
fprintf(stderr, "pesignd must be started as root");
exit(1);
}

Was this design choice made due to a specific reason as to how code-signing is implemented, or could this be changed to actually allow non-root system users to run pesign.service?

@vathpela
Copy link
Contributor

Was this design choice made due to a specific reason as to how code-signing is implemented, or could this be changed to actually allow non-root system users to run pesign.service?

I don't know any reason it couldn't be made to run as a non-root user. As to your first question - possibly just splitting the acl-setting out as its own one-shot service would work? The specific thing the daemon was built for was to provide a socket to talk to that could be bind-mounted into a chroot being used by builders, without having to plumb in all that's needed to do pkcs11 HSM hardware access with more than one chroot at a time.

I probably should have used (or made) some kind of pkcs11 proxy service instead.

@frozencemetery frozencemetery changed the title calling pesign-authorize in pesign.service prevents it from running as a separate user [RFE] pesign.service: run as separate user Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants