generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manage TLS cert/key files for registry connections and validate…
… certs Feature: Add two new parameters: podman_registry_certificates is a list of dict. Each dict specifies the certs and keys to use to connect to the specified registry using TLS and optionally use certificate authentication. More information can be found in the manpage for containers-certs.d. podman_validate_certs is a boolean which allows you to require or disable TLS certificate checking (i.e. if you do not have a CA cert for podman_registry_certificates and you still want to pull images from a TLS enabled registry). This corresponds to the parameter "validate_certs" of the module containers.podman.podman_image. You can also control certificate validation by using podman_registries_conf to configure the "insecure" parameter for a registry. Reason: Users need to be able to configure the TLS settings for connecting to registries. Result: Users can connect to registries using TLS and control how that works. QE: tests_auth_and_security.yml has been extended for this. Signed-off-by: Rich Megginson <[email protected]>
- Loading branch information
Showing
12 changed files
with
324 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Check given registry_host | ||
fail: | ||
msg: >- | ||
The given registry host {{ __podman_cert_spec_item['registry_host'] }} | ||
is invalid - cannot be used as the directory name | ||
when: __podman_cert_spec_item["registry_host"] is search("/") | ||
|
||
- name: Set per-cert spec variables part 0 | ||
set_fact: | ||
__podman_user: "{{ __podman_cert_spec_item['run_as_user'] | | ||
d(podman_run_as_user) }}" | ||
|
||
- name: Set per-cert spec variables part 1 | ||
set_fact: | ||
__podman_rootless: "{{ __podman_user != 'root' }}" | ||
|
||
- name: Check user and group information | ||
include_tasks: handle_user_group.yml | ||
vars: | ||
__podman_spec_item: "{{ __podman_cert_spec_item }}" | ||
|
||
- name: Set per-cert spec variables part 2 | ||
set_fact: | ||
__podman_user_home_dir: "{{ | ||
ansible_facts['getent_passwd'][__podman_user][4] }}" | ||
|
||
- name: Set per-cert spec variables part 3 | ||
set_fact: | ||
__podman_certs_d_path: "{{ (__podman_user_home_dir ~ | ||
__podman_user_certs_d_path | ||
if __podman_rootless else __podman_system_certs_d_path) ~ | ||
'/' ~ __podman_cert_spec_item['registry_host'] }}" | ||
|
||
- name: Set per-cert spec variables part 4 | ||
set_fact: | ||
__podman_cert_file_list: | ||
- dest: "{{ __podman_certs_d_path ~ '/' ~ | ||
(__podman_cert_spec_item['cert'] | basename | ||
if 'cert' in __podman_cert_spec_item | ||
else __podman_cert_spec_item['cert_src'] | basename | ||
if 'cert_src' in __podman_cert_spec_item | ||
else 'client.cert') }}" | ||
content: "{{ __podman_cert_spec_item['cert_content'] | d('') }}" | ||
src: "{{ __podman_cert_spec_item['cert_src'] | d('') }}" | ||
- dest: "{{ __podman_certs_d_path ~ '/' ~ | ||
(__podman_cert_spec_item['key'] | basename | ||
if 'key' in __podman_cert_spec_item | ||
else __podman_cert_spec_item['key_src'] | basename | ||
if 'key_src' in __podman_cert_spec_item | ||
else 'client.key') }}" | ||
content: "{{ __podman_cert_spec_item['key_content'] | d('') }}" | ||
src: "{{ __podman_cert_spec_item['key_src'] | d('') }}" | ||
- dest: "{{ __podman_certs_d_path ~ '/' ~ | ||
(__podman_cert_spec_item['ca_cert'] | basename | ||
if 'ca_cert' in __podman_cert_spec_item | ||
else __podman_cert_spec_item['ca_cert_src'] | basename | ||
if 'ca_cert_src' in __podman_cert_spec_item | ||
else 'ca.crt') }}" | ||
content: "{{ __podman_cert_spec_item['ca_cert_content'] | d('') }}" | ||
src: "{{ __podman_cert_spec_item['ca_cert_src'] | d('') }}" | ||
no_log: true | ||
|
||
- name: Create TLS files | ||
when: | ||
- __podman_cert_spec_item["state"] | d("present") == "present" | ||
- __podman_handle_state == "present" | ||
block: | ||
- name: Ensure certs.d directory | ||
file: | ||
path: "{{ __podman_certs_d_path }}" | ||
state: directory | ||
owner: "{{ __podman_user }}" | ||
group: "{{ __podman_group }}" | ||
mode: "0700" | ||
|
||
- name: Ensure certs.d files | ||
copy: | ||
content: "{{ item.content if item.content | length > 0 else omit }}" | ||
src: "{{ item.src if item.src | length > 0 else omit }}" | ||
dest: "{{ item.dest }}" | ||
owner: "{{ __podman_user }}" | ||
group: "{{ __podman_group }}" | ||
mode: "0600" | ||
when: (item.content | length > 0) or (item.src | length > 0) | ||
loop: "{{ __podman_cert_file_list }}" | ||
no_log: true | ||
|
||
- name: Remove TLS files | ||
when: | ||
- __podman_cert_spec_item["state"] | d("present") == "absent" | ||
- __podman_handle_state == "absent" | ||
block: | ||
- name: Remove certs.d files | ||
file: | ||
path: "{{ item.dest }}" | ||
state: absent | ||
loop: "{{ __podman_cert_file_list }}" | ||
no_log: true | ||
|
||
- name: Find files in certs.d directory | ||
find: | ||
path: "{{ __podman_certs_d_path }}" | ||
file_type: any | ||
hidden: true | ||
register: __certs_d_dir_files | ||
no_log: true | ||
|
||
- name: Ensure the certs.d directory is absent if empty | ||
file: | ||
path: "{{ __podman_certs_d_path }}" | ||
state: absent | ||
when: __certs_d_dir_files.matched == 0 | ||
no_log: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.