Repository navigation
(GH-1755) Add two new DSC resources to manage AuditPolicy #1758
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
Open
Gijs Reijn (Gijsreyn)
wants to merge
3
commits into
PowerShell:main
Choose a base branch
from
Gijsreyn:gh-1755/main/add-auditpolicy-dsc-resource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,678
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
20 changes: 20 additions & 0 deletions
20
docs/reference/resources/Microsoft/Windows/AuditPolicy/examples/auditpolicy.config.dsc.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # yaml-language-server: $schema=https://aka.ms/dsc/schemas/v3/bundled/config/document.vscode.json | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: Audit successful and failed logons | ||
| type: Microsoft.Windows/AuditPolicy | ||
| properties: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: true | ||
| - name: Audit failed credential validation | ||
| type: Microsoft.Windows/AuditPolicy | ||
| properties: | ||
| subcategory: Credential Validation | ||
| failure: true | ||
| - name: Disable auditing of other privilege use events | ||
| type: Microsoft.Windows/AuditPolicy | ||
| properties: | ||
| subcategory: Other Privilege Use Events | ||
| success: false | ||
| failure: false | ||
256 changes: 256 additions & 0 deletions
256
...ence/resources/Microsoft/Windows/AuditPolicy/examples/configure-audit-policy.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| --- | ||
| description: > | ||
| Example showing how to use the Microsoft.Windows/AuditPolicy resource in a DSC configuration | ||
| document to enforce the auditing of audit policy subcategories. | ||
| ms.date: 10/16/2026 | ||
| ms.topic: reference | ||
| title: Configure audit policy | ||
| --- | ||
|
|
||
| # Configure audit policy | ||
|
|
||
| This example shows how you can use the `Microsoft.Windows/AuditPolicy` resource in a DSC | ||
| configuration document to enforce the auditing of several audit policy subcategories, as a | ||
| hardening baseline typically requires. | ||
|
|
||
| > [!IMPORTANT] | ||
| > All operations of this resource require an elevated (administrator) process context. Run your | ||
| > terminal or PowerShell session as Administrator before using `dsc config set`. | ||
|
|
||
| ## Definition | ||
|
|
||
| The configuration document for this example defines three instances of the `AuditPolicy` | ||
| resource. | ||
|
|
||
| The first instance ensures that both successful and failed logon events are audited. The second | ||
| instance ensures that failed credential validation is audited and leaves success auditing as it | ||
| is, because the `success` property is omitted. The third instance disables auditing of the | ||
| `Other Privilege Use Events` subcategory entirely. | ||
|
|
||
| :::code language="yaml" source="auditpolicy.config.dsc.yaml"::: | ||
|
|
||
| Copy the configuration document and save it as `auditpolicy.config.dsc.yaml`. | ||
|
|
||
| ## Setup | ||
|
|
||
| The output in this example assumes that the system audits successful logons only, doesn't audit | ||
| credential validation, and audits successful privilege use events. You can set the system to this | ||
| starting state with the following commands: | ||
|
|
||
| ```powershell | ||
| auditpol /set /subcategory:"Logon" /success:enable /failure:disable | ||
| auditpol /set /subcategory:"Credential Validation" /success:disable /failure:disable | ||
| auditpol /set /subcategory:"Other Privilege Use Events" /success:enable /failure:disable | ||
| ``` | ||
|
|
||
| ## Test the configuration | ||
|
|
||
| To see whether the system is already in the desired state, use the [dsc config test][01] command. | ||
|
|
||
| ```powershell | ||
| dsc config test --file ./auditpolicy.config.dsc.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| executionInformation: | ||
| # Elided for brevity | ||
| metadata: | ||
| # Elided for brevity | ||
| results: | ||
| - executionInformation: | ||
| duration: PT0.0411372S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0411372S | ||
| name: Audit successful and failed logons | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| desiredState: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: true | ||
| actualState: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: false | ||
| guid: '{0CCE9215-69AE-11D9-BED3-505054503030}' | ||
| category: Logon/Logoff | ||
| inDesiredState: false | ||
| differingProperties: | ||
| - failure | ||
| - executionInformation: | ||
| duration: PT0.0398114S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0398114S | ||
| name: Audit failed credential validation | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| desiredState: | ||
| subcategory: Credential Validation | ||
| failure: true | ||
| actualState: | ||
| subcategory: Credential Validation | ||
| success: false | ||
| failure: false | ||
| guid: '{0CCE923F-69AE-11D9-BED3-505054503030}' | ||
| category: Account Logon | ||
| inDesiredState: false | ||
| differingProperties: | ||
| - failure | ||
| - executionInformation: | ||
| duration: PT0.0402517S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0402517S | ||
| name: Disable auditing of other privilege use events | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| desiredState: | ||
| subcategory: Other Privilege Use Events | ||
| success: false | ||
| failure: false | ||
| actualState: | ||
| subcategory: Other Privilege Use Events | ||
| success: true | ||
| failure: false | ||
| guid: '{0CCE922A-69AE-11D9-BED3-505054503030}' | ||
| category: Privilege Use | ||
| inDesiredState: false | ||
| differingProperties: | ||
| - success | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| Each instance reports `inDesiredState: false` and lists only the flags that differ. The second | ||
| instance doesn't list `success` because the configuration document doesn't specify it. | ||
|
|
||
| ## Set the configuration | ||
|
|
||
| To enforce the desired state, use the [dsc config set][02] command. | ||
|
|
||
| ```powershell | ||
| dsc config set --file ./auditpolicy.config.dsc.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| executionInformation: | ||
| # Elided for brevity | ||
| metadata: | ||
| # Elided for brevity | ||
| results: | ||
| - executionInformation: | ||
| duration: PT0.0824631S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0824631S | ||
| name: Audit successful and failed logons | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| beforeState: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: false | ||
| guid: '{0CCE9215-69AE-11D9-BED3-505054503030}' | ||
| category: Logon/Logoff | ||
| afterState: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: true | ||
| guid: '{0CCE9215-69AE-11D9-BED3-505054503030}' | ||
| category: Logon/Logoff | ||
| changedProperties: | ||
| - failure | ||
| - executionInformation: | ||
| duration: PT0.0811207S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0811207S | ||
| name: Audit failed credential validation | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| beforeState: | ||
| subcategory: Credential Validation | ||
| success: false | ||
| failure: false | ||
| guid: '{0CCE923F-69AE-11D9-BED3-505054503030}' | ||
| category: Account Logon | ||
| afterState: | ||
| subcategory: Credential Validation | ||
| success: false | ||
| failure: true | ||
| guid: '{0CCE923F-69AE-11D9-BED3-505054503030}' | ||
| category: Account Logon | ||
| changedProperties: | ||
| - failure | ||
| - executionInformation: | ||
| duration: PT0.0807443S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0807443S | ||
| name: Disable auditing of other privilege use events | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| beforeState: | ||
| subcategory: Other Privilege Use Events | ||
| success: true | ||
| failure: false | ||
| guid: '{0CCE922A-69AE-11D9-BED3-505054503030}' | ||
| category: Privilege Use | ||
| afterState: | ||
| subcategory: Other Privilege Use Events | ||
| success: false | ||
| failure: false | ||
| guid: '{0CCE922A-69AE-11D9-BED3-505054503030}' | ||
| category: Privilege Use | ||
| changedProperties: | ||
| - success | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| The second instance only changed `failure`; its `success` flag kept the current value because the | ||
| configuration document doesn't specify it. Running `dsc config set` again makes no further | ||
| changes because every instance is already in the desired state. | ||
|
|
||
| ## Preview the changes | ||
|
|
||
| To see which flags would change without applying them, add the `--what-if` option to the | ||
| `dsc config set` command. The resource reports the projected state and describes each change | ||
| under `_metadata.whatIf`. | ||
|
|
||
| ```powershell | ||
| dsc config set --file ./auditpolicy.config.dsc.yaml --what-if | ||
| ``` | ||
|
|
||
| ```yaml | ||
| # Elided for brevity | ||
| results: | ||
| - name: Audit successful and failed logons | ||
| type: Microsoft.Windows/AuditPolicy | ||
| result: | ||
| beforeState: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: false | ||
| guid: '{0CCE9215-69AE-11D9-BED3-505054503030}' | ||
| category: Logon/Logoff | ||
| afterState: | ||
| subcategory: Logon | ||
| success: true | ||
| failure: true | ||
| guid: '{0CCE9215-69AE-11D9-BED3-505054503030}' | ||
| category: Logon/Logoff | ||
| _metadata: | ||
| whatIf: | ||
| - Would change failure auditing for subcategory 'Logon' from false to true | ||
| changedProperties: | ||
| - failure | ||
| - _metadata | ||
| # Elided for brevity | ||
| ``` | ||
|
|
||
| <!-- Link definitions --> | ||
| [01]: ../../../../../../cli/config/test.md | ||
| [02]: ../../../../../../cli/config/set.md |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
If setting multiple policies is common (seems like it would be), then there should also be a
Microsoft.Windows/AuditPolicyListresource