Skip to content

fix(cli): parse the minimum password length for CIS 5.2.2 - #35

Open
victor-sys-admin wants to merge 1 commit into
sametsazak:mainfrom
victor-sys-admin:fix/cis-5.2.2-cli-min-length
Open

victor-sys-admin wants to merge 1 commit into
sametsazak:mainfrom
victor-sys-admin:fix/cis-5.2.2-cli-min-length

Conversation

@victor-sys-admin

Copy link
Copy Markdown

Summary

The CLI passed CIS 5.2.2 (minimum password length ≥ 15) as soon as the text minChars appeared in pwpolicy -getaccountpolicies. pwpolicy -setglobalpolicy minChars=N always creates the identifier com.apple.policy.legacy.minChars, whatever N is, so a 4-character minimum passed. The app was fixed in #25; the CLI was not.

Changes

mergen-cli/internal/checks/password_policy.go now uses the same rules as PasswordMinLengthCheck.swift:

  1. take the largest N from every policyAttributePassword matches '.{N,}' predicate, with an optional ? or + quantifier;
  2. if there is none, take the largest minimumLength (the parameter the CIS audit reads) or minChars value;
  3. N ≥ 15 → PASS, N < 15 → FAIL. A length policy that cannot be parsed → WARN; no policy → FAIL.

Messages now include the value, e.g. Minimum password length is 8 (should be ≥ 15). The remediation and fix are unchanged (pwpolicy -n /Local/Default -setglobalpolicy minChars=15, the CIS terminal method).

password_policy_test.go (new) covers the three quantifier forms, a 4-character policy, stacked predicates, a parameter-only output, an unparsable predicate and no policy at all.

How it was tested

On an Intel Mac, macOS 15.8.1 (Sequoia), Go 1.27.3:

  • go build, go vet ./..., go test ./internal/checks/ (9 cases), golangci-lint v2.14.0 (no new issues); xcodebuild Debug build (no Swift change)
  • mergen scan --section 5 on a Mac with a 15-character policy → ✓ 5.2.2

Not tested

  • macOS 26 Tahoe
  • a profile-installed policy (MDM minLength)
  • changing the local policy: I did not touch it

Test plan

  • sudo pwpolicy -n /Local/Default -setglobalpolicy minChars=8 → mergen scan --section 5 → 5.2.2 FAIL, Minimum password length is 8 (should be ≥ 15)
  • … minChars=15 → PASS

References

  • Wazuh SCA cis_apple_macOS_26.x.yml (v4.14.9), check 41051 — CIS 5.2.2 audit reads minimumLength
  • NIST mSCP tahoe_rev3, rule pwpolicy_minimum_length_enforce (CC BY 4.0) — takes the largest .{N, predicate

The CLI passed 5.2.2 whenever "minChars" appeared in pwpolicy output.
That string is part of the com.apple.policy.legacy.minChars
identifier, so a 4-character minimum passed too.

Parse the value with the same rules as PasswordMinLengthCheck.swift:
the largest `.{N,}` predicate, else the minimumLength / minChars
parameters, and require N >= 15.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant