Clark Boylan 4c40b92950 Prevent leaks of buildset registry credentials
Because buildset registries may be used by jobs that finish before other
jobs are finished using the buildset registry we must be careful not to
expose the registry credentials in the jobs that finish sooner.
Otherwise logs for the earlier job runs could potentially be used to
poison the registry for later jobs.

This is likely currently incomplete. Other Zuulians should look over it
carefully to ensure we're covering all the bases here.

The cases I've identified so far are:

* Setting facts that include passwords
* Reading and writing to files that include passwords (as content may be
  logged)
* Calling modules with passwords passed as arguments (the module
  invocation is logged)

I've also set no_log on zuul_return that passes up credentials because
while the logging for zuul_return is minimal today, I don't want to
count on it remaining that way.

We also use the yet to be merged secret_data attribute on zuul_return to
ensure that zuul_return itself does not expose anything unwanted.

Finally it would be great if others could check over the use of
buildset_registry variables to make sure there aren't any that got
missed. One thing I'm not sure of is whether or not when conditionals
get logged and if we need to be careful about their use too.

Temporarily remove some buildset-regitry jobs which are in a catch-22.

Change-Id: I2dea683e27f00b99a7766bf830981bf91b925265
2021-06-24 09:56:19 -07:00

88 lines
2.8 KiB
YAML

- name: Install packages
become: yes
package:
name:
- openssl
- socat
state: present
when: ansible_python_version is version('3', '<')
- name: Install packages
become: yes
package:
name:
- openssl
- socat
state: present
when: ansible_python_version is version('3', '>=')
- name: Ensure registry volume directories exists
file:
state: directory
path: "{{ buildset_registry_root }}/{{ zj_dir }}"
mode: 0755
loop:
- tls
- conf
loop_control:
loop_var: zj_dir
- name: Generate registry secrets
set_fact:
registry_password: "{{ lookup('password', '/dev/null') }}"
registry_secret: "{{ lookup('password', '/dev/null') }}"
no_log: true
- name: Write registry config
template:
src: registry.yaml.j2
dest: "{{ buildset_registry_root }}/conf/registry.yaml"
mode: 0600
- name: Generate a TLS key for the registry
command: "openssl req -x509 -newkey rsa:2048 -keyout {{ buildset_registry_root }}/tls/cert.key -out {{ buildset_registry_root }}/tls/cert.pem -days 365 -nodes -subj '/C=US/ST=California/L=Oakland/O=Company Name/OU=Org/CN={{ ansible_host }}' -addext 'subjectAltName = DNS:zuul-jobs.buildset-registry,DNS:{{ ansible_host }},IP:{{ ansible_host }},IP:127.0.0.1'"
- name: Read TLS certificate
slurp:
src: "{{ buildset_registry_root }}/tls/cert.pem"
register: certificate
- name: Decode TLS certificate
set_fact:
certificate: "{{ certificate.content | b64decode }}"
- name: Start the buildset registry
command: >-
{{ container_command }} run -d
--name="{{ (buildset_registry_port == 5000) | ternary('buildset_registry', 'buildset_registry_' + buildset_registry_port|string) }}"
--restart=always
--publish="1{{ buildset_registry_port }}:5000"
--volume="{{ buildset_registry_root }}/tls:/tls"
--volume="{{ buildset_registry_root }}/conf:/conf"
docker.io/zuul/zuul-registry:latest zuul-registry -d
# Start a socat tunnel to the buildset registry to work around
# https://github.com/containers/libpod/issues/4311
# in case we're using podman.
- name: Start socat to work around https://github.com/containers/libpod/issues/4311
shell: "socat -d -d TCP6-LISTEN:{{ buildset_registry_port }},fork TCP:127.0.0.1:1{{ buildset_registry_port }} 2> {{ buildset_registry_root }}/socat_port &"
- name: Set registry information fact
set_fact:
buildset_registry:
host: "{{ ansible_host }}"
port: "{{ buildset_registry_port }}"
username: zuul
password: "{{ registry_password }}"
cert: "{{ certificate }}"
no_log: true
- name: Return registry information to Zuul
zuul_return:
secret_data:
buildset_registry: "{{ buildset_registry }}"
# This isn't strictly necessary with the current implemenation of
# zuul_return but we set no_log: true in case the verbosity
# changes.
no_log: true