Skip to content

Auditd service fails to restart via systemd | Need an Alternative to manage it via legacy method like 'service', for example: service auditd restart #52256

Closed

Description

@Beginner77

Description of Issue/Question

While trying to manage auditd via service.running, it fails to restart whenever the conditional "watch" file has changes, due to a parameter RefuseManualStop which is set as "yes" by default.

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)
OS: CentOS 7.3 and above

Sample sls:

auditd_service:
service.running:
- name: auditd
- enable: True
- watch:
- file: /etc/audit/audit.rules

Versions Report

Salt Version:
Salt: 2018.3.4

Dependency Versions:
cffi: 1.6.0
cherrypy: Not Installed
dateutil: 1.5
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: 0.24.6
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.1
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pycryptodome: 3.4.3
pygit2: 0.24.2
Python: 2.7.5 (default, Jul 13 2018, 13:06:57)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4

System Versions:
dist: centos 7.5.1804 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-862.11.6.el7.x86_64
system: Linux
version: CentOS Linux 7.5.1804 Core

Activity

  1. added this to the Blocked milestone on Mar 20, 2019
  2. added
    pending-discussion
    on Mar 20, 2019
  3. garethgreenaway commented on Mar 20, 2019

    @garethgreenaway
    Contributor

    @Beginner77 Thanks for the report. A couple options I can think of, you can override the init system that is being used, this will override it for everything though: https://docs.saltstack.com/en/latest/ref/modules/index.html#module-provider-override

    You could also use a cmd.run to call out to the specific system you want to use to restart auditd.

    @saltstack/team-core Any other thoughts?

  4. waynew commented on Mar 20, 2019

    @waynew
    Contributor

    You could also use a cmd.run to call out to the specific system you want to use to restart auditd.

    That's also my initial thought. I'm not sure if there's a way to override the RefuseManualStop with systemd, but that might be something else worth looking into.

  5. garethgreenaway commented on Mar 20, 2019

    @garethgreenaway
    Contributor

    Another thought would be why it's not responding correctly to the restart. If you do the restart manually does it work as expected? Might be something to kick back to CentOS as an upstream bug.

  6. Beginner77 commented on Mar 21, 2019

    @Beginner77
    Author

    First of all, I would like to thank all of you for the quick responses :)

    Now, addressing each one of your solutions/workarounds,

    @garethgreenaway manually, it works when I use the command 'service auditd restart', and when I use systemctl/systemd, it fails to start, with the message, "Operation refused, unit auditd.service may be requested by dependency only.". I know this can be changed by changing the value of RefuseManualStop to "no" or commenting it out altogether from the service, but as per RedHat, it is a feature and not a bug, because systemd communicates with the process via dbus, and the auid being logged via systemd is -1, leading to misleading audit logs, and I might not be able to figure which process/person performed the operation of restarting auditd, which is wrong as far as auditing is concerned. This has been addressed in detail in this link - https://www.redhat.com/archives/linux-audit/2013-July/msg00048.html

    The document link you provided for module provider overriding looks good, and on reading it I think I can use this to manually override init though I'll have to read it further to understand how I can go about doing this.

    @waynew @garethgreenaway yea, I know I can alter my sample sls and use cmd.run and use 'service auditd restart' in the name section based on some file (onchanges). We could also change the RefuseManualStop parameter while running the state for auditd, and go about these changes via the saltmaster on environment basis, but as I stated earlier, this is a feature and not a bug in auditd. Also, on discussing this with my seniors, and also stating my inner instincts, we want to go about this via service.running, as we have been using purely saltstack based providers in provisioning, and never needed to alter the provided functionalities and use some workarounds. This is somewhat of a rarest of the rare cases, and that is why I raised a request here. Ansible has addressed this though, as per their documents and discussion forums, and I was hoping this can be done with saltstack as well.

    I would read the module provider override and further understand its functioning, in the meanwhile placing a request with you guys to see whether a functionality can be provided within salt to manage auditd separately.

  7. Beginner77 commented on Mar 21, 2019

    @Beginner77
    Author

    The module provider override link says that the override can be done in the minion config file, and this would be a system level config, I assume. I want that for audit the legacy/traditional service command is used to manage, while for other services, it should be based on the detected OS. Module provider override might not work for my case.

  8. stale commented on Jan 8, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  9. OrangeDog commented on Nov 8, 2022

    @OrangeDog
    Contributor

    RedHat have done this on purpose in order to be able to capture the details of where the service calls are coming from.
    It doesn't look like they're ever going to change it so you can manage auditd with systemctl.

    Ansible solved this by adding a per-invocation override of the service system: ansible/ansible#22171

    Salt could consider a similar feature, or continue with the workarounds given above.

  10. added
    Feature
    Platform
    and removed
    pending-discussion
    on Nov 8, 2022
  11. removed this from the Blocked milestone on Nov 8, 2022
  12. MKLeb commented on Nov 28, 2022

    @MKLeb
    Contributor

    Does using something like a providers override help? This is unlike the module provider override in that it is more granular, only existing as an override for the state it is used in. As far as I can tell, it solves the problem in a similar way to how ansible does. I was able to get it to invoke linux_service using the method described here: https://docs.saltproject.io/en/latest/ref/states/providers.html (provider should be linux_service).

    Note: From what I can see, salt doesn't actually run the service command. Instead, it just wraps around the sysvinit scripts.

  13. MKLeb commented on Aug 22, 2023

    @MKLeb
    Contributor

    @Beginner77 I am going to close this for now, given the potential solution above. If you still believe this is a valid issue, feel free to re-open it and I will investigate further :)

  14. OrangeDog commented on Aug 22, 2023

    @OrangeDog
    Contributor

    @MKLeb that changes the provider for everything. The feature request is to be able to change the provider for a single state, which is something Ansible has.

    This is still a valid feature request, and there is no particular reason (outside of available time) not to implement it.

  15. MKLeb commented on Aug 22, 2023

    @MKLeb
    Contributor

    @OrangeDog , as per the documentation linked in one of my previous comments...

    This change only affects this one state though. If it is necessary to make this override for most or every service, it is better to just override the provider in the minion config file, as described [here](https://docs.saltproject.io/en/latest/ref/modules/index.html#module-provider-override).
    

    If you have other knowledge of this not working as intended, please let me know and we can work on getting an issue filed for a bug in that behavior.

  16. OrangeDog commented on Aug 22, 2023

    @OrangeDog
    Contributor

    Oh! Yes this feature was already added in 0.9.8.
    FYI @garethgreenaway who also missed it.

    Some documentation alterations may be necessary so people can find that.

  17. OrangeDog commented on Aug 22, 2023

    @OrangeDog
    Contributor

    @Beginner77 try this:

    auditd:
      service.running:
        - provider: service
        - watch:
          - file: /etc/audit/audit.rules
  18. b-a-t commented on Oct 16, 2025

    @b-a-t

    I'll leave this for reference if someone stumbles upon this issue.

    @OrangeDog wrote:

    try this:

    auditd:
    service.running:
    - provider: service
    - watch:
    - file: /etc/audit/audit.rules

    Unfortunately, while an excellent idea by itself, due to current implementation details, it won't work OOTB. For the start, we need to specify the rh_service provider, as service by itself is a generic dispatcher, which would again pick up systemd_service.

    But, even after specifying the right provider, it wouldn't load, as the initialisation code for rh_service has constraints that block it on systemd enabled systems:

        # Disable when booted with systemd
        if __utils__["systemd.booted"](__context__):
            return (
                False,
                "The rh_service execution module failed to load: this system was booted"
                " with systemd.",
            )
    

    Moreover, even if we remove this check, there is another one below that won't let you run this module on anything greater than RHEL6:

                if osrelease_major >= 7:
                    return (
                        False,
                        "RedHat-based distros >= version 7 use systemd, will not "
                        "load rh_service.py as virtual 'service'",
                    )
    

    If we remove that constraint (overall, this logic should be implemented in the service dispatching module, IMHO), the provider override would actually get enabled. But that wouldn't solve this particular problem, as rh_service itself uses chkconfig --list service to verify that the given service is present. But on a systemd managed OS (almost) all services are not configured in init style, so the check will always fail:

    [ERROR   ] The named service auditd is not available
    
    ----------
              ID: auditd_svc
        Function: service.running
          Result: False
         Comment: The named service auditd is not available
         Started: 02:38:56.775284
        Duration: 132.034 ms
         Changes:
    

    At this point, I just gave up on the idea of overriding provider for auditd and implemented service.running functionality in a dumb way, like:

    auditd_svc:
      cmd.run:
        - name: "service auditd restart"
        - watch:
          - file: /etc/audit/audit.rules
        - unless:
          - fun: service.status
            name: auditd.service
    

    It's not ideal, but it solves the initial problem of restarting auditd on RHEL systems.

    And, BTW, you need to run service auditd restart, without specifying .service extension, otherwise systemctl will be called directly with the bogus result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FeaturePlatformState-Module

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions