Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #6185/512bf4b7 backport][stable-6] ldap moduls: add optional ca_cert_file option #6217

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/xxxx-ldap-ca-cert-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ldap modules - add ``ca_path`` option (https://github.com/ansible-collections/community.general/pull/6185).
5 changes: 5 additions & 0 deletions plugins/doc_fragments/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class ModuleDocFragment(object):
- The password to use with I(bind_dn).
type: str
default: ''
ca_path:
description:
- Set the path to PEM file with CA certs.
type: path
version_added: "6.5.0"
dn:
required: true
description:
Expand Down
5 changes: 5 additions & 0 deletions plugins/module_utils/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def gen_specs(**specs):
specs.update({
'bind_dn': dict(),
'bind_pw': dict(default='', no_log=True),
'ca_path': dict(type='path'),
'dn': dict(required=True),
'referrals_chasing': dict(type='str', default='anonymous', choices=['disabled', 'anonymous']),
'server_uri': dict(default='ldapi:///'),
Expand All @@ -52,6 +53,7 @@ def __init__(self, module):
self.module = module
self.bind_dn = self.module.params['bind_dn']
self.bind_pw = self.module.params['bind_pw']
self.ca_path = self.module.params['ca_path']
self.referrals_chasing = self.module.params['referrals_chasing']
self.server_uri = self.module.params['server_uri']
self.start_tls = self.module.params['start_tls']
Expand Down Expand Up @@ -97,6 +99,9 @@ def _connect_to_ldap(self):
if not self.verify_cert:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

if self.ca_path:
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, self.ca_path)

connection = ldap.initialize(self.server_uri)

if self.referrals_chasing == 'disabled':
Expand Down