-
Notifications
You must be signed in to change notification settings - Fork 138
Add per-auth-source cacert support to LDAP tests #22217
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
Draft
adamruzicka
wants to merge
4
commits into
SatelliteQE:master
Choose a base branch
from
adamruzicka:ldap-auth-source-cacert
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−68
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,36 @@ | ||
| """Utilities for LDAP-related test helpers.""" | ||
|
|
||
| from robottelo.config import settings | ||
|
|
||
|
|
||
| def get_ldap_cacert_pem(sat, server_type, hostname): | ||
| """Fetch the LDAP CA certificate as PEM without installing it in the OS trust store. | ||
|
|
||
| :param sat: Satellite host object | ||
| :param str server_type: 'IPA' or 'AD' | ||
| :param str hostname: LDAP server hostname | ||
| :returns: PEM-encoded CA certificate string | ||
| """ | ||
| if server_type == 'IPA': | ||
| result = sat.execute(f'curl -sf http://{hostname}/ipa/config/ca.crt') | ||
| assert result.status == 0, f'Failed to fetch IPA CA cert: {result.stderr}' | ||
| return result.stdout | ||
| if server_type == 'AD': | ||
| sat.execute('yum -y --disableplugin=foreman-protector install cifs-utils') | ||
| sat.execute( | ||
| rf'mount -t cifs -o username=administrator,pass={settings.ldap.password} ' | ||
| rf'//{hostname}/c\$ /mnt' | ||
| ) | ||
| try: | ||
| cert_path = '/mnt/Users/Administrator/Desktop/satqe-QE-SAT6-AD-CA.cer' | ||
| result = sat.execute(f'cat {cert_path}') | ||
| assert result.status == 0, 'Failed to read AD CA cert' | ||
| pem_content = result.stdout | ||
| if not pem_content.strip().startswith('-----BEGIN'): | ||
| result = sat.execute(f'openssl x509 -inform DER -in {cert_path}') | ||
| assert result.status == 0, 'Failed to convert AD CA cert to PEM' | ||
| pem_content = result.stdout | ||
| finally: | ||
| sat.execute('umount /mnt') | ||
| return pem_content | ||
| raise ValueError(f'Unsupported server_type for CA cert: {server_type}') |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
|
|
||
| """ | ||
|
|
||
| import os | ||
| from time import sleep | ||
|
|
||
| from navmazing import NavigationTriesExceeded | ||
|
|
@@ -21,7 +20,6 @@ | |
|
|
||
| from robottelo.config import settings | ||
| from robottelo.constants import ( | ||
| CERT_PATH, | ||
| HAMMER_CONFIG, | ||
| HAMMER_SESSIONS, | ||
| LDAP_ATTR, | ||
|
|
@@ -30,6 +28,7 @@ | |
| from robottelo.exceptions import CLIReturnCodeError | ||
| from robottelo.logging import logger | ||
| from robottelo.utils.datafactory import gen_string | ||
| from robottelo.utils.ldap import get_ldap_cacert_pem | ||
|
|
||
| pytestmark = [pytest.mark.destructive, pytest.mark.run_in_one_thread] | ||
|
|
||
|
|
@@ -52,36 +51,6 @@ | |
| UNABLE_AUTH = 'Unable to authenticate user' # attempting to do something without being logged in | ||
|
|
||
|
|
||
| def set_certificate_in_satellite(server_type, sat, hostname=None): | ||
| """update the cert settings in satellite based on type of ldap server""" | ||
| if server_type == 'IPA': | ||
| certfile = 'ipa.crt' | ||
| idm_cert_path_url = os.path.join(settings.ipa.hostname, 'ipa/config/ca.crt') | ||
| sat.download_file(file_url=idm_cert_path_url, local_path=CERT_PATH, file_name=certfile) | ||
| elif server_type == 'AD': | ||
| certfile = 'satqe-QE-SAT6-AD-CA.cer' | ||
| assert hostname is not None | ||
| sat.execute('yum -y --disableplugin=foreman-protector install cifs-utils') | ||
| command = r'mount -t cifs -o username=administrator,pass={0} //{1}/c\$ /mnt' | ||
| sat.execute(command.format(settings.ldap.password, hostname)) | ||
| result = sat.execute( | ||
| f'cp /mnt/Users/Administrator/Desktop/satqe-QE-SAT6-AD-CA.cer {CERT_PATH}' | ||
| ) | ||
| if result.status != 0: | ||
| raise AssertionError('Failed to copy the AD server certificate at right path') | ||
| result = sat.execute(f'update-ca-trust extract && restorecon -R {CERT_PATH}') | ||
| if result.status != 0: | ||
| raise AssertionError('Failed to update and trust the certificate') | ||
| sat.execute(f'install /{CERT_PATH}/{certfile} /etc/pki/tls/certs/') | ||
| sat.execute( | ||
| f'ln -s {certfile} /etc/pki/tls/certs/$(openssl x509 ' | ||
| f'-noout -hash -in /etc/pki/tls/certs/{certfile}).0' | ||
| ) | ||
| result = sat.execute('systemctl restart httpd') | ||
| if result.status != 0: | ||
| raise AssertionError(f'Failed to restart the httpd after applying {server_type} cert') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def ldap_tear_down(module_target_sat): | ||
| """Teardown the all ldap settings user, usergroup and ldap delete""" | ||
|
|
@@ -122,6 +91,20 @@ def rhsso_groups_teardown(module_target_sat, default_sso_host): | |
| default_sso_host.delete_sso_group(group_name) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def untrust_rhit_cas(module_target_sat): | ||
| """Temporarily remove Red Hat IT Root CAs from the system trust store.""" | ||
| anchors = '/etc/pki/ca-trust/source/anchors' | ||
| backup_dir = '/tmp/ca-backup' | ||
| module_target_sat.execute(f'mkdir -p {backup_dir}') | ||
| module_target_sat.execute(f'mv {anchors}/*-IT-Root-CA.pem {backup_dir}/') | ||
| module_target_sat.execute('update-ca-trust extract') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, |
||
| yield | ||
| module_target_sat.execute(f'mv {backup_dir}/* {anchors}/') | ||
| module_target_sat.execute(f'rm -rf {backup_dir}') | ||
| module_target_sat.execute('update-ca-trust extract') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def configure_hammer_session(parametrized_enrolled_sat, enable=True): | ||
| """Take backup of the hammer config file and enable use_sessions""" | ||
|
|
@@ -143,37 +126,42 @@ def generate_otp(secret): | |
| @pytest.mark.upgrade | ||
| @pytest.mark.parametrize('auth_data', ['AD_2019', 'IPA'], indirect=True) | ||
| def test_positive_create_with_https( | ||
| session, module_subscribe_satellite, test_name, auth_data, ldap_tear_down, module_target_sat | ||
| session, | ||
| module_subscribe_satellite, | ||
| test_name, | ||
| auth_data, | ||
| ldap_tear_down, | ||
| module_target_sat, | ||
| untrust_rhit_cas, | ||
| ): | ||
| """Create LDAP auth_source for IDM with HTTPS. | ||
| """Create LDAP auth_source for IDM/AD with LDAPS. | ||
|
lhellebr marked this conversation as resolved.
|
||
|
|
||
| :id: 7ff3daa4-2317-11ea-aeb8-d46d6dd3b5b2 | ||
|
|
||
| :customerscenario: true | ||
|
|
||
| :steps: | ||
| 1. Create a new LDAP Auth source with HTTPS, provide organization and | ||
| 1. Create a new LDAP Auth source with LDAPS, provide organization and | ||
| location information. | ||
| 2. Fill in all the fields appropriately. | ||
| 3. Login with existing LDAP user present. | ||
|
|
||
| :BZ: 1785621 | ||
|
|
||
| :expectedresults: LDAP auth source for HTTPS should be successful and LDAP login | ||
| :expectedresults: LDAP auth source for LDAPS should be successful and LDAP login | ||
| should work as expected. | ||
|
|
||
| :parametrized: yes | ||
| """ | ||
| if auth_data['auth_type'] == 'ipa': | ||
| set_certificate_in_satellite(server_type='IPA', sat=module_target_sat) | ||
| username = settings.ipa.user | ||
| account_name = auth_data['ldap_user_cn'] | ||
| server_type = 'IPA' | ||
| else: | ||
| set_certificate_in_satellite( | ||
| server_type='AD', sat=module_target_sat, hostname=auth_data['ldap_hostname'] | ||
| ) | ||
| username = settings.ldap.username | ||
| account_name = f"cn={auth_data['ldap_user_cn']},{auth_data['base_dn']}" | ||
| server_type = 'AD' | ||
| cacert_pem = get_ldap_cacert_pem(module_target_sat, server_type, auth_data['ldap_hostname']) | ||
| org = module_target_sat.api.Organization().create() | ||
| loc = module_target_sat.api.Location().create() | ||
| ldap_auth_name = gen_string('alphanumeric') | ||
|
|
@@ -184,6 +172,7 @@ def test_positive_create_with_https( | |
| 'ldap_server.name': ldap_auth_name, | ||
| 'ldap_server.host': auth_data['ldap_hostname'], | ||
| 'ldap_server.ldaps': True, | ||
| 'ldap_server.cacert': cacert_pem, | ||
| 'ldap_server.server_type': auth_data['server_type'], | ||
| 'account.account_name': account_name, | ||
| 'account.password': auth_data['ldap_user_passwd'], | ||
|
|
@@ -205,6 +194,13 @@ def test_positive_create_with_https( | |
| assert ldap_source['ldap_server']['name'] == ldap_auth_name | ||
| assert ldap_source['ldap_server']['host'] == auth_data['ldap_hostname'] | ||
| assert ldap_source['ldap_server']['port'] == '636' | ||
|
|
||
| # In AD's case, the CA cert uses CRLF line endings | ||
| # when this cert is uploaded to Satellite, the line endings are replaced | ||
| # with unix LF-only line endings. | ||
| assert ( | ||
|
lhellebr marked this conversation as resolved.
|
||
| ldap_source['ldap_server']['cacert'].strip() == cacert_pem.replace("\r\n", "\n").strip() | ||
| ) | ||
| with ( | ||
| module_target_sat.ui_session( | ||
| test_name, username, auth_data['ldap_user_passwd'] | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for reviewers:
I can't say I'm exactly happy about this test, but I'm afraid we don't really have another way of covering this in an end-to-end fashion.