Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 028aaf7

Browse files
committed
Fix registry and registry console certs
The registry is by default deployed using a certificate signed by the OpenShift CA. As this is not generally recognized, create a new re-encrypting edge route to the registry that uses a proper certificate. This way it is possible to login to the registry normally. Using the re-encrypting route triggers a bug in the Docker registry that is fixed in a newer version. To work around this bug, manually update the Docker image used for the registry to a newer one. See: openshift/origin#14249 and also openshift/origin#11391. The registry console also needs to be reconfigured with the new route to the registry. Make this configuration change using the oc_env module from openshift-ansible. For this to work, add modules from the lib_openshift role into the library path. Replace the certificate of the registry console with a proper recognized certificate so that warnings are not shown when accessing the console from a browser. Write tests for checking correct connectivity to the routes used for the registry and the registry console. These should verify that there are no certificate issues with the endpoints. Split the registry config changes into their own playbook from the post-install playbook to keep things tidy.
1 parent a30032f commit 028aaf7

File tree

4 files changed

+143
-14
lines changed

4 files changed

+143
-14
lines changed

container-src/poc-deployer/init_env.bash

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ echo "ANSIBLE_INVENTORY set to $ANSIBLE_INVENTORY"
2525
echo
2626

2727
export ANSIBLE_LIBRARY="/usr/share/ansible:\
28-
$HOME/openshift-ansible/roles/lib_utils/library"
28+
$HOME/openshift-ansible/roles/lib_utils/library:\
29+
$HOME/openshift-ansible/roles/lib_openshift/library"
2930
echo "ANSIBLE_LIBRARY set to $ANSIBLE_LIBRARY"
3031

3132
pushd /opt/deployment/poc/playbooks > /dev/null

playbooks/post_install.yml

+5-13
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,12 @@
5555
when: existing_storageclass.stdout_lines | length > 0
5656
changed_when: storageclass_template.changed
5757

58-
- name: check if registry PVC exists
59-
shell: oc get pvc -n default registry
60-
register: existing_registry_pv
61-
changed_when: false
62-
failed_when: false
63-
64-
- name: create and attach a persistent volume for registry
65-
shell: oc volume -n default dc/docker-registry --add --mount-path=/registry --overwrite --name=registry-storage -t pvc --claim-size=200Gi --claim-name=registry
66-
when: existing_registry_pv.stdout_lines | length == 0
67-
68-
- name: attach the existing persistent volume for registry
69-
shell: oc volume -n default dc/docker-registry --add --mount-path=/registry --overwrite --name=registry-storage --claim-name=registry
70-
when: existing_registry_pv.stdout_lines | length > 0
58+
- name: Additional Docker registry configuration
59+
include: registry_config.yml
7160

61+
- name: Setup default www app
62+
hosts: masters[0]
63+
tasks:
7264
# block for conditionally deploying default-www-app
7365
- block:
7466
- name: check if project default-www exists

