Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Make tlsverify optional (#18)
Browse files Browse the repository at this point in the history
- add a variable `docker_tls_verify` - if `true` will require that TLS
certificates can be verified by a root authority
- copy server CA certificate to Ansible Controller cache (so it can then
be copied to clients)
- rename `meta/requirements.yml` to `meta/collections.yml`, otherwise
this role cannot be installed using `ansible-galaxy` (it complains that
the requirements file contains a collection)
  • Loading branch information
p-j-smith authored Nov 22, 2023
1 parent 7d6b491 commit 15e4581
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
steps:
- uses: UCL-MIRSG/.github/actions/linting@v0.26.0
with:
ansible-roles-config: ./meta/requirements.yml
ansible-roles-config: ./meta/collections.yml
pre-commit-config: ./.pre-commit-config.yaml
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,36 @@ This role is for installing [docker-ce](https://docs.docker.com/engine/install/)
If you would like to [configure](https://docs.docker.com/engine/security/protect-access/#use-tls-https-to-protect-the-docker-daemon-socket)
your Docker server such that clients can connect to it via TLS, you can also use this role to generate the necessary certificates.
The following variables can be used to configure certificate creation and signing:

| Name | Description |
docker_tls_verify
| Name | Description |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `docker_generate_certificates` | If `true`, CA, server, and client certificates will be generated. Defaults to `false` |
| `docker_certificate_directory` | Directory in which to store the certificates. Defaults to `/home/docker/.docker` |
| `docker_config_dir` | Docker configuration directory. Defaults to `/etc/docker` |
| `docker_daemon_conf_file` | Docker daemon configuration filename. Defaults to `/etc/docker/daemon.json` |
| `docker_server_hostname` | Hostname of your Docker server. Used for the `commonName` field of the certificate signing request subject. Defaults to `"{{ ansible_host }}"` |
| `docker_server_ip` | IP address of your Docker server. Defaults to `0.0.0.0` |
| `docker_ca_key` | Filename for the CA certificate key. Defaults to `/home/docker/.docker/ca.key` |
| `docker_ca_csr` | Filename for the CA certificate signing request. Defaults to `/home/docker/.docker/ca.csr` |
| `docker_ca_cert` | Filename for the CA certificate. Defaults to `/home/docker/.docker/ca.pem` |
| `docker_server_key` | Filename for the server certificate key. Defaults to `/home/docker/.docker/server-key.pem` |
| `docker_server_csr` | Filename for the server certificate signing request. Defaults to `/home/docker/.docker/server.csr` |
| `docker_server_cert` | Filename for the server certificate. Defaults to `/home/docker/.docker/server-cert.pem` |
| `docker_client_hostnames` | List of hostnames of clients that will connect to the server. Defaults to `[]` |
| `docker_client_certificate_directory` | Directory in which to store the client certificates. Defaults to `/home/docker/.docker/client_certs` |
| `docker_client_certificate_cache_directory` | Directory in which to client certificates will be copied to. Defaults to `~/ansible_persistent_files/docker_certificates` |
| `docker_generate_certificates` | If `true`, CA, server, and client certificates will be generated. Defaults to `false` |
| `docker_certificate_directory` | Directory in which to store the certificates. Defaults to `/home/docker/.docker` |
| `docker_config_dir` | Docker configuration directory. Defaults to `/etc/docker` |
| `docker_daemon_conf_file` | Docker daemon configuration filename. Defaults to `/etc/docker/daemon.json` |
| `docker_server_hostname` | Hostname of your Docker server. Used for the `commonName` field of the certificate signing request subject. Defaults to `"{{ ansible_host }}"` |
| `docker_server_ip` | IP address of your Docker server. Defaults to `0.0.0.0` |
| `docker_tls_verify` | If `true`, require that TLS certificates can be verified by a root authority. Defaults to `true` |
| `docker_ca_key` | Filename for the CA certificate key. Defaults to `/home/docker/.docker/ca.key` |
| `docker_ca_csr` | Filename for the CA certificate signing request. Defaults to `/home/docker/.docker/ca.csr` |
| `docker_ca_cert` | Filename for the CA certificate. Defaults to `/home/docker/.docker/ca.pem` |
| `docker_server_key` | Filename for the server certificate key. Defaults to `/home/docker/.docker/server-key.pem` |
| `docker_server_csr` | Filename for the server certificate signing request. Defaults to `/home/docker/.docker/server.csr` |
| `docker_server_cert` | Filename for the server certificate. Defaults to `/home/docker/.docker/server-cert.pem` |
| `docker_client_hostnames` | List of hostnames of clients that will connect to the server. Defaults to `[]` |
| `docker_client_certificate_directory` | Directory in which to store the client certificates. Defaults to `/home/docker/.docker/client_certs` |
| `docker_client_certificate_cache_directory` | Directory in which to client certificates will be copied to. Defaults to `~/ansible_persistent_files/docker_certificates` |

If you have specified a list of clients in `docker_client_hostnames`, the certificate for each client will be stored locally on your Ansible
controller in the folder `docker_client_certificate_cache_directory`. You will then need to copy these certificates to the corresponding
client.

## Dependencies

You will need to install the following collections before using `mirsg.docker`:

- `community.crypto`

## Installation

Include in a requirements.yml file as follows:
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ docker_daemon_conf_file: "/etc/docker/daemon.json"
docker_server_hostname: "{{ ansible_host }}"
docker_server_ip: "0.0.0.0"
docker_server_port: "2376"
docker_tls_verify: true

# mirsg.docker CA certificate
docker_ca_key: "{{ docker_certificate_directory }}/ca.key"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion molecule/centos7/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
dependency:
name: galaxy
options:
role-file: meta/requirements.yml
requirements-file: meta/collections.yml
force: true

driver:
Expand Down
2 changes: 1 addition & 1 deletion molecule/rocky8/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
dependency:
name: galaxy
options:
role-file: meta/requirements.yml
requirements-file: meta/collections.yml
force: true

driver:
Expand Down
6 changes: 6 additions & 0 deletions tasks/server-cert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@
mode: "0400"
notify:
- Restart docker

- name: Copy server CA certificate to Ansible Controller cache
ansible.builtin.fetch:
src: "{{ docker_ca_cert }}"
dest: "{{ docker_client_certificate_cache_directory }}/ca.pem"
flat: true
2 changes: 1 addition & 1 deletion templates/daemon.json.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hosts": ["tcp://{{ docker_server_ip }}:{{ docker_server_port }}", "unix:///var/run/docker.sock"],
"tlsverify": true,
"tlsverify": {{ docker_tls_verify | lower }},
"tlscacert": "{{ docker_ca_cert }}",
"tlscert": "{{ docker_server_cert }}",
"tlskey": "{{ docker_server_key }}"
Expand Down

0 comments on commit 15e4581

Please sign in to comment.