Configure a Windows 2022 system to be DISA STIG compliant
Join us on our Discord Server to ask questions, discuss features, or just chat with other Ansible-Lockdown users.
Bug reports and feature requests are welcome from everyone, please raise an issue.
Pull requests are accepted from approved contributors only. To be onboarded, join the Discord Server and request contributor access. See CONTRIBUTING.md for the full process.
This role will make changes to the system which may have unintended consequences. This is not an auditing tool but a remediation tool to be used after an audit.
Check Mode is not supported! The role will complete in check mode without errors, but it is not supported and should be used with caution.
This role was developed against a clean install of the Windows 2022 operating system. If you are implementing an existing system please review this role for any site-specific changes that are needed.
To use the release version please point to the main branch and relevant release for the STIG benchmark you wish to work with.
Account policy is domain scoped. On a domain joined host the Default Domain Policy owns
[System Access], so the 13 secedit backed controls in this role cannot hold there. prelim.yml
detects domain membership, skips those controls and warns once, rather than writing settings the
domain will not keep. Set them in the Default Domain Policy instead.
Everything outside [System Access] applies normally on a domain member.
This behavior was verified on a domain joined workstation during Windows Fleet testing, where a
complete hardening run left all [System Access] values byte-identical to the pre-run baseline. It
has not been separately measured on Windows Server 2022.
It is possible to only run controls that are based on a particular security level for STIG. This is managed using tags:
- CAT1
- CAT2
- CAT3
The control found in the defaults main also needs to reflect true so as this will allow the controls to run when the playbook is launched.
STIG releases always contain changes, so it is highly recommended to review the new references and available variables. This has changed significantly since the initial release of ansible-lockdown.
Further details can be seen in the Changelog
The role can scan the host with the DISA SCAP Compliance Checker before and after remediation, so
the difference between the two runs shows what the role actually changed. SCC is downloaded to the
target, scoped to the Windows Server 2022 benchmark, run, and its checklists and HTML report are
written to audit_log_dir.
Every audit control defaults to off, so an ordinary hardening run is unchanged. The rest of
defaults/main/audit.yml is settings with working defaults. Enable a scan with:
# scan, remediate, scan again
ansible-playbook -i inventory site.yml -e setup_audit=true -e run_audit=true
# scan and stop, changing nothing on the host
ansible-playbook -i inventory site.yml -e setup_audit=true -e audit_only=trueSettings live in defaults/main/audit.yml. See docs/README_SCC_QuickStart.md
for the operator guide: variables, profiles, SCC command line behavior and how to read the output.
The scanner bundle is pinned to the SHA-256 that DISA publishes for it, and the download is
rejected if it does not match. Bumping scc_version without re-pinning fails the run by design.
The benchmark's per-user rules are evaluated against each user's own profile hive. A profile whose
owner is not signed in is not mounted, so a control that reads HKEY_USERS cannot see it and can
only report that it was unable to check.
So prelim.yml mounts the Default profile and every profile listed in ProfileList under
HKEY_USERS, and the per-user control covers those too. This is governed by
win22stig_load_user_hives, which defaults to true.
The hives the role mounts are released again at the end of the run, including when the run fails or ends early. Hives that were already mounted when the role started are left alone, so a signed-in user does not lose their profile mid-run. A profile that exists on disk but cannot be loaded is reported as a warning rather than silently skipped.
Setting win22stig_load_user_hives to false leaves those profiles untouched, and the control
falls back to the Default profile alone.
Domain controllers are excluded from the hive loading and from the audit. A controller's
ProfileList carries domain administrator profiles, and mounting and releasing those on a live
controller is a different proposition from a member server. The exclusion is deliberate and has
not been tested against a controller.
With create_benchmark_facts enabled (the default), the role writes a record of what it applied to:
C:\ProgramData\ansible\facts.d\compliance_facts.json
It captures the benchmark release, the run date and which CAT levels were enabled.
Windows has no default local-facts directory, so unlike the Linux roles this file is not collected automatically. Ask for it explicitly:
- name: Read the compliance facts
ansible.windows.setup:
fact_path: 'C:\ProgramData\ansible\facts.d'It then appears as ansible_compliance_facts - not under ansible_local, which is the Linux
convention. Set ansible_facts_path to relocate the directory, or create_benchmark_facts: false
to skip writing it.
- Read The Docs
- Getting Started
- Customizing Roles
- Per-Host Configuration
- Getting the Most Out of the Role
General:
-
Basic knowledge of Ansible, below are some links to the Ansible documentation to help get started if you are unfamiliar with Ansible
-
Functioning Ansible and/or Tower Installed, configured, and running. This includes all of the base Ansible/Tower configurations, needed packages installed, and infrastructure setup.
-
Please read through the tasks in this role to gain an understanding of what each control is doing. Some of the tasks are disruptive and can have unintended consequences in a live production system. Also, familiarize yourself with the variables in the defaults/main/main.yml file.
Technical Dependencies:
- Windows 2022 - Other versions are not supported
- Running Ansible/Tower setup. This role requires ansible-core 2.16.1 or newer; the role asserts this at run time.
- Python3 Ansible run environment
- pywinrm
ansible.windows>= 3.7.0 andcommunity.windows>= 3.3.0
pywinrm is required on the controller host that executes Ansible; it is the connection library Ansible uses to reach a Windows target. The two collections are pinned in collections/requirements.yml and declared in meta/main.yml; install them with ansible-galaxy collection install -r collections/requirements.yml.
1. Variable prefix. Role behavior variables and security tunables now share the win22stig_
prefix. If you override any of the security tunables in inventory, group_vars or extra vars,
rename them - the old names are no longer read and your setting will be silently ignored.
wn22stig_<name>becomeswin22stig_<name>(for examplewn22stig_lockoutbadcountbecomeswin22stig_lockoutbadcount)win2022stig_<name>becomeswin22stig_<name>foraudit_complex,audit_disruptive,complexity_highanddisruption_high- three names also correct a typo:
sebackuprivilegebecomessebackupprivilege,selockmemorprivilegebecomesselockmemoryprivilege, andmachineaccountpsswd_max_agebecomesmachineaccountpassword_max_age
Rule toggles are unchanged. They keep the wn22_<control id> form, for example
wn22_au_000010.
2. CAT control switches renamed. win2022stig_cat1_patch, win2022stig_cat2_patch and
win2022stig_cat3_patch become win22stig_cat1_controls, win22stig_cat2_controls and
win22stig_cat3_controls, matching the names the tasks actually read. The prefix and the suffix
both change, so the general prefix rule above does not cover these.
3. The GPO authoring path has been removed. This role is now remediation only. The
tasks/gpo_creation/ and tasks/domain_creation/ trees, their pipeline workflows, and the
win22stig_create_gpos / win22stig_create_domain / win22stig_ansible_remediation switches
are gone. Every control the GPO path implemented is implemented by the remediation path.
4. Removed duplicate variables. wn22stig_app_maxsize, wn22stig_sec_maxsize,
wn22stig_sys_maxsize and wn22stig_krbtgt_pass_age were dead duplicates that no task read.
Use win22stig_application_event_log_max_size, win22stig_security_event_log_max_size,
win22stig_system_event_log_max_size and win22stig_krbtgt_account_pass_age instead.
This role is designed so that the end user should not have to edit the tasks themselves. All customizing should be done via the defaults/main/main.yml file or with extra vars within the project, job, workflow, etc. Non-disruptive CAT I, CAT II, and CAT III findings will be corrected by default. Disruptive finding remediation can be enabled by setting win22stig_disruption_high to true.
Below is an example of the tag section from control within this role. Using this example if you set your run to skip all controls with the tag CCI-000366, this task will be skipped. The opposite can also happen where you run only controls tagged with CCI-000366.
tags:
- WN22-00-000010
- CAT2
- CCI-000366
- SRG-OS-000480-GPOS-00227
- SV-254238r991589_rule
- V-254238
- audit
- NIST800-53_CM-6_b
- NIST800-53_A_CM-6_1_iv
- NIST800-53_4_CM-6_bPull requests are accepted from approved contributors only, and issues are welcome from everyone. See CONTRIBUTING.md for the onboarding process, the rules, and the commit signing requirements (GPG signature and Signed-off-by on every commit).
uses:
- ansible-core 2.16.1 or newer, from the pinned virtualenv on the runner
- runs the role against a Windows target provisioned on Azure with OpenTofu, which is torn down when the run ends
- self-hosted runners
- pull requests into
develor abenchmark*branch run the devel pipeline; pull requests intomainorlatestrun the main pipeline - the job runs only for pull requests raised from a branch in this repository, because it carries the cloud credentials
- Ansible
- ansible-core 2.16.1 or newer, with Python 3
pywinrmon the controller, which is the connection library Ansible uses to reach a Windows target
Thank you to the fantastic community and all its members.
This includes a huge thank you and credit to the original authors and maintainers.