secure.yml 5.6 KB

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