Skip to content

Commit 2926317

Browse files
committed
Add support for authenticated registries
Signed-off-by: Eric D. Helms <[email protected]>
1 parent b1194fd commit 2926317

File tree

14 files changed

+123
-4
lines changed

14 files changed

+123
-4
lines changed

docs/installation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Foreman Installation Guide
2+
3+
## Authenticated Registry
4+
5+
If you need to pull images from private or authenticated container registries, you can configure registry authentication using Podman's auth file.
6+
7+
### Setting up Registry Authentication
8+
9+
1. **Login to your registry** using Podman and save credentials to the default auth file location:
10+
```bash
11+
podman login <registry> --authfile=/etc/foreman/registry-auth.json
12+
```
13+
14+
2. **Ensure proper permissions** on the auth file:
15+
```bash
16+
sudo chmod 600 /etc/foreman/registry-auth.json
17+
sudo chown root:root /etc/foreman/registry-auth.json
18+
```
19+
20+
3. **Deploy as usual** - foremanctl will automatically detect and use the authentication file:
21+
```bash
22+
./foremanctl deploy
23+
```

src/playbooks/deploy/deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
- "../../vars/images.yml"
1010
- "../../vars/database.yml"
1111
- "../../vars/foreman.yml"
12-
1312
vars:
1413
certificates_hostnames:
1514
- "{{ ansible_fqdn }}"
@@ -54,6 +53,7 @@
5453
- python3-requests
5554
roles:
5655
- role: checks
56+
- pre_install
5757
- role: certificates
5858
when: "certificate_source == 'default'"
5959
- role: certificate_checks

src/playbooks/pull-images/pull-images.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,27 @@
1212
name:
1313
- podman
1414

15+
- name: Check if auth file exists
16+
ansible.builtin.stat:
17+
path: "{{ registry_auth_file }}"
18+
register: registry_auth_file_stat
19+
when: registry_auth_file is defined and registry_auth_file | length > 0
20+
21+
- name: Set auth file variable if exists
22+
ansible.builtin.set_fact:
23+
auth_file: "{{ registry_auth_file }}"
24+
when: registry_auth_file is defined and registry_auth_file_stat.stat.exists | default(false)
25+
1526
- name: Pull an image
1627
containers.podman.podman_image:
1728
name: "{{ item }}"
29+
auth_file: "{{ auth_file | default(omit) }}"
1830
loop: "{{ images }}"
1931

2032
- name: Pull database images
2133
containers.podman.podman_image:
2234
name: "{{ item }}"
35+
auth_file: "{{ auth_file | default(omit) }}"
2336
loop: "{{ database_images }}"
2437
when:
2538
- database_mode == 'internal'

src/roles/candlepin/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ candlepin_ciphers:
1414
- TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
1515
candlepin_container_image: quay.io/foreman/candlepin
1616
candlepin_container_tag: "4.4.14"
17+
candlepin_registry_auth_file: /etc/foreman/registry-auth.json
1718

1819
candlepin_database_host: localhost
1920
candlepin_database_port: 5432

src/roles/candlepin/tasks/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@
4545
ansible.builtin.include_tasks:
4646
file: artemis.yml
4747

48+
- name: Check if auth file exists
49+
ansible.builtin.stat:
50+
path: "{{ candlepin_registry_auth_file }}"
51+
register: candlepin_auth_file_stat
52+
when: candlepin_registry_auth_file is defined and candlepin_registry_auth_file | length > 0
53+
54+
- name: Set auth file variable if exists
55+
ansible.builtin.set_fact:
56+
candlepin_auth_file: "{{ candlepin_registry_auth_file }}"
57+
when: candlepin_registry_auth_file is defined and candlepin_auth_file_stat.stat.exists | default(false)
58+
4859
- name: Pull the Candlepin container image
4960
containers.podman.podman_image:
5061
name: "{{ candlepin_container_image }}:{{ candlepin_container_tag }}"
5162
state: present
63+
auth_file: "{{ candlepin_auth_file | default(omit) }}"
5264

5365
- name: Deploy Candlepin quadlet
5466
containers.podman.podman_container:
@@ -57,6 +69,8 @@
5769
state: quadlet
5870
network: host
5971
hostname: "{{ ansible_fqdn }}"
72+
env:
73+
REGISTRY_AUTH_FILE: "{{ candlepin_auth_file | default(omit) }}"
6074
secrets:
6175
- 'candlepin-ca-cert,target=/etc/candlepin/certs/candlepin-ca.crt,mode=0440,type=mount'
6276
- 'candlepin-ca-key,target=/etc/candlepin/certs/candlepin-ca.key,mode=0440,type=mount'

