[RESOLVED] Local administrator audit packages for Linux and macOS

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
bastien30
Messages: 38
Registration: March 8, 2024 - 3:21 PM

January 7, 2026 - 12:56

Good morning,

Here are packages for auditing local administrators under Linux and MacOS.

Linux:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

# Define allowed users in admin group
allowed_admins_list = [
    r'my-admin-user',
    r'my-other-admin-user',
]

def install():
    pass

def audit():
    if is_rhel_based():
        admin_group = r'wheel'
    elif is_debian_based():
        admin_group = r'sudo'
    else:
        print(r'Unsupported Linux distribution %s' % get_distrib_linux())
        return "ERROR"

    admins_users = run(r'getent group %s' % admin_group).split(':')[3].strip('\n').strip().split(',')
    unallowed_user_in_admins_group = False
    listerror = []
    admins_dict = {"unallowed": [], "allowed": []}

    for user in admins_users:
        if not user.lower() in allowed_admins_list:
            listerror.append(user)
            admins_dict["unallowed"].append(user)
        else:
            admins_dict["allowed"].append(user)

    print("ADMINS LIST : %s" % ",".join(admins_users))  # Allowed users in admin list
    if listerror:
        print("UNALLOWED ADMINS LIST : %s" % ",".join(listerror))  # Bad users in admin list
        unallowed_user_in_admins_group = True 

    WAPT.write_audit_data_if_changed("audit-local-admins-linux", "audit-local-admins-linux", admins_dict)

    if unallowed_user_in_admins_group:
        return "ERROR"

    return "OK"

macOS:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

# Define allowed users in admin group
allowed_admins_list = [
    ### SYSTEM ACCOUNTS
    r'root',
    r'_mbsetupuser',  # System installation assistant
    ### OTHERS
    r'my-admin-user',
    r'my-other-admin-user',
]

def install():
    pass

def audit():
    admins_users = run(r'dscacheutil -q group -a name admin | grep users').split(': ')[1].strip('\n').strip().split(' ')
    unallowed_user_in_admins_group = False
    listerror = []
    admins_dict = {"unallowed": [], "allowed": []}

    for user in admins_users:
        if not user.lower() in allowed_admins_list:
            listerror.append(user)
            admins_dict["unallowed"].append(user)
        else:
            admins_dict["allowed"].append(user)

    print("ADMINS LIST : %s" % ",".join(admins_users))  # Allowed users in admin list
    if listerror:
        print("UNALLOWED ADMINS LIST : %s" % ",".join(listerror))  # Bad users in admin list
        unallowed_user_in_admins_group = True 

    WAPT.write_audit_data_if_changed("audit-local-admins-macos", "audit-local-admins-macos", admins_dict)

    if unallowed_user_in_admins_group:
        return "ERROR"

    return "OK"
italbot
Messages: 61
Registration: Sep 26, 2023 - 3:50 p.m.

January 9, 2026 - 3:22 PM

Hello,

Thank you, we will add this code to our tis-audit-local-admins package.

Sincerely,

Ingrid
Tranquil IT
Locked