secure.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ---
  2. - name: Configure facts for docker-registry
  3. set_fact:
  4. openshift_hosted_registry_routecertificates: "{{ ('routecertificates' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routecertificates, {}) }}"
  5. openshift_hosted_registry_routehost: "{{ ('routehost' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routehost, False) }}"
  6. openshift_hosted_registry_routetermination: "{{ ('routetermination' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routetermination, 'passthrough') }}"
  7. - name: Include reencrypt route configuration
  8. include: secure/reencrypt.yml
  9. static: no
  10. when: openshift_hosted_registry_routetermination == 'reencrypt'
  11. - name: Include passthrough route configuration
  12. include: secure/passthrough.yml
  13. static: no
  14. when: openshift_hosted_registry_routetermination == 'passthrough'
  15. - name: Fetch the docker-registry route
  16. oc_route:
  17. name: docker-registry
  18. namespace: default
  19. state: list
  20. register: docker_registry_route
  21. - name: Retrieve registry service for the clusterip
  22. oc_service:
  23. namespace: "{{ openshift_hosted_registry_namespace }}"
  24. name: docker-registry
  25. state: list
  26. register: docker_registry_service
  27. - name: Generate self-signed docker-registry certificates
  28. oc_adm_ca_server_cert:
  29. signer_cert: "{{ openshift_master_config_dir }}/ca.crt"
  30. signer_key: "{{ openshift_master_config_dir }}/ca.key"
  31. signer_serial: "{{ openshift_master_config_dir }}/ca.serial.txt"
  32. hostnames:
  33. - "{{ docker_registry_service.results.clusterip }}"
  34. - "{{ docker_registry_route.results[0].spec.host }}"
  35. cert: "{{ docker_registry_cert_path }}"
  36. key: "{{ docker_registry_key_path }}"
  37. expire_days: "{{ openshift_hosted_registry_cert_expire_days if openshift_version | oo_version_gte_3_5_or_1_5(openshift.common.deployment_type) | bool else omit }}"
  38. register: registry_self_cert
  39. when: docker_registry_self_signed
  40. # Setting up REGISTRY_HTTP_TLS_CLIENTCAS as the cacert doesn't seem to work.
  41. # If we need to set up a cacert, bundle it with the cert.
  42. - when: docker_registry_cacert_path is defined
  43. block:
  44. - name: Retrieve certificate files to generate certificate bundle
  45. slurp:
  46. src: "{{ item }}"
  47. with_items:
  48. - "{{ docker_registry_cert_path }}"
  49. - "{{ docker_registry_cacert_path }}"
  50. register: certificate_files
  51. - name: Generate certificate bundle
  52. copy:
  53. content: "{{ certificate_files.results | map(attribute='content') | map('b64decode') | join('') }}"
  54. dest: "{{ openshift_master_config_dir }}/named_certificates/docker-registry.pem"
  55. - name: Reset the certificate path to use the bundle
  56. set_fact:
  57. docker_registry_cert_path: "{{ openshift_master_config_dir }}/named_certificates/docker-registry.pem"
  58. - name: Create the secret for the registry certificates
  59. oc_secret:
  60. name: registry-certificates
  61. namespace: "{{ openshift_hosted_registry_namespace }}"
  62. files:
  63. - name: registry.crt
  64. path: "{{ docker_registry_cert_path }}"
  65. - name: registry.key
  66. path: "{{ docker_registry_key_path }}"
  67. register: create_registry_certificates_secret_out
  68. - name: Add the secret to the registry's pod service accounts
  69. oc_serviceaccount_secret:
  70. service_account: "{{ item }}"
  71. secret: registry-certificates
  72. namespace: "{{ openshift_hosted_registry_namespace }}"
  73. with_items:
  74. - registry
  75. - default
  76. - name: Set facts for secure registry
  77. set_fact:
  78. registry_secure_volume_mounts:
  79. - name: registry-certificates
  80. path: /etc/secrets
  81. type: secret
  82. secret_name: registry-certificates
  83. registry_secure_env_vars:
  84. REGISTRY_HTTP_TLS_CERTIFICATE: /etc/secrets/registry.crt
  85. REGISTRY_HTTP_TLS_KEY: /etc/secrets/registry.key
  86. registry_secure_edits:
  87. - key: spec.template.spec.containers[0].livenessProbe.httpGet.scheme
  88. value: HTTPS
  89. action: put
  90. - key: spec.template.spec.containers[0].readinessProbe.httpGet.scheme
  91. value: HTTPS
  92. action: put
  93. - name: Detect if there has been certificate changes
  94. set_fact:
  95. registry_cert_changed: true
  96. when: ( registry_self_cert is defined and registry_self_cert.changed ) or
  97. create_registry_certificates_secret_out.changed
  98. - name: Update openshift_hosted facts with secure registry variables
  99. set_fact:
  100. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(registry_secure_volume_mounts) }}"
  101. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine(registry_secure_env_vars) }}"
  102. openshift_hosted_registry_edits: "{{ openshift_hosted_registry_edits | union(registry_secure_edits) }}"
  103. openshift_hosted_registry_force: "{{ openshift_hosted_registry_force | union([registry_cert_changed | default(false)]) }}"