gssapi_repl_test.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.topologies import topology_m2
  13. pytestmark = pytest.mark.tier2
  14. #########################################
  15. #
  16. # WARNING!!!!! If this test is failing, and your here to find out why, the
  17. # reason is very likely your hosts file!!!!
  18. #
  19. # IT MUST LOOK LIKE THIS BELOW: Note the unique IPS for each kdc name!
  20. #
  21. # 127.0.0.1 ldapkdc.example.com localhost
  22. # 127.0.1.1 ldapkdc1.example.com
  23. # 127.0.2.1 ldapkdc2.example.com
  24. #
  25. #########################################
  26. logging.getLogger(__name__).setLevel(logging.DEBUG)
  27. log = logging.getLogger(__name__)
  28. REALM = "EXAMPLE.COM"
  29. HOST_MASTER_1 = 'ldapkdc1.example.com'
  30. HOST_MASTER_2 = 'ldapkdc2.example.com'
  31. def _create_machine_ou(inst):
  32. inst.add_s(Entry(("ou=Machines,%s" % DEFAULT_SUFFIX, {
  33. 'objectClass': 'top organizationalUnit'.split(),
  34. 'ou': 'Machines'
  35. }
  36. ))
  37. )
  38. def _create_machine_account(inst, name):
  39. # Create the simple security objects for the servers to replicate to
  40. inst.add_s(Entry(("uid=%s,ou=Machines,%s" % (name, DEFAULT_SUFFIX),
  41. {
  42. 'objectClass': 'top account'.split(),
  43. 'uid': name
  44. }
  45. )))
  46. def _check_machine_account(inst, name):
  47. r = inst.search_s('ou=Machines,%s' % DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=%s)' % name)
  48. if len(r) > 0:
  49. return True
  50. return False
  51. def _allow_machine_account(inst, name):
  52. # First we need to get the mapping tree dn
  53. mt = inst.mappingtree.list(suffix=DEFAULT_SUFFIX)[0]
  54. inst.modify_s('cn=replica,%s' % mt.dn, [
  55. (ldap.MOD_REPLACE, 'nsDS5ReplicaBindDN', "uid=%s,ou=Machines,%s" % (name, DEFAULT_SUFFIX))
  56. ])
  57. def test_gssapi_repl(topology_m2):
  58. """Test gssapi authenticated replication agreement of two masters using KDC
  59. :id: 552850aa-afc3-473e-9c39-aae802b46f11
  60. :setup: MMR with two masters
  61. :steps:
  62. 1. Create the locations on each master for the other master to bind to
  63. 2. Set on the cn=replica config to accept the other masters mapping under mapping tree
  64. 3. Create the replication agreements from M1->M2 and vice versa (M2->M1)
  65. 4. Set the replica bind method to sasl gssapi for both agreements
  66. 5. Initialize all the agreements
  67. 6. Create a user on M1 and check if user is created on M2
  68. 7. Create a user on M2 and check if user is created on M1
  69. :expectedresults:
  70. 1. Locations should be added successfully
  71. 2. Configuration should be added successfully
  72. 3. Replication agreements should be added successfully
  73. 4. Bind method should be set to sasl gssapi for both agreements
  74. 5. Agreements should be initialized successfully
  75. 6. Test User should be created on M1 and M2 both
  76. 7. Test User should be created on M1 and M2 both
  77. """
  78. return
  79. master1 = topology_m2.ms["master1"]
  80. master2 = topology_m2.ms["master2"]
  81. # Create the locations on each master for the other to bind to.
  82. _create_machine_ou(master1)
  83. _create_machine_ou(master2)
  84. _create_machine_account(master1, 'ldap/%s' % HOST_MASTER_1)
  85. _create_machine_account(master1, 'ldap/%s' % HOST_MASTER_2)
  86. _create_machine_account(master2, 'ldap/%s' % HOST_MASTER_1)
  87. _create_machine_account(master2, 'ldap/%s' % HOST_MASTER_2)
  88. # Set on the cn=replica config to accept the other masters princ mapping under mapping tree
  89. _allow_machine_account(master1, 'ldap/%s' % HOST_MASTER_2)
  90. _allow_machine_account(master2, 'ldap/%s' % HOST_MASTER_1)
  91. #
  92. # Create all the agreements
  93. #
  94. # Creating agreement from master 1 to master 2
  95. # Set the replica bind method to sasl gssapi
  96. properties = {RA_NAME: r'meTo_$host:$port',
  97. RA_METHOD: 'SASL/GSSAPI',
  98. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  99. m1_m2_agmt = master1.agreement.create(suffix=SUFFIX, host=master2.host, port=master2.port, properties=properties)
  100. if not m1_m2_agmt:
  101. log.fatal("Fail to create a master -> master replica agreement")
  102. sys.exit(1)
  103. log.debug("%s created" % m1_m2_agmt)
  104. # Creating agreement from master 2 to master 1
  105. # Set the replica bind method to sasl gssapi
  106. properties = {RA_NAME: r'meTo_$host:$port',
  107. RA_METHOD: 'SASL/GSSAPI',
  108. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  109. m2_m1_agmt = master2.agreement.create(suffix=SUFFIX, host=master1.host, port=master1.port, properties=properties)
  110. if not m2_m1_agmt:
  111. log.fatal("Fail to create a master -> master replica agreement")
  112. sys.exit(1)
  113. log.debug("%s created" % m2_m1_agmt)
  114. # Allow the replicas to get situated with the new agreements...
  115. time.sleep(5)
  116. #
  117. # Initialize all the agreements
  118. #
  119. master1.agreement.init(SUFFIX, HOST_MASTER_2, PORT_MASTER_2)
  120. master1.waitForReplInit(m1_m2_agmt)
  121. # Check replication is working...
  122. if master1.testReplication(DEFAULT_SUFFIX, master2):
  123. log.info('Replication is working.')
  124. else:
  125. log.fatal('Replication is not working.')
  126. assert False
  127. # Add a user to master 1
  128. _create_machine_account(master1, 'http/one.example.com')
  129. # Check it's on 2
  130. time.sleep(5)
  131. assert (_check_machine_account(master2, 'http/one.example.com'))
  132. # Add a user to master 2
  133. _create_machine_account(master2, 'http/two.example.com')
  134. # Check it's on 1
  135. time.sleep(5)
  136. assert (_check_machine_account(master2, 'http/two.example.com'))
  137. if __name__ == '__main__':
  138. # Run isolated
  139. # -s for DEBUG mode
  140. CURRENT_FILE = os.path.realpath(__file__)
  141. pytest.main("-s %s" % CURRENT_FILE)