Debian Codegraph @

test/integration/targets/win_app_control/main.yml

raw
1 - name: run App Control tests on Windows
2 hosts: windows
3 gather_facts: false
4 collections:
5 # This is important so that the temp ansible.windows is chosen over the ansible-test path
6 # which will not be signed
7 - ansible.windows
8
9 handlers:
10 - name: remove openauthenticode
11 shell: Uninstall-PSResource -Name OpenAuthenticode -Version 0.6.1
12 args:
13 executable: pwsh
14 delegate_to: localhost
15
16 tasks:
17 - name: make sure expected facts are set
18 assert:
19 that:
20 - ansible_install_dir is defined
21 - local_tmp_dir is defined
22
23 - name: setup and test block
24 block:
25 - name: get test remote tmp dir
26 import_role:
27 name: ../setup_remote_tmp_dir
28
29 - name: get current user
30 ansible.windows.win_powershell:
31 script: '[Environment]::UserName'
32 register: current_user_raw
33
34 - name: set current user fact
35 set_fact:
36 current_user: '{{ current_user_raw.output[0] }}'
37
38 # Environment.UserName is SYSTEM on .NET Framework and the computer name on .NET 5+
39 - name: get SYSTEM username
40 ansible.windows.win_powershell:
41 script: '[Environment]::UserName'
42 register: system_user_raw
43 become: true
44 become_method: runas
45 become_user: SYSTEM
46
47 - name: set system user fact
48 set_fact:
49 system_user: '{{ system_user_raw.output[0] }}'
50
51 - name: setup App Control
52 import_tasks: setup.yml
53
54 - name: run content before enabling App Control
55 import_tasks: test_not_enabled.yml
56
57 - name: enable App Control
58 wdac_enable:
59 remote_tmp_dir: '{{ remote_tmp_dir }}'
60 register: policy_info
61
62 - name: run content after enabling App Control
63 import_tasks: test_enabled.yml
64
65 - name: run invalid manifest tests
66 import_tasks: test_manifest.yml
67
68 always:
69 - name: disable policy through CiTool if present
70 win_shell: CiTool.exe --remove-policy {{ policy_info.policy_id }}
71 when:
72 - policy_info is defined
73 - policy_info.policy_id is truthy
74
75 - name: remove App Control policy
76 win_file:
77 path: '{{ policy_info.path }}'
78 state: absent
79 register: policy_removal
80 when:
81 - policy_info is defined
82
83 - name: reboot after removing policy file
84 win_reboot:
85 when: policy_removal is changed
86
87 - name: remove certificates
88 ansible.windows.win_powershell:
89 script: |
90 param($CAThumbprint, $Thumbprint)
91
92 $ErrorActionPreference = 'Stop'
93
94 Remove-Item -LiteralPath "Cert:\LocalMachine\Root\$CAThumbprint" -Force
95 Remove-Item -LiteralPath "Cert:\LocalMachine\TrustedPublisher\$Thumbprint" -Force
96 parameters:
97 CAThumbprint: '{{ cert_info.ca_thumbprint }}'
98 Thumbprint: '{{ cert_info.thumbprint }}'
99 when: cert_info is defined
100
101 - name: remove signed Ansible content
102 file:
103 path: '{{ ansible_install_dir }}/{{ item }}'
104 state: absent
105 loop:
106 - config/powershell_signatures.psd1
107 - executor/powershell/exec_wrapper.ps1.authenticode
108 delegate_to: localhost