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

Commit 3341c7c

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.
1 parent a30032f commit 3341c7c

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
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

+88-1
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,101 @@
5555
when: existing_storageclass.stdout_lines | length > 0
5656
changed_when: storageclass_template.changed
5757

58+
- name: update Docker image used for the registry
59+
oc_edit:
60+
name: docker-registry
61+
namespace: default
62+
kind: dc
63+
content:
64+
spec.template.spec.containers[0].image: "{{ registry_docker_image }}"
65+
66+
- name: get certificate for registry
67+
slurp:
68+
src: '/etc/origin/master/registry.crt'
69+
register: registry_cert_file
70+
71+
- name: put registry certificate content into variable
72+
set_fact:
73+
registry_dest_cert: "{{ registry_cert_file['content'] | b64decode }}"
74+
75+
- name: create a re-encrypt route with a proper cert for the registry
76+
oc_route:
77+
name: docker-registry-reencrypt
78+
namespace: default
79+
cert_path: "/etc/origin/master/named_certificates/{{ openshift_public_hostname }}.crt"
80+
key_path: "/etc/origin/master/named_certificates/{{ openshift_public_hostname }}.key"
81+
cacert_path: "/etc/origin/master/named_certificates/ext_ca.crt"
82+
dest_cacert_content: "{{ registry_dest_cert }}"
83+
service_name: "docker-registry"
84+
port: "5000"
85+
host: "docker-registry.{{ openshift_public_hostname }}"
86+
tls_termination: "reencrypt"
87+
run_once: true
88+
89+
- name: update registry URL in registry console
90+
oc_env:
91+
state: present
92+
name: registry-console
93+
namespace: default
94+
kind: dc
95+
env_vars:
96+
REGISTRY_HOST: docker-registry.{{ openshift_public_hostname }}
97+
run_once: true
98+
99+
- name: check if we already have registry-console.cert created
100+
stat:
101+
path: /etc/origin/master/registry-console.cert
102+
register: registry_console_cert
103+
104+
- name: create registry console cert file with a proper cert+key
105+
shell: >
106+
cat /etc/origin/master/{{ openshift_public_hostname }}.crt
107+
/etc/origin/master/{{ openshift_public_hostname }}.key
108+
> /etc/origin/master/registry-console.cert
109+
when: registry_console_cert.stat.exists == False
110+
111+
- name: set access rights for registry-console.cert
112+
file:
113+
path: /etc/origin/master/registry-console.cert
114+
owner: root
115+
group: root
116+
mode: 0640
117+
118+
- name: create cert secret for registry console
119+
oc_secret:
120+
state: present
121+
namespace: default
122+
name: console-secret
123+
files:
124+
- name: registry-console.cert
125+
path: '/etc/origin/master/registry-console.cert'
126+
run_once: true
127+
128+
- name: add cert secret as a volume to dc/registry-console
129+
oc_volume:
130+
state: present
131+
name: registry-console
132+
namespace: default
133+
kind: dc
134+
mount_type: secret
135+
secret_name: console-secret
136+
vol_name: console-secret-vol
137+
mount_path: /etc/cockpit/ws-certs.d
138+
run_once: true
139+
58140
- name: check if registry PVC exists
59141
shell: oc get pvc -n default registry
60142
register: existing_registry_pv
61143
changed_when: false
62144
failed_when: false
63145

64146
- 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
147+
shell: >
148+
oc volume -n default dc/docker-registry --add
149+
--mount-path=/registry --overwrite
150+
--name=registry-storage
151+
--claim-name=registry
152+
-t pvc --claim-size=200Gi
66153
when: existing_registry_pv.stdout_lines | length == 0
67154

68155
- name: attach the existing persistent volume for registry
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)