-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kerberos): checking keytab is now working
The return code of grep was not checked so nothing was check. Use a module to check if keytab is working and reuse the same code used by "krb_keytab". The new check use the new "try_kinit" which supports checking multiple principals inside one keytab.
- Loading branch information
Showing
2 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
#!/usr/bin/python | ||
# Copyright 2022 TOSIT.IO | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
# Make coding more python3-ish | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils._text import to_native | ||
from ansible_collections.tosit.tdp.plugins.module_utils.kerberos import try_kinit | ||
|
||
def main(): | ||
argument_spec = dict( | ||
kinit_bin=dict(type='path', default='kinit'), | ||
kdestroy_bin=dict(type='path', default='kdestroy'), | ||
principal=dict(type='list', elements='str', required=True), | ||
path=dict(type='path', required=True), | ||
) | ||
|
||
module = AnsibleModule( | ||
argument_spec=argument_spec, | ||
add_file_common_args=True, | ||
supports_check_mode=True, | ||
) | ||
|
||
kinit_bin = module.params['kinit_bin'] | ||
kdestroy_bin = module.params['kdestroy_bin'] | ||
principals = module.params['principal'] | ||
keytab_path = module.params['path'] | ||
|
||
try: | ||
results = { | ||
'changed': False, | ||
} | ||
|
||
if not try_kinit(module, kinit_bin, kdestroy_bin, principals, keytab_path): | ||
raise RuntimeError("Keytab '{}' with principal '{}' is not working".format(keytab_path, principals)) | ||
|
||
module.exit_json(**results) | ||
|
||
except Exception: | ||
import traceback | ||
module.fail_json(msg=to_native(traceback.format_exc())) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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