| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2016 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
import pytest |
| 10 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from lib389.agreement import * |
| 13 |
from test389.topologies import topology_m2_gssapi, gssapi_ack |
| 14 |
|
| 15 |
pytestmark = pytest.mark.tier2 |
| 16 |
|
| 17 |
######################################### |
| 18 |
# |
| 19 |
# WARNING!!!!! If this test is failing, and your here to find out why, the |
| 20 |
# reason is very likely your hosts file!!!! |
| 21 |
# |
| 22 |
# IT MUST LOOK LIKE THIS BELOW: Note the unique IPS for each kdc name! |
| 23 |
# |
| 24 |
# 127.0.0.1 ldapkdc.example.com localhost |
| 25 |
# 127.0.1.1 ldapkdc1.example.com |
| 26 |
# 127.0.2.1 ldapkdc2.example.com |
| 27 |
# |
| 28 |
######################################### |
| 29 |
|
| 30 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 31 |
log = logging.getLogger(__name__) |
| 32 |
|
| 33 |
REALM = "EXAMPLE.COM" |
| 34 |
|
| 35 |
HOST_SUPPLIER_1 = 'ldapkdc1.example.com' |
| 36 |
HOST_SUPPLIER_2 = 'ldapkdc2.example.com' |
| 37 |
|
| 38 |
|
| 39 |
def _create_machine_ou(inst): |
| 40 |
inst.add_s(Entry(("ou=Machines,%s" % DEFAULT_SUFFIX, { |
| 41 |
'objectClass': 'top organizationalUnit'.split(), |
| 42 |
'ou': 'Machines' |
| 43 |
} |
| 44 |
)) |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
def _create_machine_account(inst, name): |
| 49 |
# Create the simple security objects for the servers to replicate to |
| 50 |
inst.add_s(Entry(("uid=%s,ou=Machines,%s" % (name, DEFAULT_SUFFIX), |
| 51 |
{ |
| 52 |
'objectClass': 'top account'.split(), |
| 53 |
'uid': name |
| 54 |
} |
| 55 |
))) |
| 56 |
|
| 57 |
|
| 58 |
def _check_machine_account(inst, name): |
| 59 |
r = inst.search_s('ou=Machines,%s' % DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=%s)' % name) |
| 60 |
if len(r) > 0: |
| 61 |
return True |
| 62 |
return False |
| 63 |
|
| 64 |
|
| 65 |
def _allow_machine_account(inst, name): |
| 66 |
# First we need to get the mapping tree dn |
| 67 |
mt = inst.mappingtree.list(suffix=DEFAULT_SUFFIX)[0] |
| 68 |
inst.modify_s('cn=replica,%s' % mt.dn, [ |
| 69 |
(ldap.MOD_REPLACE, 'nsDS5ReplicaBindDN', f"uid={name},ou=Machines,{DEFAULT_SUFFIX}".encode('utf-8')) |
| 70 |
]) |
| 71 |
|
| 72 |
@gssapi_ack |
| 73 |
def test_gssapi_repl(topology_m2_gssapi): |
| 74 |
"""Test gssapi authenticated replication agreement of two suppliers using KDC |
| 75 |
|
| 76 |
:id: 552850aa-afc3-473e-9c39-aae802b46f11 |
| 77 |
|
| 78 |
:setup: MMR with two suppliers |
| 79 |
|
| 80 |
:steps: |
| 81 |
1. Create the locations on each supplier for the other supplier to bind to |
| 82 |
2. Set on the cn=replica config to accept the other suppliers mapping under mapping tree |
| 83 |
3. Create the replication agreements from M1->M2 and vice versa (M2->M1) |
| 84 |
4. Set the replica bind method to sasl gssapi for both agreements |
| 85 |
5. Initialize all the agreements |
| 86 |
6. Create a user on M1 and check if user is created on M2 |
| 87 |
7. Create a user on M2 and check if user is created on M1 |
| 88 |
|
| 89 |
:expectedresults: |
| 90 |
1. Locations should be added successfully |
| 91 |
2. Configuration should be added successfully |
| 92 |
3. Replication agreements should be added successfully |
| 93 |
4. Bind method should be set to sasl gssapi for both agreements |
| 94 |
5. Agreements should be initialized successfully |
| 95 |
6. Test User should be created on M1 and M2 both |
| 96 |
7. Test User should be created on M1 and M2 both |
| 97 |
""" |
| 98 |
supplier1 = topology_m2_gssapi.ms["supplier1"] |
| 99 |
supplier2 = topology_m2_gssapi.ms["supplier2"] |
| 100 |
|
| 101 |
# Create the locations on each supplier for the other to bind to. |
| 102 |
_create_machine_ou(supplier1) |
| 103 |
_create_machine_ou(supplier2) |
| 104 |
|
| 105 |
_create_machine_account(supplier1, 'ldap/%s' % HOST_SUPPLIER_1) |
| 106 |
_create_machine_account(supplier1, 'ldap/%s' % HOST_SUPPLIER_2) |
| 107 |
_create_machine_account(supplier2, 'ldap/%s' % HOST_SUPPLIER_1) |
| 108 |
_create_machine_account(supplier2, 'ldap/%s' % HOST_SUPPLIER_2) |
| 109 |
|
| 110 |
# Set on the cn=replica config to accept the other suppliers princ mapping under mapping tree |
| 111 |
_allow_machine_account(supplier1, 'ldap/%s' % HOST_SUPPLIER_2) |
| 112 |
_allow_machine_account(supplier2, 'ldap/%s' % HOST_SUPPLIER_1) |
| 113 |
|
| 114 |
# |
| 115 |
# Create all the agreements |
| 116 |
# |
| 117 |
# Creating agreement from supplier 1 to supplier 2 |
| 118 |
|
| 119 |
# Set the replica bind method to sasl gssapi |
| 120 |
properties = {RA_NAME: 'meTo_' + supplier2.host + ':' + str(supplier2.port), |
| 121 |
RA_METHOD: 'SASL/GSSAPI', |
| 122 |
RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]} |
| 123 |
m1_m2_agmt = supplier1.agreement.create(suffix=SUFFIX, host=supplier2.host, port=supplier2.port, properties=properties) |
| 124 |
if not m1_m2_agmt: |
| 125 |
log.fatal("Fail to create a supplier -> supplier replica agreement") |
| 126 |
sys.exit(1) |
| 127 |
log.debug("%s created" % m1_m2_agmt) |
| 128 |
|
| 129 |
# Creating agreement from supplier 2 to supplier 1 |
| 130 |
|
| 131 |
# Set the replica bind method to sasl gssapi |
| 132 |
properties = {RA_NAME: 'meTo_' + supplier1.host + ':' + str(supplier1.port), |
| 133 |
RA_METHOD: 'SASL/GSSAPI', |
| 134 |
RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]} |
| 135 |
m2_m1_agmt = supplier2.agreement.create(suffix=SUFFIX, host=supplier1.host, port=supplier1.port, properties=properties) |
| 136 |
if not m2_m1_agmt: |
| 137 |
log.fatal("Fail to create a supplier -> supplier replica agreement") |
| 138 |
sys.exit(1) |
| 139 |
log.debug("%s created" % m2_m1_agmt) |
| 140 |
|
| 141 |
# Allow the replicas to get situated with the new agreements... |
| 142 |
time.sleep(5) |
| 143 |
|
| 144 |
# |
| 145 |
# Initialize all the agreements |
| 146 |
# |
| 147 |
agmt = Agreement(supplier1, m1_m2_agmt) |
| 148 |
agmt.begin_reinit() |
| 149 |
agmt.wait_reinit() |
| 150 |
|
| 151 |
# Check replication is working... |
| 152 |
if supplier1.testReplication(DEFAULT_SUFFIX, supplier2): |
| 153 |
log.info('Replication is working: supplier1 -> supplier2') |
| 154 |
else: |
| 155 |
log.fatal('Replication is not working: supplier1 -> supplier2') |
| 156 |
assert False |
| 157 |
|
| 158 |
if supplier2.testReplication(DEFAULT_SUFFIX, supplier1): |
| 159 |
log.info('Replication is working: supplier2 -> supplier1') |
| 160 |
else: |
| 161 |
log.fatal('Replication is not working: supplier2 -> supplier1') |
| 162 |
assert False |
| 163 |
|
| 164 |
# Add a user to supplier 1 |
| 165 |
_create_machine_account(supplier1, 'http/one.example.com') |
| 166 |
# Check it's on 2 |
| 167 |
time.sleep(5) |
| 168 |
assert (_check_machine_account(supplier2, 'http/one.example.com')) |
| 169 |
# Add a user to supplier 2 |
| 170 |
_create_machine_account(supplier2, 'http/two.example.com') |
| 171 |
# Check it's on 1 |
| 172 |
time.sleep(5) |
| 173 |
assert (_check_machine_account(supplier2, 'http/two.example.com')) |
| 174 |
|
| 175 |
|
| 176 |
if __name__ == '__main__': |
| 177 |
# Run isolated |
| 178 |
# -s for DEBUG mode |
| 179 |
CURRENT_FILE = os.path.realpath(__file__) |
| 180 |
pytest.main("-s %s" % CURRENT_FILE) |