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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
#!/usr/bin/python
from k5test import *
realm = K5Realm(create_host=False, create_user=False)
def make_client(name):
global realm
realm.addprinc(name, password(name))
ccache = os.path.join(realm.testdir,
'kadmin_ccache_' + name.replace('/', '_'))
realm.kinit(name, password(name),
flags=['-S', 'kadmin/admin', '-c', ccache])
return ccache
def kadmin_as(client, query):
global realm
return realm.run_as_client([kadmin, '-c', client, '-q', query])
def delprinc(name):
global realm
realm.run_kadminl('delprinc -force ' + name)
all_add = make_client('all_add')
all_changepw = make_client('all_changepw')
all_delete = make_client('all_delete')
all_inquire = make_client('all_inquire')
all_list = make_client('all_list')
all_modify = make_client('all_modify')
all_rename = make_client('all_rename')
some_add = make_client('some_add')
some_changepw = make_client('some_changepw')
some_delete = make_client('some_delete')
some_inquire = make_client('some_inquire')
some_modify = make_client('some_modify')
some_rename = make_client('some_rename')
restricted_add = make_client('restricted_add')
restricted_modify = make_client('restricted_modify')
restricted_rename = make_client('restricted_rename')
wctarget = make_client('wctarget')
admin = make_client('user/admin')
none = make_client('none')
restrictions = make_client('restrictions')
realm.run_kadminl('addpol -minlife "1 day" minlife')
f = open(os.path.join(realm.testdir, 'acl'), 'w')
f.write('''
all_add a
all_changepw c
all_delete d
all_inquire i
all_list l
all_modify im
all_rename ad
some_add a selected
some_changepw c selected
some_delete d selected
some_inquire i selected
some_modify im selected
some_rename d from
some_rename a to
restricted_add a * +preauth
restricted_modify im * +preauth
restricted_rename ad * +preauth
*/* d *2/*1
*/admin a
wctarget a wild/*
restrictions a type1 -policy minlife
restrictions a type2 -clearpolicy
restrictions a type3 -maxlife 1h -maxrenewlife 2h
''')
f.close()
realm.start_kadmind()
# cpw can generate four different RPC calls depending on options.
realm.addprinc('selected', 'oldpw')
realm.addprinc('unselected', 'oldpw')
for pw in ('-pw newpw', '-randkey'):
for ks in ('', '-e aes256-cts:normal'):
args = pw + ' ' + ks
out = kadmin_as(all_changepw, 'cpw %s unselected' % args)
if ('Password for "unselected@KRBTEST.COM" changed.' not in out and
'Key for "unselected@KRBTEST.COM" randomized.' not in out):
fail('cpw success (acl)')
out = kadmin_as(some_changepw, 'cpw %s selected' % args)
if ('Password for "selected@KRBTEST.COM" changed.' not in out and
'Key for "selected@KRBTEST.COM" randomized.' not in out):
fail('cpw success (target)')
out = kadmin_as(none, 'cpw %s selected' % args)
if 'Operation requires ``change-password\'\' privilege' not in out:
fail('cpw failure (no perms)')
out = kadmin_as(some_changepw, 'cpw %s unselected' % args)
if 'Operation requires ``change-password\'\' privilege' not in out:
fail('cpw failure (target)')
out = kadmin_as(none, 'cpw %s none' % args)
if ('Password for "none@KRBTEST.COM" changed.' not in out and
'Key for "none@KRBTEST.COM" randomized.' not in out):
fail('cpw success (self exemption)')
realm.run_kadminl('modprinc -policy minlife none')
out = kadmin_as(none, 'cpw %s none' % args)
if 'Current password\'s minimum life has not expired' not in out:
fail('cpw failure (minimum life)')
realm.run_kadminl('modprinc -clearpolicy none')
delprinc('selected')
delprinc('unselected')
out = kadmin_as(all_add, 'addpol policy')
realm.run_kadminl('delpol -force policy')
if 'Operation requires' in out:
fail('addpol success (acl)')
out = kadmin_as(none, 'addpol policy')
if 'Operation requires ``add\'\' privilege' not in out:
fail('addpol failure (no perms)')
# addprinc can generate two different RPC calls depending on options.
for ks in ('', '-e aes256-cts:normal'):
args = '-pw pw ' + ks
out = kadmin_as(all_add, 'addprinc %s unselected' % args)
if 'Principal "unselected@KRBTEST.COM" created.' not in out:
fail('addprinc success (acl)')
delprinc('unselected')
out = kadmin_as(some_add, 'addprinc %s selected' % args)
if 'Principal "selected@KRBTEST.COM" created.' not in out:
fail('addprinc success(target)')
delprinc('selected')
out = kadmin_as(restricted_add, 'addprinc %s unselected' % args)
if 'Principal "unselected@KRBTEST.COM" created.' not in out:
fail('addprinc success (restrictions) -- addprinc')
out = realm.run_kadminl('getprinc unselected')
if 'REQUIRES_PRE_AUTH' not in out:
fail('addprinc success (restrictions) -- restriction check')
delprinc('unselected')
out = kadmin_as(none, 'addprinc %s selected' % args)
if 'Operation requires ``add\'\' privilege' not in out:
fail('addprinc failure (no perms)')
out = kadmin_as(some_add, 'addprinc %s unselected' % args)
if 'Operation requires ``add\'\' privilege' not in out:
fail('addprinc failure (target)')
realm.addprinc('unselected', 'pw')
out = kadmin_as(all_delete, 'delprinc -force unselected')
if 'Principal "unselected@KRBTEST.COM" deleted.' not in out:
fail('delprinc success (acl)')
realm.addprinc('selected', 'pw')
out = kadmin_as(some_delete, 'delprinc -force selected')
if 'Principal "selected@KRBTEST.COM" deleted.' not in out:
fail('delprinc success (target)')
realm.addprinc('unselected', 'pw')
out = kadmin_as(none, 'delprinc -force unselected')
if 'Operation requires ``delete\'\' privilege' not in out:
fail('delprinc failure (no perms)')
out = kadmin_as(some_delete, 'delprinc -force unselected')
if 'Operation requires ``delete\'\' privilege' not in out:
fail('delprinc failure (no target)')
out = kadmin_as(all_inquire, 'getpol minlife')
if 'Policy: minlife' not in out:
fail('getpol success (acl)')
out = kadmin_as(none, 'getpol minlife')
if 'Operation requires ``get\'\' privilege' not in out:
fail('getpol failure (no perms)')
realm.run_kadminl('modprinc -policy minlife none')
out = kadmin_as(none, 'getpol minlife')
if 'Policy: minlife' not in out:
fail('getpol success (self policy exemption)')
realm.run_kadminl('modprinc -clearpolicy none')
realm.addprinc('selected', 'pw')
realm.addprinc('unselected', 'pw')
out = kadmin_as(all_inquire, 'getprinc unselected')
if 'Principal: unselected@KRBTEST.COM' not in out:
fail('getprinc success (acl)')
out = kadmin_as(some_inquire, 'getprinc selected')
if 'Principal: selected@KRBTEST.COM' not in out:
fail('getprinc success (target)')
out = kadmin_as(none, 'getprinc selected')
if 'Operation requires ``get\'\' privilege' not in out:
fail('getprinc failure (no perms)')
out = kadmin_as(some_inquire, 'getprinc unselected')
if 'Operation requires ``get\'\' privilege' not in out:
fail('getprinc failure (target)')
out = kadmin_as(none, 'getprinc none')
if 'Principal: none@KRBTEST.COM' not in out:
fail('getprinc success (self exemption)')
delprinc('selected')
delprinc('unselected')
out = kadmin_as(all_list, 'listprincs')
if 'K/M@KRBTEST.COM' not in out:
fail('listprincs success (acl)')
out = kadmin_as(none, 'listprincs')
if 'Operation requires ``list\'\' privilege' not in out:
fail('listprincs failure (no perms)')
realm.addprinc('selected', 'pw')
realm.addprinc('unselected', 'pw')
realm.run_kadminl('setstr selected key value')
realm.run_kadminl('setstr unselected key value')
out = kadmin_as(all_inquire, 'getstrs unselected')
if 'key: value' not in out:
fail('getstrs success (acl)')
out = kadmin_as(some_inquire, 'getstrs selected')
if 'key: value' not in out:
fail('getstrs success (target)')
out = kadmin_as(none, 'getstrs selected')
if 'Operation requires ``get\'\' privilege' not in out:
fail('getstrs failure (no perms)')
out = kadmin_as(some_inquire, 'getstrs unselected')
if 'Operation requires ``get\'\' privilege' not in out:
fail('getstrs failure (target)')
out = kadmin_as(none, 'getstrs none')
if '(No string attributes.)' not in out:
fail('getstrs success (self exemption)')
delprinc('selected')
delprinc('unselected')
out = kadmin_as(all_modify, 'modpol -maxlife "1 hour" policy')
if 'Operation requires' in out:
fail('modpol success (acl)')
out = kadmin_as(none, 'modpol -maxlife "1 hour" policy')
if 'Operation requires ``modify\'\' privilege' not in out:
fail('modpol failure (no perms)')
realm.addprinc('selected', 'pw')
realm.addprinc('unselected', 'pw')
out = kadmin_as(all_modify, 'modprinc -maxlife "1 hour" unselected')
if 'Principal "unselected@KRBTEST.COM" modified.' not in out:
fail('modprinc success (acl)')
out = kadmin_as(some_modify, 'modprinc -maxlife "1 hour" selected')
if 'Principal "selected@KRBTEST.COM" modified.' not in out:
fail('modprinc success (target)')
out = kadmin_as(restricted_modify, 'modprinc -maxlife "1 hour" unselected')
if 'Principal "unselected@KRBTEST.COM" modified.' not in out:
fail('modprinc success (restrictions) -- modprinc')
out = realm.run_kadminl('getprinc unselected')
if 'REQUIRES_PRE_AUTH' not in out:
fail('addprinc success (restrictions) -- restriction check')
out = kadmin_as(all_inquire, 'modprinc -maxlife "1 hour" selected')
if 'Operation requires ``modify\'\' privilege' not in out:
fail('addprinc failure (no perms)')
out = kadmin_as(some_modify, 'modprinc -maxlife "1 hour" unselected')
if 'Operation requires' not in out:
fail('modprinc failure (target)')
delprinc('selected')
delprinc('unselected')
realm.addprinc('selected', 'pw')
realm.addprinc('unselected', 'pw')
out = kadmin_as(all_modify, 'purgekeys unselected')
if 'Old keys for principal "unselected@KRBTEST.COM" purged' not in out:
fail('purgekeys success (acl)')
out = kadmin_as(some_modify, 'purgekeys selected')
if 'Old keys for principal "selected@KRBTEST.COM" purged' not in out:
fail('purgekeys success (target)')
out = kadmin_as(none, 'purgekeys selected')
if 'Operation requires ``modify\'\' privilege' not in out:
fail('purgekeys failure (no perms)')
out = kadmin_as(some_modify, 'purgekeys unselected')
if 'Operation requires ``modify\'\' privilege' not in out:
fail('purgekeys failure (target)')
delprinc('selected')
delprinc('unselected')
realm.addprinc('from', 'pw')
out = kadmin_as(all_rename, 'renprinc -force from to')
if 'Principal "from@KRBTEST.COM" renamed to "to@KRBTEST.COM".' not in out:
fail('renprinc success (acl)')
realm.run_kadminl('renprinc -force to from')
out = kadmin_as(some_rename, 'renprinc -force from to')
if 'Principal "from@KRBTEST.COM" renamed to "to@KRBTEST.COM".' not in out:
fail('renprinc success (target)')
realm.run_kadminl('renprinc -force to from')
out = kadmin_as(all_add, 'renprinc -force from to')
if 'Operation requires ``delete\'\' privilege' not in out:
fail('renprinc failure (no delete perms)')
out = kadmin_as(all_delete, 'renprinc -force from to')
if 'Operation requires ``add\'\' privilege' not in out:
fail('renprinc failure (no add perms)')
out = kadmin_as(some_rename, 'renprinc -force from notto')
if 'Operation requires ``add\'\' privilege' not in out:
fail('renprinc failure (new target)')
realm.run_kadminl('renprinc -force from notfrom')
out = kadmin_as(some_rename, 'renprinc -force notfrom to')
if 'Operation requires ``delete\'\' privilege' not in out:
fail('renprinc failure (old target)')
out = kadmin_as(restricted_rename, 'renprinc -force notfrom to')
if 'Operation requires ``add\'\' privilege' not in out:
fail('renprinc failure (restrictions)')
delprinc('notfrom')
realm.addprinc('selected', 'pw')
realm.addprinc('unselected', 'pw')
out = kadmin_as(all_modify, 'setstr unselected key value')
if 'Attribute set for principal "unselected@KRBTEST.COM".' not in out:
fail('modprinc success (acl)')
out = kadmin_as(some_modify, 'setstr selected key value')
if 'Attribute set for principal "selected@KRBTEST.COM".' not in out:
fail('modprinc success (target)')
out = kadmin_as(none, 'setstr selected key value')
if 'Operation requires ``modify\'\' privilege' not in out:
fail('addprinc failure (no perms)')
out = kadmin_as(some_modify, 'setstr unselected key value')
if 'Operation requires' not in out:
fail('modprinc failure (target)')
delprinc('selected')
delprinc('unselected')
out = kadmin_as(admin, 'addprinc -pw pw anytarget')
if 'Principal "anytarget@KRBTEST.COM" created.' not in out:
fail('addprinc success (client wildcard)')
delprinc('anytarget')
out = kadmin_as(wctarget, 'addprinc -pw pw wild/card')
if 'Principal "wild/card@KRBTEST.COM" created.' not in out:
fail('addprinc sucess (target wildcard)')
delprinc('wild/card')
out = kadmin_as(wctarget, 'addprinc -pw pw wild/card/extra')
if 'Operation requires' not in out:
fail('addprinc failure (target wildcard extra component)')
realm.addprinc('admin/user', 'pw')
out = kadmin_as(admin, 'delprinc -force admin/user')
if 'Principal "admin/user@KRBTEST.COM" deleted.' not in out:
fail('delprinc success (wildcard backreferences)')
out = kadmin_as(admin, 'delprinc -force none')
if 'Operation requires' not in out:
fail('delprinc failure (wildcard backreferences not matched)')
kadmin_as(restrictions, 'addprinc -pw pw type1')
out = realm.run_kadminl('getprinc type1')
if 'Policy: minlife' not in out:
fail('restriction (policy)')
delprinc('type1')
kadmin_as(restrictions, 'addprinc -pw pw -policy minlife type2')
out = realm.run_kadminl('getprinc type2')
if 'Policy: [none]' not in out:
fail('restriction (clearpolicy)')
delprinc('type2')
kadmin_as(restrictions, 'addprinc -pw pw -maxlife "1 minute" type3')
out = realm.run_kadminl('getprinc type3')
if ('Maximum ticket life: 0 days 00:01:00' not in out or
'Maximum renewable life: 0 days 02:00:00' not in out):
fail('restriction (maxlife low, maxrenewlife unspec)')
delprinc('type3')
kadmin_as(restrictions, 'addprinc -pw pw -maxrenewlife "1 day" type3')
out = realm.run_kadminl('getprinc type3')
if 'Maximum renewable life: 0 days 02:00:00' not in out:
fail('restriction (maxrenewlife high)')
success('kadmin ACL enforcement')
|