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

Allow init read all non-security socket files #1577

Merged
merged 1 commit into from Dec 15, 2023

Conversation

zpytela
Copy link
Contributor

@zpytela zpytela commented Jan 27, 2023

This permission is required when LoadCredential is set to point to a socket file for providing credentials to a service:

LoadCredential=id:/run/wg-credentials.socket

Systemd in its read_full_file_full() function checks exit code of xfopenat() and in case of -ENXIO connects to the AF_UNIX socket.

The files_read_non_security_sock_files() interface was added.

Addresses the following AVC denial:
type=AVC msg=audit(1672210323.355:1362): avc: denied { read } for pid=4490 comm="(sd-mkdcreds)" name="wg-credentials.socket" dev="tmpfs" ino=1033 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=sock_file permissive=0

Systemd uses the LoadCredential option to pass a credential to the unit.
Credentials here are small objects that may be passed to unit processes,
typically  cryptographic keys or certificates, user account information
or identity information from host to services.
The credential files/IPC sockets must be accessible to the service manager,
but don't have to be directly accessible to the unit's processes: the
credential data is read and copied into separate, read-only copies for
the unit that are accessible to appropriately privileged processes.

Consequently, when LoadCredential is set to point to a socket file,
systemd needs the read permission for the sock_file security class:

LoadCredential=id:/run/wg-credentials.socket

Systemd in its read_full_file_full() function checks exit code of
xfopenat() and in case of -ENXIO connects to the AF_UNIX socket.

The files_read_non_security_sock_files() interface was added.

Addresses the following AVC denial:
type=AVC msg=audit(1672210323.355:1362): avc:  denied  { read } for  pid=4490 comm="(sd-mkdcreds)" name="wg-credentials.socket" dev="tmpfs" ino=1033 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=sock_file permissive=0
@umglurf
Copy link

umglurf commented Jan 29, 2023

Hi, I installed the rpm from the build and got one step further, but there is now a new block for connect

type=AVC msg=audit(1674992652.819:336): avc:  denied  { connectto } for  pid=1225 comm="(sd-mkdcreds)" path="/run/wg-credentials.socket" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:unconfined_service_t:s0 tclass=unix_stream_socket permissive=0

@zpytela
Copy link
Contributor Author

zpytela commented Jan 30, 2023

@umglurf, is this a custom service, not in Fedora?

@umglurf
Copy link

umglurf commented Jan 30, 2023

@umglurf, is this a custom service, not in Fedora?

Hi, that is correct, it's a service I've written, but I think this would be the same issue with services in Fedora. I can create a small demo service if that would be helpful?

@zpytela
Copy link
Contributor Author

zpytela commented Jan 30, 2023

That'd be nice. If a similar AVC appears, the following module should help:

cat local_init_connect_domain.cil
(allow init_t domain (unix_stream_socket (connectto))
semodule -i local_init_connect_domain.cil

@umglurf
Copy link

umglurf commented Jan 30, 2023

That'd be nice.

I've attached a simple credential server that just always returns foobar, it requires python3-systemd, otherwise nothing but python3.
test-socket.tar.gz

If a similar AVC appears, the following module should help:

cat local_init_connect_domain.cil
(allow init_t domain (unix_stream_socket (connectto))
semodule -i local_init_connect_domain.cil

That worked.

@umglurf
Copy link

umglurf commented Jun 3, 2023

@zpytela any update on this PR?

@zpytela zpytela merged commit 52cbc15 into fedora-selinux:rawhide Dec 15, 2023
@zpytela zpytela deleted the sd-creds-sockets branch December 15, 2023 17:41
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

Successfully merging this pull request may close these issues.

None yet

2 participants