saltstack / saltstack/salt

SELinux component of file modules fails in presence of equivalency-rules on RHEL 8

Open
#62,875 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage RHEL
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description of Issue

Attempts to create files with appropriate SELinux contexts fails if there is an equivalency rule in place

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)

As part of implementing hardening-prescriptions, am attempting to override a systemd-managed mount's mount-options using:

file_mount_options:
  file.managed:
    - name: '/etc/systemd/system/tmp.mount.d/options.conf'
    - user: 'root'
    - grou: 'root'
    - mode: '0644'
    - makedirs: True
    - dir_mode: '0755'
    - selinux:
        seuser: system_u
        serole: object_r
        setype: systemd_unit_file_t
        serange: s0
    - contents: |-
        [Mount]
        Options=mode=1777,strictatime,nodev, noexec,nosuid

State (partially) fails with the alert:

[ERROR   ] Command 'semanage' failed with return code: 1
[ERROR   ] stderr: ValueError: File spec /etc/systemd/system/tmp.mount.d/options.conf conflicts with equivalency rule '/etc/systemd/system /usr/lib/systemd/system'; Try adding '/usr/lib/systemd/system/tmp.mount.d/options.conf' instead
[ERROR   ] retcode: 1
[ERROR   ] Unable to manage file: Problem setting fcontext: {'pid': 1839, 'retcode': 1, 'stdout': '', 'stderr': "ValueError: File spec /etc/systemd/system/tmp.mount.d/options.conf conflicts with equivalency rule '/etc/systemd/system /usr/lib/systemd/system'; Try adding '/usr/lib/systemd/system/tmp.mount.d/options.conf' instead"}

I parenthetically say "partially" because it successfully creates the file…

# ls -lZd /etc/systemd/system/tmp.mount.d/options.conf
-rw-r--r--. 1 root root unconfined_u:object_r:systemd_unit_file_t:s0 58 Oct 12 18:46 /etc/systemd/system/tmp.mount.d/options.conf

…but vomits when attempting to set an appropriate fcontext (thus the fcontext's user-token not being properly set.

The default fcontexts look like:

# semanage fcontext -l | grep -E '^(/etc|/usr/lib)/systemd/system'
/usr/lib/systemd/system(/.*)?                      all files          system_u:object_r:systemd_unit_file_t:s0
[...elided...]
/etc/systemd/system = /usr/lib/systemd/system

While there are a number of more-specific /usr/lib/systemd/system mappings, none are relevant to either a *.mount.d, options.conf or even *.conf file-path.

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

See prior section.

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

# /usr/bin/salt-call --versions-report
Salt Version:
          Salt: 3004.2

Dependency Versions:
          cffi: 1.11.5
      cherrypy: Not Installed
      dateutil: 2.6.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.14
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: Not Installed
        Python: 3.6.8 (default, Jun 14 2022, 12:54:58)
  python-gnupg: Not Installed
        PyYAML: 3.12
         PyZMQ: 19.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: rhel 8.6 Ootpa
        locale: UTF-8
       machine: x86_64
       release: 4.18.0-372.26.1.el8_6.x86_64
        system: Linux
       version: Red Hat Enterprise Linux 8.6 Ootpa

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Salt's file.managed SELinux handling and the semanage invocation described in the report; reproduce on RHEL 8 with the /etc/systemd/system equivalency rule. Trace how the target path is converted into an fcontext specification, then verify the file is created without the conflict and receives the intended SELinux user token.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
devops, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.