Skip to content

Commit 4d5ac2a

Browse files
authored
add: randkey keytab (#946)
1 parent bede66d commit 4d5ac2a

4 files changed

Lines changed: 18 additions & 27 deletions

File tree

.kerberos/config_server.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def ktadd(
171171
172172
:param list[str] names: principals
173173
:param str fn: filename
174-
:param bool is_rand_key: generate random key
174+
:param bool is_rand_key: generate new principal keys
175175
"""
176176

177177
@abstractmethod
@@ -335,31 +335,26 @@ async def ktadd(
335335
self,
336336
names: list[str],
337337
fn: str,
338-
is_rand_key: bool = False,
338+
is_rand_key: bool = True,
339339
) -> None:
340340
"""Create or write to keytab.
341341
342342
:param list[str] names: principals
343343
:param str fn: filename
344-
:param bool is_rand_key: generate random key
344+
:param bool is_rand_key: generate new principal keys
345345
:raises PrincipalNotFoundError: on not found princ
346346
"""
347347
principals = [await self._get_raw_principal(name) for name in names]
348348
if not all(principals):
349349
raise PrincipalNotFoundError("Principal not found")
350350

351-
if is_rand_key:
352-
for princ in principals:
353-
await self.loop.run_in_executor(
354-
self.pool,
355-
princ.ktadd,
356-
fn,
357-
True,
358-
)
359-
360-
else:
361-
for princ in principals:
362-
await self.loop.run_in_executor(self.pool, princ.ktadd, fn)
351+
for princ in principals:
352+
await self.loop.run_in_executor(
353+
self.pool,
354+
princ.ktadd,
355+
fn,
356+
is_rand_key,
357+
)
363358

364359
async def lock_princ(self, name: str, **dbargs) -> None:
365360
"""Lock princ.
@@ -678,17 +673,12 @@ async def ktadd(
678673
:param KtaddRequest request: request data
679674
"""
680675
filename = os.path.join(gettempdir(), str(uuid.uuid1()))
681-
if request.is_rand_key:
682-
await kadmin.ktadd(
683-
request.names,
684-
filename,
685-
is_rand_key=request.is_rand_key,
686-
)
687-
else:
688-
await kadmin.ktadd(
689-
request.names,
690-
filename,
691-
)
676+
await kadmin.ktadd(
677+
request.names,
678+
filename,
679+
request.is_rand_key,
680+
)
681+
692682
return FileResponse(
693683
filename,
694684
background=BackgroundTask(os.unlink, filename),
91 Bytes
Binary file not shown.

.package/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ services:
230230
- dns_server_config:/DNS_server_configs/
231231
- ldap_keytab:/LDAP_keytab/
232232
- ./resolv.conf:/resolv.conf
233+
- dnsdist_confd:/dnsdist
233234
hostname: api_server
234235
environment:
235236
USE_CORE_TLS: 1

app/ldap_protocol/kerberos/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ async def ktadd(
432432
"""Generate keytab and return (aiter_bytes, TaskStruct).
433433
434434
:param list[str] names: List of principal names.
435-
:param bool is_rand_key: If True, generate random key.
435+
:param bool is_rand_key: If True, generate new principal keys.
436436
:raises KerberosNotFoundError: If principal not found.
437437
:return tuple: (aiter_bytes, (func, args, kwargs)).
438438
"""

0 commit comments

Comments
 (0)