playbooks/registry_config.yml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
- name: Do additional Docker registry configuration
3+
hosts: masters[0]
4+
tasks:
5+
- name: update Docker image used for the registry
6+
oc_edit:
7+
name: docker-registry
8+
namespace: default
9+
kind: dc
10+
content:
11+
spec.template.spec.containers[0].image: "{{ registry_docker_image }}"
12+
13+
- name: get certificate for registry
14+
slurp:
15+
src: '/etc/origin/master/registry.crt'
16+
register: registry_cert_file
17+
18+
- name: put registry certificate content into variable
19+
set_fact:
20+
registry_dest_cert: "{{ registry_cert_file['content'] | b64decode }}"
21+
22+
- name: create a re-encrypt route with a proper cert for the registry
23+
oc_route:
24+
name: docker-registry-reencrypt
25+
namespace: default
26+
cert_path: "/etc/origin/master/named_certificates/{{ openshift_public_hostname }}.crt"
27+
key_path: "/etc/origin/master/named_certificates/{{ openshift_public_hostname }}.key"
28+
cacert_path: "/etc/origin/master/named_certificates/ext_ca.crt"
29+
dest_cacert_content: "{{ registry_dest_cert }}"
30+
service_name: "docker-registry"
31+
port: "5000"
32+
host: "docker-registry.{{ openshift_public_hostname }}"
33+
tls_termination: "reencrypt"
34+
run_once: true
35+
36+
- name: update registry URL in registry console
37+
oc_env:
38+
state: present
39+
name: registry-console
40+
namespace: default
41+
kind: dc
42+
env_vars:
43+
REGISTRY_HOST: docker-registry.{{ openshift_public_hostname }}
44+
run_once: true
45+
46+
- name: check if we already have registry-console.cert created
47+
stat:
48+
path: /etc/origin/master/registry-console.cert
49+
register: registry_console_cert
50+
51+
- name: create registry console cert file with a proper cert+key
52+
shell: >
53+
cat /etc/origin/master/{{ openshift_public_hostname }}.crt
54+
/etc/origin/master/{{ openshift_public_hostname }}.key
55+
> /etc/origin/master/registry-console.cert
56+
when: registry_console_cert.stat.exists == False
57+
58+
- name: set access rights for registry-console.cert
59+
file:
60+
path: /etc/origin/master/registry-console.cert
61+
owner: root
62+
group: root
63+
mode: 0640
64+
65+
- name: create cert secret for registry console
66+
oc_secret:
67+
state: present
68+
namespace: default
69+
name: console-secret
70+
files:
71+
- name: registry-console.cert
72+
path: '/etc/origin/master/registry-console.cert'
73+
run_once: true
74+
75+
- name: add cert secret as a volume to dc/registry-console
76+
oc_volume:
77+
state: present
78+
name: registry-console
79+
namespace: default
80+
kind: dc
81+
mount_type: secret
82+
secret_name: console-secret
83+
vol_name: console-secret-vol
84+
mount_path: /etc/cockpit/ws-certs.d
85+
run_once: true
86+
87+
- name: check if registry PVC exists
88+
shell: oc get pvc -n default registry
89+
register: existing_registry_pv
90+
changed_when: false
91+
failed_when: false
92+
93+
- name: create and attach a persistent volume for registry
94+
shell: >
95+
oc volume -n default dc/docker-registry --add
96+
--mount-path=/registry --overwrite
97+
--name=registry-storage
98+
--claim-name=registry
99+
-t pvc --claim-size=200Gi
100+
when: existing_registry_pv.stdout_lines | length == 0
101+
102+
- name: attach the existing persistent volume for registry
103+
shell: >
104+
oc volume -n default dc/docker-registry --add
105+
--mount-path=/registry --overwrite
106+
--name=registry-storage --claim-name=registry
107+
when: existing_registry_pv.stdout_lines | length > 0
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
#!/usr/bin/env bats
22

3+
check_route_url() {
4+
# OpenShift adds its own CA cert to the CA bundle. For testing, we don't
5+
# want to have that cert available, so create a copy of the CA bundle
6+
# without the OpenShift cert added.
7+
ca_bundle=$(mktemp)
8+
sed '/openshift-signer/,/^$/d' /etc/ssl/certs/ca-bundle.crt > $ca_bundle
9+
10+
url=$(oc get route $1 -o json -o jsonpath='{.spec.host}')
11+
12+
curl --cacert $ca_bundle https://$url >&2
13+
curl_status=$?
14+
15+
rm $ca_bundle
16+
17+
return $curl_status
18+
}
19+
320
@test "test default namespace pod health" {
421
all_pods_count=$(oc get pods -n default -o json | jq '[.items[].status.phase]|length')
522
running_pods_count=$(oc get pods -n default -o json | jq '[.items[].status.phase|select(. == "Running")]|length')
623

724
[ $all_pods_count -eq $running_pods_count ]
825
}
26+
27+
@test "test connectivity to registry URL" {
28+
run check_route_url docker-registry-reencrypt
29+
30+
[ $status -eq 0 ]
31+
}
32+
33+
@test "test connectivity to registry console URL" {
34+
run check_route_url registry-console
35+
36+
[ $status -eq 0 ]
37+
}

0 commit comments

Comments
 (0)