gssapi_repl_test.py 5.9 KB

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