main.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. ---
  2. # A number of checks to be performed, but ultimately modify oauth/cluster with
  3. # an additional identityProvider for OIDC.
  4. #
  5. - name: Check for the KeyCloak resource
  6. k8s_info:
  7. kubeconfig: tmp/kubeconfig-ocp4
  8. validate_certs: no
  9. api_version: keycloak.org/v1alpha1
  10. kind: keycloak
  11. namespace: rhsso
  12. name: rhsso
  13. register: sso_cr
  14. - assert:
  15. that:
  16. - (sso_cr.resources | length) == 1
  17. - sso_cr.resources[0].spec.externalAccess.enabled
  18. - sso_cr.resources[0].status.ready
  19. - sso_cr.resources[0].status.phase == "reconciling"
  20. fail_msg: "ERROR: RHSSO instance is missing or not configured correctly."
  21. success_msg: "OK: RHSSO instance is configured correctly."
  22. - name: Store RHSSO URL as a fact
  23. set_fact:
  24. sso_url: "{{ sso_cr.resources[0].status.externalURL }}"
  25. - name: Check for the realm resource
  26. k8s_info:
  27. kubeconfig: tmp/kubeconfig-ocp4
  28. validate_certs: no
  29. api_version: keycloak.org/v1alpha1
  30. kind: keycloakrealm
  31. namespace: rhsso
  32. name: sample-realm
  33. register: sso_realm
  34. - assert:
  35. that:
  36. - (sso_realm.resources | length) == 1
  37. - sso_realm.resources[0].spec.realm.id == "sample"
  38. - sso_realm.resources[0].spec.realm.realm == "sample"
  39. - sso_realm.resources[0].spec.realm.enabled
  40. - sso_realm.resources[0].status.ready
  41. - sso_realm.resources[0].status.phase == "reconciling"
  42. fail_msg: "ERROR: RHSSO sample realm is missing or not configured correctly."
  43. success_msg: "OK: RHSSO sample realm is configured correctly."
  44. - name: Check that the client is configured correctly
  45. k8s_info:
  46. kubeconfig: tmp/kubeconfig-ocp4
  47. validate_certs: no
  48. api_version: keycloak.org/v1alpha1
  49. kind: keycloakclient
  50. namespace: rhsso
  51. name: sample-client
  52. register: sso_client
  53. - assert:
  54. that:
  55. - (sso_client.resources | length) == 1
  56. - sso_client.resources[0].spec.client.clientId == "sample-client"
  57. - '"offline_access" in sso_client.resources[0].spec.client.defaultClientScopes'
  58. - sso_client.resources[0].status.ready
  59. - sso_client.resources[0].status.phase == "reconciling"
  60. fail_msg: "ERROR: RHSSO sample-client is missing or not configured correctly."
  61. success_msg: "OK: RHSSO sample-client is configured correctly."
  62. - name: Store sample-client's secret name as a fact
  63. set_fact:
  64. sso_client_secret: "{{ sso_client.resources[0].status.secondaryResources.Secret[0] }}"
  65. - name: Read the sample-client's actual secret
  66. k8s_info:
  67. kubeconfig: tmp/kubeconfig-ocp4
  68. validate_certs: no
  69. api_version: v1
  70. kind: secret
  71. namespace: rhsso
  72. name: "{{ sso_client_secret }}"
  73. register: sso_client_secret
  74. - assert:
  75. that:
  76. - (sso_client_secret.resources | length) == 1
  77. - sso_client_secret.resources[0].data.CLIENT_SECRET is defined
  78. fail_msg: "ERROR: sample-client secret is missing."
  79. success_msg: "OK: sample-client secret found."
  80. - name: Store the secret as a fact
  81. set_fact:
  82. sso_client_secret: "{{ sso_client_secret.resources[0].data.CLIENT_SECRET }}"
  83. - name: Check that the ingresscontroller's defaultCertificate is set
  84. k8s_info:
  85. kubeconfig: tmp/kubeconfig-ocp4
  86. validate_certs: no
  87. api_version: operator.openshift.io/v1
  88. kind: ingresscontroller
  89. namespace: openshift-ingress-operator
  90. name: default
  91. register: ingress_ca
  92. - name: Get the router's default CA content
  93. k8s_info:
  94. kubeconfig: tmp/kubeconfig-ocp4
  95. validate_certs: no
  96. api_version: v1
  97. kind: secret
  98. namespace: openshift-config
  99. name: "{{ ingress_ca.resources[0].spec.defaultCertificate.name }}"
  100. register: ingress_ca
  101. - name: Store the CA cert as an actual fact
  102. set_fact:
  103. ingress_ca: "{{ ingress_ca.resources[0].data['tls.crt'] }}"
  104. - name: Check on oauth/cluster
  105. k8s_info:
  106. kubeconfig: tmp/kubeconfig-ocp4
  107. validate_certs: no
  108. api_version: config.openshift.io/v1
  109. kind: oauth
  110. name: cluster
  111. register: cluster_auth
  112. - assert:
  113. that:
  114. - (cluster_auth.resources | length) == 1
  115. - (cluster_auth.resources[0].spec.identityProviders | length) >= 1
  116. - cluster_auth.resources[0].spec.identityProviders[0].type == "HTPasswd"
  117. fail_msg: "ERROR: OpenShift cluster authentication is not configured correctly."
  118. success_msg: "OK: OpenShift cluster authentication is configured correctly."
  119. - name: Make certain client secret exists in openshift-config
  120. k8s:
  121. kubeconfig: tmp/kubeconfig-ocp4
  122. validate_certs: no
  123. api_version: v1
  124. kind: secret
  125. namespace: openshift-config
  126. name: sso-client-secret
  127. definition:
  128. metadata:
  129. labels:
  130. app: sso
  131. type: Opaque
  132. data:
  133. clientSecret: "{{ sso_client_secret }}"
  134. - name: Make certain router CA CM exists in openshift-config
  135. k8s:
  136. kubeconfig: tmp/kubeconfig-ocp4
  137. validate_certs: no
  138. api_version: v1
  139. kind: configmap
  140. namespace: openshift-config
  141. name: sso-ingress-ca
  142. definition:
  143. metadata:
  144. labels:
  145. app: sso
  146. data:
  147. ca.crt: "{{ ingress_ca | string | b64decode }}"
  148. - name: Figure out what to do with oauth/cluster - option 1
  149. set_fact:
  150. oauth_op: add
  151. oauth_path: /spec/identityProviders/-
  152. when: (cluster_auth.resources[0].spec.identityProviders | length) == 1
  153. - name: Figure out what to do with oauth/cluster - option 2
  154. set_fact:
  155. oauth_op: replace
  156. oauth_path: /spec/identityProviders/1
  157. when: (cluster_auth.resources[0].spec.identityProviders | length) == 2
  158. - name: Patch oauth/cluster
  159. kubernetes.core.k8s_json_patch:
  160. kubeconfig: tmp/kubeconfig-ocp4
  161. validate_certs: no
  162. api_version: config.openshift.io/v1
  163. kind: oauth
  164. name: cluster
  165. patch:
  166. - op: "{{ oauth_op }}"
  167. path: "{{ oauth_path }}"
  168. value:
  169. name: oidc_sso
  170. mappingMethod: claim
  171. type: OpenID
  172. openID:
  173. clientID: sample-client
  174. clientSecret:
  175. name: sso-client-secret
  176. ca:
  177. name: sso-ingress-ca
  178. claims:
  179. preferredUsername:
  180. - preferred_username
  181. name:
  182. - name
  183. email:
  184. - email
  185. groups:
  186. - groups
  187. issuer: "{{ sso_url }}/auth/realms/sample"
  188. # TODO: Wait for clusteroperator/authentication to stop progressing.
  189. # TODO: Check that all keycloakuser (or all users?) have offline_access realm role?
  190. ...