Skip to content

Commit 315103b

Browse files
committed
Fix grub2_bootloader_argument to accept variables defining minimal values
1 parent b4dd9c8 commit 315103b

32 files changed

+706
-63
lines changed

docs/templates/template_reference.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,68 @@ they must be of the same length.
461461

462462
- **arg_name** - argument name, eg. `audit`
463463

464-
- **arg_value** - argument value, eg. `'1'`
465-
466-
- **arg_variable** - the variable used as the value for the argument, eg. `'var_slub_debug_options'`
467-
This parameter is mutually exclusive with **arg_value**.
464+
- **arg_value** - argument value, eg. `'1'`.
465+
This parameter is mutually exclusive with **arg_variable** and **arg_minimal_value**.
466+
467+
- **arg_variable** - the variable used as the value for the argument, eg. `'var_slub_debug_options'`.
468+
This parameter is mutually exclusive with **arg_value** and **arg_minimal_value**.
469+
470+
- **arg_minimal_value** - XCCDF variable ID whose value is the minimum
471+
acceptable integer for the argument, eg. `'var_audit_backlog_limit'`.
472+
When set, the OVAL check captures the numeric value after
473+
`arg_name=` and verifies it is greater than or equal to the
474+
variable's value at scan time.
475+
This parameter is mutually exclusive with **arg_value** and **arg_variable**.
476+
477+
The three value modes control how `template.py` builds the
478+
`ARG_NAME_VALUE` string that all templates use:
479+
480+
- **arg_value** — the value is a literal, known at build time.
481+
`ARG_NAME_VALUE` is set to `"arg_name=arg_value"` (e.g.
482+
`"audit=1"`). All templates use it directly.
483+
484+
- **arg_variable** — the value is an XCCDF variable name, resolved
485+
at scan/remediation time. `ARG_NAME_VALUE` is set to the bare
486+
argument name (e.g. `"slub_debug"`), because the actual value is
487+
unknown at build time. Each remediation template overrides
488+
`ARG_NAME_VALUE` with the runtime variable (e.g. Bash produces
489+
`slub_debug=$var_slub_debug_options`). OVAL does an exact
490+
string match against the variable's value.
491+
492+
- **arg_minimal_value** — same as **arg_variable** for
493+
remediations: the value is an XCCDF variable name, and
494+
`ARG_NAME_VALUE` is the bare argument name (e.g.
495+
`"audit_backlog_limit"`). The difference is in OVAL: instead
496+
of an exact string match, the check captures the numeric value
497+
and compares it as an integer `>=` the variable's value. For
498+
example, `audit_backlog_limit=16384` passes when the variable
499+
is `8192`.
468500

469501
- Languages: Ansible, Bash, OVAL, Blueprint, Kickstart
470502

503+
- Examples:
504+
505+
# Hardcoded value — OVAL checks for exact "audit=1"
506+
template:
507+
name: grub2_bootloader_argument
508+
vars:
509+
arg_name: audit
510+
arg_value: "1"
511+
512+
# XCCDF variable, exact match — OVAL checks for "slub_debug=<var value>"
513+
template:
514+
name: grub2_bootloader_argument
515+
vars:
516+
arg_name: slub_debug
517+
arg_variable: var_slub_debug_options
518+
519+
# XCCDF variable, minimum value — OVAL checks integer >= <var value>
520+
template:
521+
name: grub2_bootloader_argument
522+
vars:
523+
arg_name: audit_backlog_limit
524+
arg_minimal_value: var_audit_backlog_limit
525+
471526
#### grub2_bootloader_argument_absent
472527
- Ensures that a kernel command line argument is absent in GRUB 2 configuration.
473528
The template can also remove arguments with a value assigned, eg. audit=1

linux_os/guide/auditing/grub2_audit_backlog_limit_argument/policy/stig/shared.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ vuldiscussion: |-
1515
checktext: |-
1616
Verify {{{ full_name }}} allocates a sufficient audit_backlog_limit to capture processes that start prior to the audit daemon with the following command:
1717
18-
$ sudo grubby --info=ALL | grep args | grep -v 'audit_backlog_limit=8192'
18+
$ sudo grubby --info=ALL | grep args | grep -v 'audit_backlog_limit'
1919
20-
If the command returns any outputs, and audit_backlog_limit is less than "8192", this is a finding.
20+
If the command produces output, at least one kernel entry is missing "audit_backlog_limit" parameter. This is a finding.
21+
22+
Verify the audit_backlog_limit is set to a value of at least 8192 with the following command:
23+
24+
$ sudo grubby --info=ALL | sed -n 's/.*audit_backlog_limit=\([0-9]*\).*/\1/p'
25+
26+
If the returned value is less than "8192", this is a finding.
2127
2228
fixtext: |-
2329
Configure {{{ full_name }}} to allocate sufficient audit_backlog_limit to capture processes that start prior to the audit daemon with the following command:
2430
2531
$ sudo grubby --update-kernel=ALL --args=audit_backlog_limit=8192
26-
27-