src/roles/foreman/defaults/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
foreman_container_image: "quay.io/foreman/foreman"
33
foreman_container_tag: "nightly"
4+
foreman_registry_auth_file: /etc/foreman/registry-auth.json
45

56
foreman_database_name: foreman
67
foreman_database_user: foreman

src/roles/foreman/tasks/main.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
---
2+
- name: Check if auth file exists
3+
ansible.builtin.stat:
4+
path: "{{ foreman_registry_auth_file }}"
5+
register: foreman_auth_file_stat
6+
when: foreman_registry_auth_file is defined and foreman_registry_auth_file | length > 0
7+
8+
- name: Set auth file variable if exists
9+
ansible.builtin.set_fact:
10+
foreman_auth_file: "{{ foreman_registry_auth_file }}"
11+
when: foreman_registry_auth_file is defined and foreman_auth_file_stat.stat.exists | default(false)
12+
213
- name: Pull the Foreman container image
314
containers.podman.podman_image:
415
name: "{{ foreman_container_image }}:{{ foreman_container_tag }}"
516
state: present
17+
auth_file: "{{ foreman_auth_file | default(omit) }}"
618

719
- name: Create secret for DATABASE_URL
820
containers.podman.podman_secret:
@@ -63,6 +75,7 @@
6375
env:
6476
SEED_ADMIN_USER: "{{ foreman_initial_admin_username }}"
6577
SEED_ADMIN_PASSWORD: "{{ foreman_initial_admin_password }}"
78+
REGISTRY_AUTH_FILE: "{{ foreman_auth_file | default(omit) }}"
6679
quadlet_options:
6780
- |
6881
[Install]
@@ -88,6 +101,7 @@
88101
DYNFLOW_SIDEKIQ_SCRIPT: "/usr/share/foreman/extras/dynflow-sidekiq.rb"
89102
DYNFLOW_REDIS_URL: "redis://localhost:6379/6"
90103
REDIS_PROVIDER: "DYNFLOW_REDIS_URL"
104+
REGISTRY_AUTH_FILE: "{{ foreman_auth_file | default(omit) }}"
91105
command: "/usr/libexec/foreman/sidekiq-selinux -e production -r /usr/share/foreman/extras/dynflow-sidekiq.rb -C /etc/foreman/dynflow/%i.yml"
92106
quadlet_options:
93107
- |

src/roles/postgresql/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
postgresql_container_image: quay.io/sclorg/postgresql-13-c9s
33
postgresql_container_tag: "latest"
4+
postgresql_registry_auth_file: /etc/foreman/registry-auth.json
45
postgresql_container_name: postgresql
56
postgresql_network: host
67
postgresql_restart_policy: always

src/roles/postgresql/tasks/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
---
2+
- name: Check if auth file exists
3+
ansible.builtin.stat:
4+
path: "{{ postgresql_registry_auth_file }}"
5+
register: postgresql_auth_file_stat
6+
when: postgresql_registry_auth_file is defined and postgresql_registry_auth_file | length > 0
7+
8+
- name: Set auth file variable if exists
9+
ansible.builtin.set_fact:
10+
postgresql_auth_file: "{{ postgresql_registry_auth_file }}"
11+
when: postgresql_registry_auth_file is defined and postgresql_auth_file_stat.stat.exists | default(false)
12+
213
- name: Pull PostgreSQL container image
314
containers.podman.podman_image:
415
name: "{{ postgresql_container_image }}:{{ postgresql_container_tag }}"
516
state: present
17+
auth_file: "{{ postgresql_auth_file | default(omit) }}"
618

719
- name: Create PostgreSQL storage directory
820
ansible.builtin.file:
@@ -29,6 +41,8 @@
2941
- "{{ postgresql_data_dir }}:/var/lib/pgsql/data:Z"
3042
secrets:
3143
- 'postgresql_admin_password,target=POSTGRESQL_ADMIN_PASSWORD,type=env'
44+
env:
45+
REGISTRY_AUTH_FILE: "{{ postgresql_auth_file | default(omit) }}"
3246
quadlet_options:
3347
- |
3448
[Install]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Create /etc/foreman directory
3+
ansible.builtin.file:
4+
path: /etc/foreman
5+
state: directory
6+
mode: '0755'
7+
owner: root
8+
group: root

0 commit comments

Comments
 (0)