secure.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ---
  2. - name: Create passthrough route for docker-registry
  3. command: >
  4. {{ openshift.common.client_binary }} create route passthrough
  5. --service docker-registry
  6. --config={{ openshift_hosted_kubeconfig }}
  7. -n default
  8. register: create_docker_registry_route
  9. changed_when: "'already exists' not in create_docker_registry_route.stderr"
  10. failed_when: "'already exists' not in create_docker_registry_route.stderr and create_docker_registry_route.rc != 0"
  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=/etc/origin/master/ca.crt
  34. --signer-key=/etc/origin/master/ca.key
  35. --signer-serial=/etc/origin/master/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. command: >
  42. {{ openshift.common.client_binary }} secrets new registry-certificates
  43. {{ openshift_master_config_dir }}/registry.crt
  44. {{ openshift_master_config_dir }}/registry.key
  45. --config={{ openshift_hosted_kubeconfig }}
  46. -n default
  47. register: create_registry_certificates_secret
  48. changed_when: "'already exists' not in create_registry_certificates_secret.stderr"
  49. failed_when: "'already exists' not in create_registry_certificates_secret.stderr and create_registry_certificates_secret.rc != 0"
  50. - name: "Add the secret to the registry's pod service accounts"
  51. command: >
  52. {{ openshift.common.client_binary }} secrets add {{ item }} registry-certificates
  53. --config={{ openshift_hosted_kubeconfig }}
  54. -n default
  55. with_items:
  56. - registry
  57. - default
  58. - name: Determine if registry-certificates secret volume attached
  59. command: >
  60. {{ openshift.common.client_binary }} get dc/docker-registry
  61. -o jsonpath='{.spec.template.spec.volumes[*].secret.secretName}'
  62. --config={{ openshift_hosted_kubeconfig }}
  63. -n default
  64. register: docker_registry_volumes
  65. changed_when: false
  66. failed_when: "'secretName is not found' not in docker_registry_volumes.stdout and docker_registry_volumes.rc != 0"
  67. - name: Attach registry-certificates secret volume
  68. command: >
  69. {{ openshift.common.client_binary }} volume dc/docker-registry --add --type=secret
  70. --secret-name=registry-certificates
  71. -m /etc/secrets
  72. --config={{ openshift_hosted_kubeconfig }}
  73. -n default
  74. when: "'registry-certificates' not in docker_registry_volumes.stdout"
  75. - name: Determine if registry environment variables must be set
  76. command: >
  77. {{ openshift.common.client_binary }} env dc/docker-registry
  78. --list
  79. --config={{ openshift_hosted_kubeconfig }}
  80. -n default
  81. register: docker_registry_env
  82. changed_when: false
  83. - name: Configure certificates in registry deplomentConfig
  84. command: >
  85. {{ openshift.common.client_binary }} env dc/docker-registry
  86. REGISTRY_HTTP_TLS_CERTIFICATE=/etc/secrets/registry.crt
  87. REGISTRY_HTTP_TLS_KEY=/etc/secrets/registry.key
  88. --config={{ openshift_hosted_kubeconfig }}
  89. -n default
  90. 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"
  91. - name: Determine if registry liveness probe scheme is HTTPS
  92. command: >
  93. {{ openshift.common.client_binary }} get dc/docker-registry
  94. -o jsonpath='{.spec.template.spec.containers[*].livenessProbe.httpGet.scheme}'
  95. --config={{ openshift_hosted_kubeconfig }}
  96. -n default
  97. register: docker_registry_liveness_probe
  98. changed_when: false
  99. # This command is on a single line to preserve patch json.
  100. - name: Update registry liveness probe from HTTP to HTTPS
  101. 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"
  102. when: "'HTTPS' not in docker_registry_liveness_probe.stdout"
  103. - name: Determine if registry readiness probe scheme is HTTPS
  104. command: >
  105. {{ openshift.common.client_binary }} get dc/docker-registry
  106. -o jsonpath='{.spec.template.spec.containers[*].readinessProbe.httpGet.scheme}'
  107. --config={{ openshift_hosted_kubeconfig }}
  108. -n default
  109. register: docker_registry_readiness_probe
  110. changed_when: false
  111. # This command is on a single line to preserve patch json.
  112. - name: Update registry readiness probe from HTTP to HTTPS
  113. 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"
  114. when: "'HTTPS' not in docker_registry_readiness_probe.stdout"