Skip to content

Add TLS/LDAPS utilities for certificate management#246

Draft
shridhargadekar wants to merge 2 commits into
SSSD:masterfrom
shridhargadekar:add-tls-ldaps-utilities
Draft

Add TLS/LDAPS utilities for certificate management#246
shridhargadekar wants to merge 2 commits into
SSSD:masterfrom
shridhargadekar:add-tls-ldaps-utilities

Conversation

@shridhargadekar
Copy link
Copy Markdown
Contributor

  • Add TLSUtils class in sssd_test_framework/utils/tls.py

    • trust_ca_certificate(): Install CA cert to system trust store
    • trust_ca_certificate_file(): Install CA cert from file
    • configure_ldap_tls(): Configure LDAP client TLS settings
    • disable_certificate_verification(): Disable cert verification (testing only)
  • Add export_root_ca_certificate() method to ADHost

    • Exports AD root CA certificate in PEM format
    • Used for LDAPS connections on port 636
  • Add tls utility to Client role

    • Accessible via client.tls in tests

This enables LDAPS testing by allowing tests to trust AD's CA certificate:
ca_cert = ad.host.export_root_ca_certificate()
client.tls.trust_ca_certificate(ca_cert, 'ad-root-ca')
client.adcli.join(domain=domain, args=['--use-ldaps'])"

 - Add TLSUtils class in sssd_test_framework/utils/tls.py
   - trust_ca_certificate(): Install CA cert to system trust store
   - trust_ca_certificate_file(): Install CA cert from file
   - configure_ldap_tls(): Configure LDAP client TLS settings
   - disable_certificate_verification(): Disable cert verification (testing only)

 - Add export_root_ca_certificate() method to ADHost
   - Exports AD root CA certificate in PEM format
   - Used for LDAPS connections on port 636

 - Add tls utility to Client role
   - Accessible via client.tls in tests

 This enables LDAPS testing by allowing tests to trust AD's CA certificate:
   ca_cert = ad.host.export_root_ca_certificate()
   client.tls.trust_ca_certificate(ca_cert, 'ad-root-ca')
   client.adcli.join(domain=domain, args=['--use-ldaps'])"

Signed-off-by: shridhargadekar <shridhar.always@gmail.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new TLSUtils utility for certificate management and LDAP TLS configuration, and adds a method to the AD host class for exporting root CA certificates. Review feedback suggests that the LDAP configuration logic is destructive and should avoid overwriting the entire configuration file. Additionally, the implementation is currently limited to Red Hat-based distributions and lacks proper shell quoting for file paths, which could lead to issues with special characters.

Comment thread sssd_test_framework/utils/tls.py
Comment thread sssd_test_framework/utils/tls.py Outdated
Comment thread sssd_test_framework/utils/tls.py Outdated
@shridhargadekar shridhargadekar marked this pull request as draft May 19, 2026 08:25
…destructive config

Addresses review feedback:

1. Add multi-distribution support:
   - Detect RHEL/Fedora vs Debian/Ubuntu CA trust systems
   - RHEL: /etc/pki/ca-trust/source/anchors + update-ca-trust
   - Debian: /usr/local/share/ca-certificates + update-ca-certificates
   - Auto-detect /etc/openldap/ldap.conf vs /etc/ldap/ldap.conf

2. Add proper shell quoting:
   - Import shlex module
   - Use shlex.quote() for all file paths
   - Prevents issues with spaces/special characters in certificate names

3. Make LDAP config non-destructive:
   - Use grep + sed to update existing TLS_REQCERT lines
   - Append new lines only if they don't exist
   - Preserves all other LDAP configuration settings
   - Creates config file with touch if it doesn't exist

Changes:
- Added _detect_ca_trust_system() helper method
- Updated trust_ca_certificate() to use detected paths and shlex.quote()
- Rewrote configure_ldap_tls() to use sed for in-place updates
- Updated docstrings to reflect multi-distro support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant