DRAFT: sshd_disable_compression: accept both "no" and "delayed"#14831
Open
macko1 wants to merge 3 commits into
Open
DRAFT: sshd_disable_compression: accept both "no" and "delayed"#14831macko1 wants to merge 3 commits into
macko1 wants to merge 3 commits into
Conversation
|
Skipping CI for Draft Pull Request. |
eb216f4 to
20d65c5
Compare
Add `operation` parameter (default "equals") to the `oval_line_in_file_state_xccdf_variable`, `oval_line_in_directory_state_xccdf_variable`, `sshd_oval_check`, and `sshd_oval_check_usr` OVAL Jinja macros in `shared/macros/10-oval.jinja`. `sshd_oval_check_usr` (used by SLE16) gets the parameter so `sshd_oval_check` and `sshd_oval_check_usr` have the same interface -- `oval.template` passes `operation` to both. Reformat `sshd_oval_check` and `sshd_oval_check_usr` with comments.
02ec17a to
69fdd62
Compare
`shared/templates/sshd_lineinfile/oval.template` had 4 branches (2x2 matrix: product x XCCDF_VARIABLE). Pass both `value` and `xccdf_variable` to `sshd_oval_check` and `sshd_oval_check_usr` -- each macro already checks which parameter is set. Reduces `oval.template` to 2 branches (product only). `shared/templates/sshd_lineinfile/template.py`: - Default `operation` to "equals" when a rule does not set it - Default `value` and `xccdf_variable` to "" so `oval.template` can pass both without relying on Jinja's silent undefined behavior
DISA STIG V-258002 allows the `Compression` parameter in `/etc/ssh/sshd_config` to be set to "no" or "delayed". The RHEL 9 STIG profile selected `var_sshd_disable_compression=no`, and the OVAL state used `operation="equals"`, so systems with `Compression delayed` were flagged as non-compliant. Add a `stig` option (`no|delayed`) to `var_sshd_disable_compression.var` and set `operation` to `"pattern match"` in `sshd_disable_compression/rule.yml` so the OVAL check treats the variable value as a regex. Update RHEL 9 and OL9 STIG controls to select `var_sshd_disable_compression=stig`. Add `sshd_disable_compression/tests/delayed_value.pass.sh`. Named `stig` following the convention in `var_password_hashing_algorithm` (`cis_rhel8`, `cis_ubuntu2204`).
69fdd62 to
e95c01f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sshd_disable_compression: accept both "no" and "delayed"
Description:
Allow
sshd_disable_compressionto accept bothnoanddelayed.DISA STIG V-258002 (RHEL-09-255130) requires that sshd must not allow compression or must only allow compression after successful authentication. The
Compressionparameter in/etc/ssh/sshd_configcontrols this:Compression no-- disables compression entirelyCompression delayed-- compresses only after authenticationThe problem:
Compression delayedwere incorrectly flagged as non-compliantoval_line_in_file_state_xccdf_variablemacro inshared/macros/10-oval.jinjahardcodedoperation="equals", forcing an exact match against the single value selected by the RHEL 9 STIG profile (var_sshd_disable_compression=no)The fix:
operationparameter to the OVAL Jinja macros inshared/macros/10-oval.jinja:oval_line_in_file_state_xccdf_variablesshd_oval_checksshd_oval_check_usr"equals"so existing rules are unaffectedshared/templates/sshd_lineinfile/oval.templateandtemplate.pyto passoperationto the macrosoperation: "pattern match"insshd_disable_compression/rule.ymlso the OVAL check treatsvar_sshd_disable_compressionas a regexstigoption (no|delayed) tovar_sshd_disable_compression.varvar_sshd_disable_compression=stigsshd_disable_compression/tests/delayed_value.pass.sh-- setsCompression delayedand verifies the OVAL check passesNotes:
Compression no(strictest valid value)sshd_oval_check_usr(used by SLE16) gets theoperationparameter sosshd_oval_checkandsshd_oval_check_usrhave the same interface. No SLE16 rule usesoperation="pattern match"today, butoval.templatepassesoperationto both macrosshared/templates/sshd_lineinfile/oval.templateis simplified:XCCDF_VARIABLE)valueandxccdf_variableto the macro -- the macro checks which one is set and uses itRationale:
Adding
operationto the macro lets individual rules override the comparison operator to"pattern match"-- the variable value is treated as a regex (no|delayedmatches either)The variable option is named
stigfollowing the convention invar_password_hashing_algorithm(cis_rhel8,cis_ubuntu2204-- named after the profile)operation="pattern match"withvar_refis already used by:banner_etc_issueset_password_hashing_algorithmpam_faillockgrub2_bootloader_argumenttemplateFixes sshd_disable_compression only seems to check for no #13078
Review Hints:
Build and verify the generated OVAL uses
pattern match:./build_product rhel9 -r sshd_disable_compression grep 'operation=.*var_ref.*sshd_disable_compression' build/rhel9/checks/oval/sshd_disable_compression.xmlRun rule tests in a container:
SSH_ADDITIONAL_OPTIONS="-o IdentityFile=~/.ssh/id_ed25519" \ tests/automatus.py rule \ --container localhost/ssg_test_suite \ --datastream build/ssg-rhel9-ds.xml \ --remediate-using bash \ --make-applicable-in-containers \ --remove-platforms \ sshd_disable_compressionAll
sshd_disable_compressionrule tests andsshd_lineinfiletemplate tests pass locally (tested in a UBI 9 container using Automatus), includingdelayed_value.pass.sh.To verify other sshd rules are unaffected, run the full template test:
SSH_ADDITIONAL_OPTIONS="-o IdentityFile=~/.ssh/id_ed25519" \ tests/automatus.py template \ --container localhost/ssg_test_suite \ --datastream build/ssg-rhel9-ds.xml \ --remediate-using bash \ --make-applicable-in-containers \ --remove-platforms \ sshd_lineinfileFailed CI runs (pre-existing, unrelated to this PR):
Yaml Lint on Changed yaml files:key-duplicatesonsshd_disable_compression/rule.ymlline 54{{% if product == "ol7" %}} platform: ... {{% elif product == "sle12" %}} platform: ...generates twoplatform:YAML keys in the raw fileyamllintreads the file before Jinja rendering and sees both keys at oncerule.ymlbefore this PRRun Tests(RHEL 8):Couldn't install required packages: crypto-policies-scripts,auditcrypto-policies-scriptsandauditpackages (stale or missing repos)sshd_disable_compressionRed Hat Konflux / compliance-operator-dev-enterprise-contract: supply chain security check for the compliance operator container image (SLSA provenance, trusted build tasks, CVE scans). Tests the container build pipeline, not ComplianceAsCode content rules.testing-farm:centos-stream-9-x86_64:contest-ansible,contest-oscap,contest-other: