-
Notifications
You must be signed in to change notification settings - Fork 825
Align audit_rules_sudoers_d remediation with DISA STIG content #15060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| {{% macro local_variable_modern_style(lvarid, arch) %}} | ||
| <local_variable id="{{{ lvarid }}}" comment="The composite pattern used to detect if audit has been configured" datatype="string" version="1"> | ||
| <concat> | ||
| <literal_component>^\-a\s+always,exit\s+\-F\s+arch={{{ arch }}}\s+\-F\s+{{{ FILTER_TYPE }}}=</literal_component> | ||
| <literal_component>^\-a\s+always,exit\s+\-F\s+arch={{{ arch }}}\s+\-F\s+(dir|path)=</literal_component> | ||
| {{% if PATH_IS_VARIABLE %}} | ||
| <variable_component var_ref="{{{ PATH }}}"/> | ||
| {{% else %}} | ||
| <literal_component>{{{ PATH_ESCAPED }}}</literal_component> | ||
| {{% endif %}} | ||
| <literal_component>\s+\-F\s+perm=\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$</literal_component> | ||
| <literal_component>/?\s+\-F\s+perm=\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$</literal_component> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ggbecker Will it accidentally start accepting paths with trailing slash where it shouldn't accept it? When the audit rule is supposed to watch a regular file (not a directory) but the audit rule contains a path with a trailing slash, will the rule fail? Let's assume that I have the following rules in the What will be the OVAL result? |
||
| </concat> | ||
| </local_variable> | ||
| {{% endmacro %}} | ||
|
|
@@ -109,7 +109,7 @@ | |
| {{% else %}} | ||
| <literal_component>{{{ PATH_ESCAPED }}}</literal_component> | ||
| {{% endif %}} | ||
| <literal_component>[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$</literal_component> | ||
| <literal_component>/?[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$</literal_component> | ||
| </concat> | ||
| </local_variable> | ||
| {{% endif %}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,13 @@ def preprocess(data, lang): | |
| name = ssg.utils.escape_id(os.path.basename(os.path.normpath(path))) | ||
| data["name"] = name | ||
| if lang == "oval": | ||
| data["path_escaped"] = path.replace("/", "\\/") | ||
| # Normalize away a trailing slash so it can be made optional in the | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ggbecker I consider having the new behavior accessible by a new template parameter instead of changing the existing behavior. |
||
| # OVAL pattern (via '/?'). This lets the check accept the watched path | ||
| # with or without a trailing slash regardless of how the rule is | ||
| # written on disk (e.g. both '-F dir=/etc/sudoers.d' and | ||
| # '-F path=/etc/sudoers.d/'). | ||
| normalized_path = path.rstrip("/") or "/" | ||
| data["path_escaped"] = normalized_path.replace("/", "\\/") | ||
| if "key" not in data: | ||
| data["key"] = data["_rule_id"] | ||
| if data["path"].endswith("/"): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| {{{ setup_auditctl_environment() }}} | ||
| path={{{ PATH }}} | ||
| style={{{ audit_watches_style }}} | ||
| filter_type={{{ FILTER_TYPE }}} | ||
| . $SHARED/audit_rules_watch/auditctl_alternate_filter_type.pass.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| {{{ setup_auditctl_environment() }}} | ||
| path={{{ PATH }}} | ||
| style={{{ audit_watches_style }}} | ||
| filter_type={{{ FILTER_TYPE }}} | ||
| . $SHARED/audit_rules_watch/auditctl_trailing_slash_toggle.pass.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| {{{ setup_augenrules_environment() }}} | ||
|
|
||
| path={{{ PATH }}} | ||
| style={{{ audit_watches_style }}} | ||
| filter_type={{{ FILTER_TYPE }}} | ||
| . $SHARED/audit_rules_watch/augenrules_alternate_filter_type.pass.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| {{{ setup_augenrules_environment() }}} | ||
|
|
||
| path={{{ PATH }}} | ||
| style={{{ audit_watches_style }}} | ||
| filter_type={{{ FILTER_TYPE }}} | ||
| . $SHARED/audit_rules_watch/augenrules_trailing_slash_toggle.pass.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| # The OVAL check accepts either the 'dir=' (subtree) or 'path=' (single object) | ||
| # filter type. Configure the rule using the opposite filter type from the one | ||
| # the remediation would emit and confirm the check still passes. | ||
| if [[ "$style" == "modern" ]] ; then | ||
| if [[ "$filter_type" == "dir" ]]; then alt_filter="path"; else alt_filter="dir"; fi | ||
| echo "-a always,exit -F arch=b32 -F $alt_filter=$path -F perm=wa -F key=logins" >> /etc/audit/audit.rules | ||
| echo "-a always,exit -F arch=b64 -F $alt_filter=$path -F perm=wa -F key=logins" >> /etc/audit/audit.rules | ||
| else | ||
| # Legacy '-w' watches have no dir/path distinction; use the standard form. | ||
| echo "-w $path -p wa -k login" >> /etc/audit/audit.rules | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| # The OVAL check treats a trailing slash on the watched path as optional. | ||
| # Toggle the trailing slash relative to the rule's configured path and confirm | ||
| # the check still passes. | ||
| if [[ "$path" == */ ]]; then toggled_path="${path%/}"; else toggled_path="${path}/"; fi | ||
|
|
||
| if [[ "$style" == "modern" ]] ; then | ||
| echo "-a always,exit -F arch=b32 -F $filter_type=$toggled_path -F perm=wa -F key=logins" >> /etc/audit/audit.rules | ||
| echo "-a always,exit -F arch=b64 -F $filter_type=$toggled_path -F perm=wa -F key=logins" >> /etc/audit/audit.rules | ||
| else | ||
| echo "-w $toggled_path -p wa -k login" >> /etc/audit/audit.rules | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| # The OVAL check accepts either the 'dir=' (subtree) or 'path=' (single object) | ||
| # filter type. Configure the rule using the opposite filter type from the one | ||
| # the remediation would emit and confirm the check still passes. | ||
| if [[ "$style" == "modern" ]] ; then | ||
| if [[ "$filter_type" == "dir" ]]; then alt_filter="path"; else alt_filter="dir"; fi | ||
| echo "-a always,exit -F arch=b32 -F $alt_filter=$path -F perm=wa -F key=logins" >> /etc/audit/rules.d/login.rules | ||
| echo "-a always,exit -F arch=b64 -F $alt_filter=$path -F perm=wa -F key=logins" >> /etc/audit/rules.d/login.rules | ||
| else | ||
| # Legacy '-w' watches have no dir/path distinction; use the standard form. | ||
| echo "-w $path -p wa -k login" >> /etc/audit/rules.d/login.rules | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # packages = audit | ||
|
|
||
| # The OVAL check treats a trailing slash on the watched path as optional. | ||
| # Toggle the trailing slash relative to the rule's configured path and confirm | ||
| # the check still passes. | ||
| if [[ "$path" == */ ]]; then toggled_path="${path%/}"; else toggled_path="${path}/"; fi | ||
|
|
||
| if [[ "$style" == "modern" ]] ; then | ||
| echo "-a always,exit -F arch=b32 -F $filter_type=$toggled_path -F perm=wa -F key=logins" >> /etc/audit/rules.d/login.rules | ||
| echo "-a always,exit -F arch=b64 -F $filter_type=$toggled_path -F perm=wa -F key=logins" >> /etc/audit/rules.d/login.rules | ||
| else | ||
| echo "-w $toggled_path -p wa -k login" >> /etc/audit/rules.d/login.rules | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RHEL 10 STIG contains the trailing slash in the rule, so the description won't match the rule. https://stigaview.com/products/rhel10/v1r2/RHEL-10-500690/