secure.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ---
  2. - name: Create passthrough route for docker-registry
  3. oc_route:
  4. kubeconfig: "{{ openshift_hosted_kubeconfig }}"
  5. name: docker-registry
  6. namespace: default
  7. service_name: docker-registry
  8. state: present
  9. tls_termination: passthrough
  10. run_once: true
  11. - name: Determine if registry certificate must be created
  12. stat:
  13. path: "{{ openshift_master_config_dir }}/{{ item }}"
  14. with_items:
  15. - registry.crt
  16. - registry.key
  17. register: docker_registry_certificates_stat_result
  18. changed_when: false
  19. failed_when: false
  20. - name: Retrieve registry service IP
  21. oc_service:
  22. namespace: default
  23. name: docker-registry
  24. state: list
  25. register: docker_registry_service_ip
  26. changed_when: false
  27. - set_fact:
  28. docker_registry_route_hostname: "{{ 'docker-registry-default.' ~ (openshift_master_default_subdomain | default('router.default.svc.cluster.local', true)) }}"
  29. - name: Create registry certificates if they do not exist
  30. command: >
  31. {{ openshift.common.client_binary }} adm ca create-server-cert
  32. --signer-cert={{ openshift_master_config_dir }}/ca.crt
  33. --signer-key={{ openshift_master_config_dir }}/ca.key
  34. --signer-serial={{ openshift_master_config_dir }}/ca.serial.txt
  35. --hostnames="{{ docker_registry_service_ip.results.clusterip }},docker-registry.default.svc.cluster.local,{{ docker_registry_route_hostname }}"
  36. --cert={{ openshift_master_config_dir }}/registry.crt
  37. --key={{ openshift_master_config_dir }}/registry.key
  38. when: False in (docker_registry_certificates_stat_result.results | default([]) | oo_collect(attribute='stat.exists') | list)
  39. - name: Create the secret for the registry certificates
  40. oc_secret:
  41. kubeconfig: "{{ openshift_hosted_kubeconfig }}"
  42. name: registry-certificates
  43. namespace: default
  44. state: present
  45. files:
  46. - name: registry.crt
  47. path: "{{ openshift_master_config_dir }}/registry.crt"
  48. - name: registry.key
  49. path: "{{ openshift_master_config_dir }}/registry.key"
  50. register: create_registry_certificates_secret
  51. run_once: true
  52. - name: "Add the secret to the registry's pod service accounts"
  53. oc_serviceaccount_secret:
  54. service_account: "{{ item }}"
  55. secret: registry-certificates
  56. namespace: default
  57. kubeconfig: "{{ openshift_hosted_kubeconfig }}"
  58. state: present
  59. with_items:
  60. - registry
  61. - default
  62. - name: Determine if registry-certificates secret volume attached
  63. command: >
  64. {{ openshift.common.client_binary }} get dc/docker-registry
  65. -o jsonpath='{.spec.template.spec.volumes[?(@.secret)].secret.secretName}'
  66. --config={{ openshift_hosted_kubeconfig }}
  67. -n default
  68. register: docker_registry_volumes
  69. changed_when: false
  70. failed_when: "docker_registry_volumes.stdout != '' and 'secretName is not found' not in docker_registry_volumes.stdout and docker_registry_volumes.rc != 0"
  71. - name: Attach registry-certificates secret volume
  72. command: >
  73. {{ openshift.common.client_binary }} volume dc/docker-registry --add --type=secret
  74. --secret-name=registry-certificates
  75. -m /etc/secrets
  76. --config={{ openshift_hosted_kubeconfig }}
  77. -n default
  78. when: "'registry-certificates' not in docker_registry_volumes.stdout"
  79. - name: Determine if registry environment variables must be set
  80. command: >
  81. {{ openshift.common.client_binary }} env dc/docker-registry
  82. --list
  83. --config={{ openshift_hosted_kubeconfig }}
  84. -n default
  85. register: docker_registry_env
  86. changed_when: false
  87. - name: Configure certificates in registry deplomentConfig
  88. command: >
  89. {{ openshift.common.client_binary }} env dc/docker-registry
  90. REGISTRY_HTTP_TLS_CERTIFICATE=/etc/secrets/registry.crt
  91. REGISTRY_HTTP_TLS_KEY=/etc/secrets/registry.key
  92. --config={{ openshift_hosted_kubeconfig }}
  93. -n default
  94. when: "'REGISTRY_HTTP_TLS_CERTIFICATE=/etc/secrets/registry.crt' not in docker_registry_env.stdout or 'REGISTRY_HTTP_TLS_KEY=/etc/secrets/registry.key' not in docker_registry_env.stdout"
  95. - name: Determine if registry liveness probe scheme is HTTPS
  96. command: >
  97. {{ openshift.common.client_binary }} get dc/docker-registry
  98. -o jsonpath='{.spec.template.spec.containers[*].livenessProbe.httpGet.scheme}'
  99. --config={{ openshift_hosted_kubeconfig }}
  100. -n default
  101. register: docker_registry_liveness_probe
  102. changed_when: false
  103. # This command is on a single line to preserve patch json.
  104. - name: Update registry liveness probe from HTTP to HTTPS
  105. command: "{{ openshift.common.client_binary }} patch dc/docker-registry --api-version=v1 -p '{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"registry\",\"livenessProbe\":{\"httpGet\":{\"scheme\":\"HTTPS\"}}}]}}}}' --config={{ openshift_hosted_kubeconfig }} -n default"
  106. when: "'HTTPS' not in docker_registry_liveness_probe.stdout"
  107. - name: Determine if registry readiness probe scheme is HTTPS
  108. command: >
  109. {{ openshift.common.client_binary }} get dc/docker-registry
  110. -o jsonpath='{.spec.template.spec.containers[*].readinessProbe.httpGet.scheme}'
  111. --config={{ openshift_hosted_kubeconfig }}
  112. -n default
  113. register: docker_registry_readiness_probe
  114. changed_when: false
  115. # This command is on a single line to preserve patch json.
  116. - name: Update registry readiness probe from HTTP to HTTPS
  117. command: "{{ openshift.common.client_binary }} patch dc/docker-registry --api-version=v1 -p '{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"registry\",\"readinessProbe\":{\"httpGet\":{\"scheme\":\"HTTPS\"}}}]}}}}' --config={{ openshift_hosted_kubeconfig }} -n default"
  118. when: "'HTTPS' not in docker_registry_readiness_probe.stdout"