Bug 1761765

Summary: Cannot lock down cockpit.service: avc: denied { mounton } / { nnp_transition }
Product: [Fedora] Fedora Reporter: Martin Pitt <mpitt>
Component: selinux-policyAssignee: Patrik Koncity <pkoncity>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: 31CC: dwalsh, lvrabec, mgrepl, plautrba, zpytela
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
URL: https://github.com/fedora-selinux/selinux-policy-contrib/commit/793708559184e44e7b7c93f47eb5860fcb1017fd
Whiteboard:
Fixed In Version: selinux-policy-3.14.4-39.fc31 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-10-29 01:27:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Martin Pitt 2019-10-15 10:24:01 UTC
Description of problem: I'm currently trying to lock down the permissions of cockpit.service (in version 205+ we can finally do that in a meaningful way).

But it seems some SELinux policy prevents using systemd's features like PrivateTmp=, ProtectHome=, and similar ones that set up a private mount namespace. Others that don't involve mount name spaces, like NoNewPrivileges=true or MemoryDenyWriteExecute=true do work.


Version-Release number of selected component (if applicable):

selinux-policy-3.14.4-35.fc31.noarch
cockpit-204-1.fc31

How reproducible: Always


Steps to Reproduce:
1. echo PrivateTmp=true >> /usr/lib/systemd/system/cockpit.service
2. systemctl daemon-reload; systemctl stop cockpit; systemctl start cockpit.socket
3. visit http://localhost:9090

Actual results: Browser fails with "The connection was reset", and journal shows errors:

audit[10307]: AVC avc:  denied  { mounton } for  pid=10307 comm="(emotectl)" path="/run/systemd/unit-root/run/cockpit/tls" dev="tmpfs" ino=59323 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:cockpit_var_run_t:s0 tclass=dir permissive=0

cockpit.service: Failed to set up mount namespacing: /run/systemd/unit-root/run/cockpit/tls: Permission denied

Expected results: cockpit.service starts and login works

This looks very similar for ProtectSystem=true and others.



I tried with the full glory:

User=cockpit-ws
Group=cockpit-ws
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
rivateTmp=true
PrivateDevices=true
ProtectKernelTunables=true
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
MemoryDenyWriteExecute=true

This works after `setenforce 0`. This shows another follow-up error which is also relevant:

AVC avc:  denied  { nnp_transition } for  pid=10443 comm="(kpit-tls)" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:cockpit_ws_t:s0 tclass=process2 permissive=1

Comment 1 Lukas Vrabec 2019-10-22 18:17:30 UTC
commit 793708559184e44e7b7c93f47eb5860fcb1017fd (HEAD -> rawhide, origin/rawhide, origin/HEAD)
Author: Patrik Koncity <pkoncity>
Date:   Tue Oct 22 17:24:10 2019 +0200

    Update cockpit policy
    
    Allow to systemd to use dir with file context cockpit_var_run_t as mount point
    Allow SELinux Domain trasition from sytemd into confined domain with NoNewPrivileges
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1761765

Comment 2 Martin Pitt 2019-10-22 19:16:15 UTC
Awesome, thank you Lukas!

Comment 3 Lukas Vrabec 2019-10-22 19:25:05 UTC
Kudos to Patrik. :) 

Fix will be part of next selinux-policy update. If you need some scratch builds we could provide them.

Comment 4 Fedora Update System 2019-10-26 16:59:16 UTC
FEDORA-2019-7d65c50fd6 has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2019-7d65c50fd6

Comment 5 Fedora Update System 2019-10-27 04:02:43 UTC
selinux-policy-3.14.4-39.fc31 has been pushed to the Fedora 31 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-7d65c50fd6

Comment 6 Martin Pitt 2019-10-28 06:55:12 UTC
The update works great, thank you! OOI, is this fix also aimed at Fedora 30?

Comment 7 Fedora Update System 2019-10-29 01:27:42 UTC
selinux-policy-3.14.4-39.fc31 has been pushed to the Fedora 31 stable repository. If problems still persist, please make note of it in this bug report.