community.windows.win_audit_rule 模块 – 向文件、文件夹或注册表项添加审核规则

注意

此模块是 community.windows 集合(版本 2.3.0)的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.windows

要在 playbook 中使用它,请指定:community.windows.win_audit_rule

概要

  • 用于将审核规则应用于文件、文件夹或注册表项。

  • 应用后,它将开始将执行定义的操作的用户记录到事件查看器中的安全日志中。

  • 该行为旨在忽略继承的规则,因为在不首先禁用继承行为的情况下无法调整这些规则。不过,出于调试目的,它仍会在输出中打印继承的规则。

参数

参数

注释

audit_flags

列表 / 元素=字符串 / 必需

定义是在失败、成功还是两者都记录日志。

要记录两者,请定义为逗号分隔的列表“Success, Failure”。

选项

  • "Failure"

  • "Success"

inheritance_flags

列表 / 元素=字符串

定义文件夹或注册表项内的哪些对象将继承这些设置。

如果您要在文件上设置规则,则此值必须更改为 none

有关选项的更多信息,请参见 MSDN PropagationFlags 枚举,网址为 https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.inheritanceflags.aspx

选项

  • "ContainerInherit" ←(默认)

  • "ObjectInherit" ←(默认)

默认值: ["ContainerInherit", "ObjectInherit"]

path

别名:dest,destination

路径 / 必需

文件、文件夹或注册表项的路径。

注册表路径应采用 Powershell 格式,以根的缩写开头,例如 HKLM:\Software

propagation_flags

字符串

审核规则上的传播标志。

当路径类型为文件时,将忽略此值。

有关选项的更多信息,请参见 MSDN PropagationFlags 枚举,网址为 https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.propagationflags.aspx

选项

  • "None" ←(默认)

  • "InherityOnly"

  • "NoPropagateInherit"

rights

列表 / 元素=字符串 / 必需

所需的权限的逗号分隔列表。仅在添加规则时需要。

如果 path 是文件或目录,则权限可以是 MSDN FileSystemRights 下的任何权限 https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemrights.aspx

如果 path 是注册表项,则权限可以是 MSDN RegistryRights 下的任何权限 https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.registryrights.aspx

state

字符串

规则应为 present 还是 absent

对于 absent,仅需要 pathuserstate

指定 absent 将删除与定义的 user 匹配的所有规则。

选项

  • "absent"

  • "present" ←(默认)

user

字符串 / 必需

要调整规则的用户或组。

另请参阅

另请参阅

community.windows.win_audit_policy_system

用于更改系统范围的审核策略。

示例

- name: Add filesystem audit rule for a folder
  community.windows.win_audit_rule:
    path: C:\inetpub\wwwroot\website
    user: BUILTIN\Users
    rights: write,delete,changepermissions
    audit_flags: success,failure
    inheritance_flags: ContainerInherit,ObjectInherit

- name: Add filesystem audit rule for a file
  community.windows.win_audit_rule:
    path: C:\inetpub\wwwroot\website\web.config
    user: BUILTIN\Users
    rights: write,delete,changepermissions
    audit_flags: success,failure
    inheritance_flags: None

- name: Add registry audit rule
  community.windows.win_audit_rule:
    path: HKLM:\software
    user: BUILTIN\Users
    rights: delete
    audit_flags: 'success'

- name: Remove filesystem audit rule
  community.windows.win_audit_rule:
    path: C:\inetpub\wwwroot\website
    user: BUILTIN\Users
    state: absent

- name: Remove registry audit rule
  community.windows.win_audit_rule:
    path: HKLM:\software
    user: BUILTIN\Users
    state: absent

返回值

常见的返回值记录在 此处,以下是此模块特有的字段

描述

current_audit_rules

字典

定义的 path 上的当前规则

将返回“在 path 上未定义审核规则”

已返回:始终

示例: {"audit_flags": "Success", "inheritance_flags": "False", "is_inherited": "False", "propagation_flags": "None", "rights": "Delete", "user": "Everyone"}

path_type

字符串

所针对的路径的类型。

将是 file、directory 或 registry 之一。

已返回:始终

作者

  • Noah Sparks (@nwsparks)