forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunasadministrator_windows_test.go
198 lines (180 loc) · 6.26 KB
/
runasadministrator_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
import (
"testing"
"github.com/mcuadros/go-defaults"
)
func TestRunAsAdministratorDisabled(t *testing.T) {
setup(t)
if config.RunTasksAsCurrentUser {
t.Skip("Skipping since running as current user...")
}
payload := GenericWorkerPayload{
Command: []string{
`whoami /groups`,
// S-1-16-12288 is SID of 'High Mandatory Level' which implies process is elevated
// See also https://msdn.microsoft.com/en-us/library/bb625963.aspx
// and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_token_elevation
`whoami /groups | C:\Windows\System32\find.exe "S-1-16-12288" > nul`,
},
MaxRunTime: 10,
}
defaults.SetDefaults(&payload)
td := testTask(t)
_ = submitAndAssert(t, td, payload, "failed", "failed")
}
func TestRunAsAdministratorEnabledMissingScopes(t *testing.T) {
setup(t)
if config.RunTasksAsCurrentUser {
t.Skip("Skipping since running as current user...")
}
payload := GenericWorkerPayload{
Command: []string{
`whoami /groups`,
// S-1-16-12288 is SID of 'High Mandatory Level' which implies process is elevated
// See also https://msdn.microsoft.com/en-us/library/bb625963.aspx
// and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_token_elevation
`whoami /groups | C:\Windows\System32\find.exe "S-1-16-12288" > nul`,
},
MaxRunTime: 10,
Features: FeatureFlags{
RunAsAdministrator: true,
},
OSGroups: []string{
"Administrators",
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = []string{
"generic-worker:os-group:" + td.ProvisionerID + "/" + td.WorkerType + "/Administrators",
}
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}
func TestRunAsAdministratorMissingOSGroup(t *testing.T) {
setup(t)
if config.RunTasksAsCurrentUser {
t.Skip("Skipping since running as current user...")
}
payload := GenericWorkerPayload{
Command: []string{
`whoami /groups`,
// S-1-16-12288 is SID of 'High Mandatory Level' which implies process is elevated
// See also https://msdn.microsoft.com/en-us/library/bb625963.aspx
// and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_token_elevation
`whoami /groups | C:\Windows\System32\find.exe "S-1-16-12288" > nul`,
},
MaxRunTime: 10,
OSGroups: []string{}, // Administrators not included!
Features: FeatureFlags{
RunAsAdministrator: true,
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = []string{
"generic-worker:run-as-administrator:" + td.ProvisionerID + "/" + td.WorkerType,
"generic-worker:os-group:" + td.ProvisionerID + "/" + td.WorkerType + "/Administrators",
}
// either UAC is enabled, and this should have malformed-payload because
// does not have Administrators group set in osGroups; or UAC is disabled
// and should have malformed-payload since runAsAdministrator shouldn't be
// allowed for a worker type with UAC disabled
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}
// the payload never actually runs, so we don't need to also cover ed25519.
func TestChainOfTrustWithRunAsAdministrator(t *testing.T) {
setup(t)
payload := GenericWorkerPayload{
Command: []string{
`type "` + config.Ed25519SigningKeyLocation + `"`,
},
MaxRunTime: 5,
OSGroups: []string{"Administrators"},
Features: FeatureFlags{
ChainOfTrust: true,
RunAsAdministrator: true,
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = []string{
"generic-worker:run-as-administrator:" + td.ProvisionerID + "/" + td.WorkerType,
"generic-worker:os-group:" + td.ProvisionerID + "/" + td.WorkerType + "/Administrators",
}
if config.RunTasksAsCurrentUser {
// When running as current user, chain of trust key is not private so
// generic-worker should detect that it isn't secured from task user
// and cause malformed-payload exception.
expectChainOfTrustKeyNotSecureMessage(t, td, payload)
return
}
// if UAC is disabled, we should have malformed-payload for trying to use
// runAsAdministrator. if it is enabled, we should have malformed-payload
// because chain of trust certificate isn't secure.
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}
func TestChainOfTrustWithoutRunAsAdministrator(t *testing.T) {
setup(t)
payload := GenericWorkerPayload{
Command: []string{
`type "` + config.Ed25519SigningKeyLocation + `"`,
},
MaxRunTime: 5,
OSGroups: []string{"Administrators"},
Features: FeatureFlags{
ChainOfTrust: true,
RunAsAdministrator: false, // FALSE !!!!
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = []string{
"generic-worker:run-as-administrator:" + td.ProvisionerID + "/" + td.WorkerType,
"generic-worker:os-group:" + td.ProvisionerID + "/" + td.WorkerType + "/Administrators",
}
if config.RunTasksAsCurrentUser {
// When running as current user, chain of trust key is not private so
// generic-worker should detect that it isn't secured from task user
// and cause malformed-payload exception.
expectChainOfTrustKeyNotSecureMessage(t, td, payload)
return
}
if UACEnabled() {
_ = submitAndAssert(t, td, payload, "failed", "failed")
} else {
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}
}
func TestRunAsAdministratorEnabled(t *testing.T) {
setup(t)
if config.RunTasksAsCurrentUser {
t.Skip("Skipping since running as current user...")
}
payload := GenericWorkerPayload{
Command: []string{
`whoami /groups`,
// S-1-16-12288 is SID of 'High Mandatory Level' which implies process is elevated
// See also https://msdn.microsoft.com/en-us/library/bb625963.aspx
// and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_token_elevation
`whoami /groups | C:\Windows\System32\find.exe "S-1-16-12288" > nul`,
},
MaxRunTime: 10,
Features: FeatureFlags{
RunAsAdministrator: true,
},
OSGroups: []string{
"Administrators",
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = []string{
"generic-worker:run-as-administrator:" + td.ProvisionerID + "/" + td.WorkerType,
"generic-worker:os-group:" + td.ProvisionerID + "/" + td.WorkerType + "/Administrators",
}
if UACEnabled() {
_ = submitAndAssert(t, td, payload, "completed", "completed")
} else {
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}
}