secure.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. - docker-registry.default.svc.cluster.local
  52. - "{{ docker_registry_route_hostname }}"
  53. cert: "{{ openshift_master_config_dir }}/registry.crt"
  54. key: "{{ openshift_master_config_dir }}/registry.key"
  55. 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 }}"
  56. register: server_cert_out
  57. - name: Create the secret for the registry certificates
  58. oc_secret:
  59. name: registry-certificates
  60. namespace: "{{ openshift_hosted_registry_namespace }}"
  61. files:
  62. - name: registry.crt
  63. path: "{{ openshift_master_config_dir }}/registry.crt"
  64. - name: registry.key
  65. path: "{{ openshift_master_config_dir }}/registry.key"
  66. register: create_registry_certificates_secret_out
  67. - name: Add the secret to the registry's pod service accounts
  68. oc_serviceaccount_secret:
  69. service_account: "{{ item }}"
  70. secret: registry-certificates
  71. namespace: "{{ openshift_hosted_registry_namespace }}"
  72. with_items:
  73. - registry
  74. - default
  75. - name: Set facts for secure registry
  76. set_fact:
  77. registry_secure_volume_mounts:
  78. - name: registry-certificates
  79. path: /etc/secrets
  80. type: secret
  81. secret_name: registry-certificates
  82. registry_secure_env_vars:
  83. REGISTRY_HTTP_TLS_CERTIFICATE: /etc/secrets/registry.crt
  84. REGISTRY_HTTP_TLS_KEY: /etc/secrets/registry.key
  85. registry_secure_edits:
  86. - key: spec.template.spec.containers[0].livenessProbe.httpGet.scheme
  87. value: HTTPS
  88. action: put
  89. - key: spec.template.spec.containers[0].readinessProbe.httpGet.scheme
  90. value: HTTPS
  91. action: put
  92. - name: Update openshift_hosted facts with secure registry variables
  93. set_fact:
  94. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(registry_secure_volume_mounts) }}"
  95. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine(registry_secure_env_vars) }}"
  96. openshift_hosted_registry_edits: "{{ openshift_hosted_registry_edits | union(registry_secure_edits) }}"
  97. openshift_hosted_registry_force: "{{ openshift_hosted_registry_force | union([server_cert_out.changed]) | union([create_registry_certificates_secret_out.changed]) }}"