linux_os/guide/auditing/grub2_audit_backlog_limit_argument/rule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ template:
5050
name: grub2_bootloader_argument
5151
vars:
5252
arg_name: audit_backlog_limit
53-
arg_variable: var_audit_backlog_limit
53+
arg_minimal_value: var_audit_backlog_limit

linux_os/guide/auditing/var_audit_backlog_limit.var

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ documentation_complete: true
33
title: Audit backlog limit
44

55
description: |-
6-
Value of the audit_backlog_limit argument in GRUB 2 configuration.
7-
The audit_backlog_limit parameter determines how auditd records can
8-
be held in the auditd backlog.
6+
Minimum value of the audit_backlog_limit kernel parameter.
7+
This parameter sets the maximum number of outstanding audit
8+
records the kernel buffers while the audit daemon is not yet
9+
running or cannot keep up. If the backlog exceeds this limit,
10+
the kernel takes action based on the audit failure flag
11+
(silently drop, warn and drop, or panic).
912

10-
type: string
13+
type: number
1114

12-
operator: equals
15+
operator: greater than or equal
1316

1417
interactive: true
1518

shared/templates/grub2_bootloader_argument/ansible.template

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
# strategy = restrict
44
# complexity = medium
55
# disruption = low
6-
7-
{{% if ARG_VARIABLE %}}
8-
{{{ ansible_instantiate_variables(ARG_VARIABLE) }}}
9-
{{% set ARG_NAME_VALUE = ARG_NAME ~ "={{ " ~ ARG_VARIABLE ~ " }}" %}}
6+
{{#- Override ARG_NAME_VALUE when the rule uses an XCCDF variable. Safe as template.py fails if both are set. -#}}
7+
{{% set _var = ARG_MINIMAL_VALUE or ARG_VARIABLE %}}
8+
{{% if _var %}}
9+
{{{ ansible_instantiate_variables(_var) }}}
10+
{{% set ARG_NAME_VALUE = ARG_NAME ~ "={{ " ~ _var ~ " }}" %}}
1011
{{% endif %}}
11-
{{{ ansible_grub2_bootloader_argument(ARG_NAME, ARG_NAME_VALUE, ARG_VARIABLE) }}}
12+
13+
{{#- Generate Ansible tasks to update GRUB config files #}}
14+
{{{- ansible_grub2_bootloader_argument(ARG_NAME, ARG_NAME_VALUE, ARG_VARIABLE) }}}

shared/templates/grub2_bootloader_argument/bash.template

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
Product-specific categorization should be synced across all template content types
55
-#}}
66

7-
{{%- if ARG_VARIABLE %}}
8-
{{{- bash_instantiate_variables(ARG_VARIABLE) }}}
9-
{{%- set ARG_NAME_VALUE = ARG_NAME ~ "=$" ~ ARG_VARIABLE %}}
7+
{{#- Override ARG_NAME_VALUE when the rule uses an XCCDF variable. Safe as template.py fails if both are set. -#}}
8+
{{%- set _var = ARG_MINIMAL_VALUE or ARG_VARIABLE %}}
9+
{{%- if _var %}}
10+
{{{- bash_instantiate_variables(_var) }}}
11+
{{%- set ARG_NAME_VALUE = ARG_NAME ~ "=$" ~ _var %}}
1012
{{% endif %}}
1113

1214
if {{{ bash_bootc_build() }}} ; then
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv,multi_platform_ubuntu,multi_platform_sle,multi_platform_almalinux
2-
{{%- if ARG_VARIABLE %}}
3-
{{%- set ARG_NAME_VALUE = ARG_NAME ~ "=(blueprint-populate " ~ ARG_VARIABLE ~ ")" -%}}
2+
{{#- Override ARG_NAME_VALUE when the rule uses an XCCDF variable. Safe as template.py fails if both are set. -#}}
3+
{{%- set _var = ARG_MINIMAL_VALUE or ARG_VARIABLE %}}
4+
{{%- if _var %}}
5+
{{%- set ARG_NAME_VALUE = ARG_NAME ~ "=(blueprint-populate " ~ _var ~ ")" -%}}
46
{{%- endif %}}
57
[customizations.kernel]
68
append = "{{{ ARG_NAME_VALUE }}}"

shared/templates/grub2_bootloader_argument/kickstart.template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
# complexity = medium
55
# disruption = low
66

7-
{{%- if ARG_VARIABLE %}}
8-
{{%- set ARG_NAME_VALUE = ARG_NAME ~ "=(kickstart-populate " ~ ARG_VARIABLE ~ ")" -%}}
7+
{{#- Override ARG_NAME_VALUE when the rule uses an XCCDF variable. Safe as template.py fails if both are set. -#}}
8+
{{%- set _var = ARG_MINIMAL_VALUE or ARG_VARIABLE %}}
9+
{{%- if _var %}}
10+
{{%- set ARG_NAME_VALUE = ARG_NAME ~ "=(kickstart-populate " ~ _var ~ ")" -%}}
911
{{%- endif %}}
1012

1113
bootloader {{{ ARG_NAME_VALUE }}}

0 commit comments

Comments
 (0)