|
|
ad1545 |
From 3e0e8c309c70a0d379b985189c23f1bacd62a96e Mon Sep 17 00:00:00 2001
|
|
|
ad1545 |
From: Florence Blanc-Renaud <flo@redhat.com>
|
|
|
ad1545 |
Date: Fri, 30 Nov 2018 15:46:25 +0100
|
|
|
ad1545 |
Subject: [PATCH] ipatest: add test for ipa-pkinit-manage enable|disable
|
|
|
ad1545 |
|
|
|
ad1545 |
Add a test for ipa-pkinit-manage with the following scenario:
|
|
|
ad1545 |
- install master with option --no-pkinit
|
|
|
ad1545 |
- call ipa-pkinit-manage enable
|
|
|
ad1545 |
- call ipa-pkinit-manage disable
|
|
|
ad1545 |
- call ipa-pkinit-manage enable
|
|
|
ad1545 |
|
|
|
ad1545 |
At each step, check that the PKINIT cert is consistent with the
|
|
|
ad1545 |
expectations: when pkinit is enabled, the cert is signed by IPA
|
|
|
ad1545 |
CA and tracked by 'IPA' ca helper, but when pkinit is disabled,
|
|
|
ad1545 |
the cert is self-signed and tracked by 'SelfSign' CA helper.
|
|
|
ad1545 |
|
|
|
ad1545 |
Related to https://pagure.io/freeipa/issue/7200
|
|
|
ad1545 |
|
|
|
ad1545 |
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
|
|
|
ad1545 |
Reviewed-By: Christian Heimes <cheimes@redhat.com>
|
|
|
ad1545 |
---
|
|
|
ad1545 |
.../test_integration/test_pkinit_manage.py | 111 ++++++++++++++++++
|
|
|
ad1545 |
1 file changed, 111 insertions(+)
|
|
|
ad1545 |
create mode 100644 ipatests/test_integration/test_pkinit_manage.py
|
|
|
ad1545 |
|
|
|
ad1545 |
diff --git a/ipatests/test_integration/test_pkinit_manage.py b/ipatests/test_integration/test_pkinit_manage.py
|
|
|
ad1545 |
new file mode 100644
|
|
|
ad1545 |
index 0000000000000000000000000000000000000000..bc1d9e338cdf4e7a503b3c83ac12792894eecce2
|
|
|
ad1545 |
--- /dev/null
|
|
|
ad1545 |
+++ b/ipatests/test_integration/test_pkinit_manage.py
|
|
|
ad1545 |
@@ -0,0 +1,111 @@
|
|
|
ad1545 |
+#
|
|
|
ad1545 |
+# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
|
|
|
ad1545 |
+#
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+"""
|
|
|
ad1545 |
+Module provides tests for the ipa-pkinit-manage command.
|
|
|
ad1545 |
+"""
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+from __future__ import absolute_import
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+from ipalib import x509
|
|
|
ad1545 |
+from ipaplatform.paths import paths
|
|
|
ad1545 |
+from ipapython.dn import DN
|
|
|
ad1545 |
+from ipatests.test_integration.base import IntegrationTest
|
|
|
ad1545 |
+from ipatests.pytest_ipa.integration import tasks
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+SELFSIGNED_CA_HELPER = 'SelfSign'
|
|
|
ad1545 |
+IPA_CA_HELPER = 'IPA'
|
|
|
ad1545 |
+PKINIT_STATUS_ENABLED = 'enabled'
|
|
|
ad1545 |
+PKINIT_STATUS_DISABLED = 'disabled'
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+def check_pkinit_status(host, status):
|
|
|
ad1545 |
+ """Ensures that ipa-pkinit-manage status returns the expected state"""
|
|
|
ad1545 |
+ result = host.run_command(['ipa-pkinit-manage', 'status'],
|
|
|
ad1545 |
+ raiseonerr=False)
|
|
|
ad1545 |
+ assert result.returncode == 0
|
|
|
ad1545 |
+ assert 'PKINIT is {}'.format(status) in result.stdout_text
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+def check_pkinit_tracking(host, ca_helper):
|
|
|
ad1545 |
+ """Ensures that the PKINIT cert is tracked by the expected helper"""
|
|
|
ad1545 |
+ result = host.run_command(['getcert', 'list', '-f', paths.KDC_CERT],
|
|
|
ad1545 |
+ raiseonerr=False)
|
|
|
ad1545 |
+ assert result.returncode == 0
|
|
|
ad1545 |
+ # Make sure that only one request exists
|
|
|
ad1545 |
+ assert result.stdout_text.count('Request ID') == 1
|
|
|
ad1545 |
+ # Make sure that the right CA helper is used to track the cert
|
|
|
ad1545 |
+ assert 'CA: {}'.format(ca_helper) in result.stdout_text
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+def check_pkinit_cert_issuer(host, issuer):
|
|
|
ad1545 |
+ """Ensures that the PKINIT cert is signed by the expected issuer"""
|
|
|
ad1545 |
+ data = host.get_file_contents(paths.KDC_CERT)
|
|
|
ad1545 |
+ pkinit_cert = x509.load_pem_x509_certificate(data)
|
|
|
ad1545 |
+ # Make sure that the issuer is the expected one
|
|
|
ad1545 |
+ assert DN(pkinit_cert.issuer) == DN(issuer)
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+def check_pkinit(host, enabled=True):
|
|
|
ad1545 |
+ """Checks that PKINIT is configured as expected
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+ If enabled:
|
|
|
ad1545 |
+ ipa-pkinit-manage status must return 'PKINIT is enabled'
|
|
|
ad1545 |
+ the certificate must be tracked by IPA CA helper
|
|
|
ad1545 |
+ the certificate must be signed by IPA CA
|
|
|
ad1545 |
+ If disabled:
|
|
|
ad1545 |
+ ipa-pkinit-manage status must return 'PKINIT is disabled'
|
|
|
ad1545 |
+ the certificate must be tracked by SelfSign CA helper
|
|
|
ad1545 |
+ the certificate must be self-signed
|
|
|
ad1545 |
+ """
|
|
|
ad1545 |
+ if enabled:
|
|
|
ad1545 |
+ # When pkinit is enabled:
|
|
|
ad1545 |
+ # cert is tracked by IPA CA helper
|
|
|
ad1545 |
+ # cert is signed by IPA CA
|
|
|
ad1545 |
+ check_pkinit_status(host, PKINIT_STATUS_ENABLED)
|
|
|
ad1545 |
+ check_pkinit_tracking(host, IPA_CA_HELPER)
|
|
|
ad1545 |
+ check_pkinit_cert_issuer(
|
|
|
ad1545 |
+ host,
|
|
|
ad1545 |
+ 'CN=Certificate Authority,O={}'.format(host.domain.realm))
|
|
|
ad1545 |
+ else:
|
|
|
ad1545 |
+ # When pkinit is disabled
|
|
|
ad1545 |
+ # cert is tracked by 'SelfSign' CA helper
|
|
|
ad1545 |
+ # cert is self-signed
|
|
|
ad1545 |
+ check_pkinit_status(host, PKINIT_STATUS_DISABLED)
|
|
|
ad1545 |
+ check_pkinit_tracking(host, SELFSIGNED_CA_HELPER)
|
|
|
ad1545 |
+ check_pkinit_cert_issuer(
|
|
|
ad1545 |
+ host,
|
|
|
ad1545 |
+ 'CN={},O={}'.format(host.hostname, host.domain.realm))
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+class TestPkinitManage(IntegrationTest):
|
|
|
ad1545 |
+ """Tests the ipa-pkinit-manage command.
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+ ipa-pkinit-manage can be used to enable, disable or check
|
|
|
ad1545 |
+ the status of PKINIT.
|
|
|
ad1545 |
+ When pkinit is enabled, the kerberos server is using a certificate
|
|
|
ad1545 |
+ signed either externally or by IPA CA. In the latter case, certmonger
|
|
|
ad1545 |
+ is tracking the cert with IPA helper.
|
|
|
ad1545 |
+ When pkinit is disabled, the kerberos server is using a self-signed
|
|
|
ad1545 |
+ certificate that is tracked by certmonger with the SelfSigned helper.
|
|
|
ad1545 |
+ """
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+ @classmethod
|
|
|
ad1545 |
+ def install(cls, mh):
|
|
|
ad1545 |
+ # Install the master with PKINIT disabled
|
|
|
ad1545 |
+ tasks.install_master(cls.master, extra_args=['--no-pkinit'])
|
|
|
ad1545 |
+ check_pkinit(cls.master, enabled=False)
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+ def test_pkinit_enable(self):
|
|
|
ad1545 |
+ self.master.run_command(['ipa-pkinit-manage', 'enable'])
|
|
|
ad1545 |
+ check_pkinit(self.master, enabled=True)
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+ def test_pkinit_disable(self):
|
|
|
ad1545 |
+ self.master.run_command(['ipa-pkinit-manage', 'disable'])
|
|
|
ad1545 |
+ check_pkinit(self.master, enabled=False)
|
|
|
ad1545 |
+
|
|
|
ad1545 |
+ def test_pkinit_reenable(self):
|
|
|
ad1545 |
+ self.master.run_command(['ipa-pkinit-manage', 'enable'])
|
|
|
ad1545 |
+ check_pkinit(self.master, enabled=True)
|
|
|
ad1545 |
--
|
|
|
ad1545 |
2.17.2
|
|
|
ad1545 |
|