secure.yml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. - name: Set fact docker_registry_route_hostname
  3. set_fact:
  4. docker_registry_route_hostname: "{{ 'docker-registry-default.' ~ (openshift_master_default_subdomain | default('router.default.svc.cluster.local', true)) }}"
  5. - name: Get the certificate contents for registry
  6. copy:
  7. backup: True
  8. dest: "/etc/origin/master/named_certificates/{{ item.value | basename }}"
  9. src: "{{ item.value }}"
  10. when: item.key in ['certfile', 'keyfile', 'cafile'] and item.value
  11. with_dict: "{{ openshift_hosted_registry_routecertificates }}"
  12. # When certificates are defined we will create the reencrypt
  13. # docker-registry route
  14. - name: Create a reencrypt route for docker-registry
  15. oc_route:
  16. name: docker-registry
  17. namespace: "{{ openshift_hosted_registry_namespace }}"
  18. service_name: docker-registry
  19. tls_termination: "{{ openshift_hosted_registry_routetermination }}"
  20. host: "{{ openshift_hosted_registry_routehost | default(docker_registry_route_hostname) }}"
  21. cert_path: "/etc/origin/master/named_certificates/{{ openshift_hosted_registry_routecertificates['certfile'] | basename }}"
  22. key_path: "/etc/origin/master/named_certificates/{{ openshift_hosted_registry_routecertificates['keyfile'] | basename }}"
  23. cacert_path: "/etc/origin/master/named_certificates/{{ openshift_hosted_registry_routecertificates['cafile'] | basename }}"
  24. dest_cacert_path: /etc/origin/master/ca.crt
  25. when:
  26. - "'cafile' in openshift_hosted_registry_routecertificates"
  27. - "'certfile' in openshift_hosted_registry_routecertificates"
  28. - "'keyfile' in openshift_hosted_registry_routecertificates"
  29. # When routetermination is passthrough we will create the route
  30. - name: Create passthrough route for docker-registry
  31. oc_route:
  32. name: docker-registry
  33. namespace: "{{ openshift_hosted_registry_namespace }}"
  34. service_name: docker-registry
  35. tls_termination: "{{ openshift_hosted_registry_routetermination }}"
  36. host: "{{ openshift_hosted_registry_routehost | ternary(openshift_hosted_registry_routehost, docker_registry_route_hostname) }}"
  37. when: openshift_hosted_registry_routetermination == 'passthrough'
  38. - name: Retrieve registry service IP
  39. oc_service:
  40. namespace: "{{ openshift_hosted_registry_namespace }}"
  41. name: docker-registry
  42. state: list
  43. register: docker_registry_service_ip
  44. - name: Create registry certificates
  45. oc_adm_ca_server_cert:
  46. signer_cert: "{{ openshift_master_config_dir }}/ca.crt"
  47. signer_key: "{{ openshift_master_config_dir }}/ca.key"
  48. signer_serial: "{{ openshift_master_config_dir }}/ca.serial.txt"
  49. hostnames:
  50. - "{{ docker_registry_service_ip.results.clusterip }}"
  51. - "{{ openshift_hosted_registry_name }}.default.svc"
  52. - "{{ openshift_hosted_registry_name }}.default.svc.{{ openshift.common.dns_domain }}"
  53. - "{{ docker_registry_route_hostname }}"
  54. cert: "{{ openshift_master_config_dir }}/registry.crt"
  55. key: "{{ openshift_master_config_dir }}/registry.key"
  56. 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 }}"
  57. register: server_cert_out
  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: "{{ openshift_master_config_dir }}/registry.crt"
  65. - name: registry.key
  66. path: "{{ openshift_master_config_dir }}/registry.key"
  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: Update openshift_hosted facts with secure registry variables
  94. set_fact:
  95. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(registry_secure_volume_mounts) }}"
  96. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine(registry_secure_env_vars) }}"
  97. openshift_hosted_registry_edits: "{{ openshift_hosted_registry_edits | union(registry_secure_edits) }}"
  98. openshift_hosted_registry_force: "{{ openshift_hosted_registry_force | union([server_cert_out.changed]) | union([create_registry_certificates_secret_out.changed]) }}"