diff --git a/.circleci/config.yml b/.circleci/config.yml index e07b615a..111d7545 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -170,16 +170,23 @@ jobs: type: string steps: - common_setup + - run: + name: Write pgEdge repository client credentials + command: | + mkdir -p ~/.pgedge + chmod 700 ~/.pgedge + ( + umask 077 + printf '%s' "${PGEDGE_CLIENT_KEY:?PGEDGE_CLIENT_KEY must be set}" | base64 -d > ~/.pgedge/client.key + printf '%s' "${PGEDGE_CLIENT_CRT:?PGEDGE_CLIENT_CRT must be set}" | base64 -d > ~/.pgedge/client.crt + ) - run: name: Start << parameters.systemd_os >> systemd cluster command: make ci-systemd-up SYSTEMD_OS=<< parameters.systemd_os >> - run: name: Run << parameters.systemd_os >> systemd E2E tests command: | - # The fixture names drop the hyphen before the OS version, e.g. - # rocky-9-community -> docker-systemd-rocky9-community. - fixture="docker-systemd-$(echo '<< parameters.systemd_os >>' | sed -E 's/^([a-z]+)-([0-9]+)/\1\2/')" - make test-e2e E2E_FIXTURE="${fixture}" E2E_DEBUG=1 TEST_RERUN_FAILS=2 + make test-e2e E2E_FIXTURE='docker-systemd-<< parameters.systemd_os >>' E2E_DEBUG=1 TEST_RERUN_FAILS=2 - run: name: Archive debug output command: | diff --git a/.devcontainer/walkthrough/post-create.sh b/.devcontainer/walkthrough/post-create.sh index ec887000..ae9e7390 100755 --- a/.devcontainer/walkthrough/post-create.sh +++ b/.devcontainer/walkthrough/post-create.sh @@ -3,11 +3,30 @@ set -euo pipefail echo "=== pgEdge Control Plane Walkthrough — Codespaces Setup ===" -# Add the pgEdge repository +# Add the pgEdge repository. downloads.pgedge.com, not apt.pgedge.com: the +# gated repository cannot serve the package that configures access to it. echo "Adding pgEdge apt repository..." -sudo curl -sSL https://apt.pgedge.com/repodeb/pgedge-release_latest_all.deb -o /tmp/pgedge-release.deb +sudo curl -sSL https://downloads.pgedge.com/repodeb/pgedge-release_latest_all.deb -o /tmp/pgedge-release.deb sudo dpkg -i /tmp/pgedge-release.deb +# The repository ships disabled and authenticates clients with mutual TLS. +# Supply PGEDGE_CLIENT_CERT and PGEDGE_CLIENT_KEY (PEM contents) to use it. +if [ -n "${PGEDGE_CLIENT_CERT:-}" ] && [ -n "${PGEDGE_CLIENT_KEY:-}" ]; then + echo "Installing the pgEdge client certificate..." + sudo install -d -m 0755 /etc/pgedge + # Create the key empty at 0600 first: writing it and then chmod'ing would + # leave it world-readable for the interval in between. + sudo install -m 0600 /dev/null /etc/pgedge/client.key + sudo install -m 0644 /dev/null /etc/pgedge/client.crt + printf '%s\n' "$PGEDGE_CLIENT_CERT" | sudo tee /etc/pgedge/client.crt >/dev/null + printf '%s\n' "$PGEDGE_CLIENT_KEY" | sudo tee /etc/pgedge/client.key >/dev/null + sudo pgedge-subscription-manager install \ + /etc/pgedge/client.crt /etc/pgedge/client.key --force +else + echo "WARNING: PGEDGE_CLIENT_CERT / PGEDGE_CLIENT_KEY are not set." + echo " The pgEdge repository stays disabled and the install below will fail." +fi + # Install jq and the Postgres client echo "Installing jq and pgEdge Postgres client..." sudo apt-get update -qq diff --git a/Makefile b/Makefile index a62476df..466f6cf6 100644 --- a/Makefile +++ b/Makefile @@ -138,9 +138,9 @@ e2e-help: @echo "" @echo " E2E variables:" @echo " E2E_FIXTURE Fixture name (lima, ec2, ec2-systemd, lima-systemd," - @echo " docker-systemd-rocky9, docker-systemd-debian13," - @echo " docker-systemd-rocky9-community," - @echo " docker-systemd-debian13-community)" + @echo " docker-systemd-rocky-9, docker-systemd-debian-13," + @echo " docker-systemd-rocky-9-community," + @echo " docker-systemd-debian-13-community)" @echo " E2E_RUN Test name regex filter" @echo " E2E_PARALLEL Parallelism (default: 4)" @echo " E2E_DEBUG=1 Print debug output for failing tests" @@ -663,3 +663,24 @@ ci-systemd-down: docs: docker build -t control-plane-docs ./docs docker run --rm -it -p 8000:8000 -v ${PWD}:/docs control-plane-docs + +################################### +# pgEdge repo key # +################################### + +repo_key_dir=$(HOME)/.pgedge +repo_key=$(repo_key_dir)/client.key +repo_csr=$(repo_key_dir)/client.csr +repo_crt=$(repo_key_dir)/client.crt + +$(repo_key_dir): + mkdir $(repo_key_dir) + +$(repo_key): $(repo_key_dir) + openssl genrsa -out $(repo_key) 2048 + +$(repo_csr): $(repo_key) + openssl req -new -key $(repo_key) -out $(repo_csr) -subj "/CN=$(shell hostname)" + +.PHONY: pgedge-repo-csr +pgedge-repo-csr: $(repo_csr) diff --git a/docker/control-plane-systemd-ci/debian-13-community/docker-compose.yaml b/docker/control-plane-systemd-ci/debian-13-community/docker-compose.yaml index f91478d7..80b4de04 100644 --- a/docker/control-plane-systemd-ci/debian-13-community/docker-compose.yaml +++ b/docker/control-plane-systemd-ci/debian-13-community/docker-compose.yaml @@ -8,7 +8,7 @@ # IP on the compose network. # # make ci-systemd-up SYSTEMD_OS=debian-13-community -# make test-e2e E2E_FIXTURE=docker-systemd-debian13-community +# make test-e2e E2E_FIXTURE=docker-systemd-debian-13-community # make ci-systemd-down SYSTEMD_OS=debian-13-community name: cp-systemd-debian-13-community @@ -34,21 +34,21 @@ x-host: &host services: host-1: <<: *host - container_name: cp-debian13-community-host-1 + container_name: cp-debian-13-community-host-1 hostname: host-1 ports: - "127.0.0.1:3030:3000" host-2: <<: *host - container_name: cp-debian13-community-host-2 + container_name: cp-debian-13-community-host-2 hostname: host-2 ports: - "127.0.0.1:3031:3000" host-3: <<: *host - container_name: cp-debian13-community-host-3 + container_name: cp-debian-13-community-host-3 hostname: host-3 ports: - "127.0.0.1:3032:3000" diff --git a/docker/control-plane-systemd-ci/debian-13/Dockerfile b/docker/control-plane-systemd-ci/debian-13/Dockerfile index 66553b18..a99a735e 100644 --- a/docker/control-plane-systemd-ci/debian-13/Dockerfile +++ b/docker/control-plane-systemd-ci/debian-13/Dockerfile @@ -21,21 +21,41 @@ RUN apt-get update && \ # pgEdge prerequisites from the release repo, so CI tests certified builds. # The RAG server package enables its own unit, which would listen on port # 8080 at boot. The Control Plane runs its own RAG units, so disable it. -RUN curl -fsSL --retry 5 https://apt.pgedge.com/repodeb/pgedge-release_latest_all.deb \ - -o /tmp/pgedge-release.deb && \ - dpkg -i /tmp/pgedge-release.deb && \ - rm /tmp/pgedge-release.deb && \ - apt-get update -o Acquire::Retries=5 && \ - apt-get install -y -o Acquire::Retries=5 \ - pgedge-postgresql-18 \ - pgedge-postgresql-18-spock50 \ - pgedge-pgbackrest \ - pgedge-patroni \ - pgedge-postgrest \ - pgedge-postgres-mcp \ - pgedge-rag-server2 && \ - rm -f /etc/systemd/system/multi-user.target.wants/pgedge-rag-server2.service && \ - rm -rf /var/lib/apt/lists/* +RUN --mount=type=secret,id=repo_client_crt \ + --mount=type=secret,id=repo_client_key \ + < [Runme extension](https://marketplace.visualstudio.com/items?itemName=stateful.runme) > in VS Code and click **Execute Cell** on each block. +> [!IMPORTANT] +> **The pgEdge package repository needs a client certificate** +> Before creating the Codespace, add `PGEDGE_CLIENT_CERT` and +> `PGEDGE_CLIENT_KEY` as *account-level* Codespaces secrets -- under your own +> [Codespaces settings](https://github.com/settings/codespaces), granting this +> repository access to each -- holding the PEM contents of your client +> certificate and its matching key. Account-level secrets need no write access +> to this repository, so there is no need to fork it; they reach the setup +> script because it runs as `postCreateCommand`, after the Codespace is up. +> The certificate must be the full chain -- your leaf certificate first, +> followed by the issuing intermediate -- because the leaf alone cannot +> authenticate. The +> repositories authenticate clients with mutual TLS, so without both secrets +> the setup leaves them disabled and the Postgres client will not install. + ## Prerequisites - [Docker Engine](https://docs.docker.com/engine/install/) (Linux) or [Docker Desktop](https://docs.docker.com/desktop/) (macOS) diff --git a/e2e/fixtures/outputs/docker-systemd-debian13-community.test_config.yaml b/e2e/fixtures/outputs/docker-systemd-debian-13-community.test_config.yaml similarity index 51% rename from e2e/fixtures/outputs/docker-systemd-debian13-community.test_config.yaml rename to e2e/fixtures/outputs/docker-systemd-debian-13-community.test_config.yaml index 9a216ce6..269af7ba 100644 --- a/e2e/fixtures/outputs/docker-systemd-debian13-community.test_config.yaml +++ b/e2e/fixtures/outputs/docker-systemd-debian-13-community.test_config.yaml @@ -3,13 +3,13 @@ hosts: host-1: external_ip: 127.0.0.1 port: 3030 - ssh_command: docker exec cp-debian13-community-host-1 sh -c + ssh_command: docker exec cp-debian-13-community-host-1 sh -c host-2: external_ip: 127.0.0.1 port: 3031 - ssh_command: docker exec cp-debian13-community-host-2 sh -c + ssh_command: docker exec cp-debian-13-community-host-2 sh -c host-3: external_ip: 127.0.0.1 port: 3032 - ssh_command: docker exec cp-debian13-community-host-3 sh -c + ssh_command: docker exec cp-debian-13-community-host-3 sh -c service_packages_not_installed: true diff --git a/e2e/fixtures/outputs/docker-systemd-debian13.test_config.yaml b/e2e/fixtures/outputs/docker-systemd-debian-13.test_config.yaml similarity index 50% rename from e2e/fixtures/outputs/docker-systemd-debian13.test_config.yaml rename to e2e/fixtures/outputs/docker-systemd-debian-13.test_config.yaml index 7a282d14..05ac9c7b 100644 --- a/e2e/fixtures/outputs/docker-systemd-debian13.test_config.yaml +++ b/e2e/fixtures/outputs/docker-systemd-debian-13.test_config.yaml @@ -3,12 +3,12 @@ hosts: host-1: external_ip: 127.0.0.1 port: 3010 - ssh_command: docker exec cp-debian13-host-1 sh -c + ssh_command: docker exec cp-debian-13-host-1 sh -c host-2: external_ip: 127.0.0.1 port: 3011 - ssh_command: docker exec cp-debian13-host-2 sh -c + ssh_command: docker exec cp-debian-13-host-2 sh -c host-3: external_ip: 127.0.0.1 port: 3012 - ssh_command: docker exec cp-debian13-host-3 sh -c + ssh_command: docker exec cp-debian-13-host-3 sh -c diff --git a/e2e/fixtures/outputs/docker-systemd-rocky9-community.test_config.yaml b/e2e/fixtures/outputs/docker-systemd-rocky-9-community.test_config.yaml similarity index 51% rename from e2e/fixtures/outputs/docker-systemd-rocky9-community.test_config.yaml rename to e2e/fixtures/outputs/docker-systemd-rocky-9-community.test_config.yaml index a65a62e5..d6aa6ddc 100644 --- a/e2e/fixtures/outputs/docker-systemd-rocky9-community.test_config.yaml +++ b/e2e/fixtures/outputs/docker-systemd-rocky-9-community.test_config.yaml @@ -3,13 +3,13 @@ hosts: host-1: external_ip: 127.0.0.1 port: 3020 - ssh_command: docker exec cp-rocky9-community-host-1 sh -c + ssh_command: docker exec cp-rocky-9-community-host-1 sh -c host-2: external_ip: 127.0.0.1 port: 3021 - ssh_command: docker exec cp-rocky9-community-host-2 sh -c + ssh_command: docker exec cp-rocky-9-community-host-2 sh -c host-3: external_ip: 127.0.0.1 port: 3022 - ssh_command: docker exec cp-rocky9-community-host-3 sh -c + ssh_command: docker exec cp-rocky-9-community-host-3 sh -c service_packages_not_installed: true diff --git a/e2e/fixtures/outputs/docker-systemd-rocky9.test_config.yaml b/e2e/fixtures/outputs/docker-systemd-rocky-9.test_config.yaml similarity index 51% rename from e2e/fixtures/outputs/docker-systemd-rocky9.test_config.yaml rename to e2e/fixtures/outputs/docker-systemd-rocky-9.test_config.yaml index 565bf68a..b76ff397 100644 --- a/e2e/fixtures/outputs/docker-systemd-rocky9.test_config.yaml +++ b/e2e/fixtures/outputs/docker-systemd-rocky-9.test_config.yaml @@ -3,12 +3,12 @@ hosts: host-1: external_ip: 127.0.0.1 port: 3000 - ssh_command: docker exec cp-rocky9-host-1 sh -c + ssh_command: docker exec cp-rocky-9-host-1 sh -c host-2: external_ip: 127.0.0.1 port: 3001 - ssh_command: docker exec cp-rocky9-host-2 sh -c + ssh_command: docker exec cp-rocky-9-host-2 sh -c host-3: external_ip: 127.0.0.1 port: 3002 - ssh_command: docker exec cp-rocky9-host-3 sh -c + ssh_command: docker exec cp-rocky-9-host-3 sh -c diff --git a/e2e/fixtures/roles/install_systemd_prerequisites/defaults/main.yaml b/e2e/fixtures/roles/install_systemd_prerequisites/defaults/main.yaml index ae6dcac9..c8223fd8 100644 --- a/e2e/fixtures/roles/install_systemd_prerequisites/defaults/main.yaml +++ b/e2e/fixtures/roles/install_systemd_prerequisites/defaults/main.yaml @@ -1,2 +1,9 @@ --- cp_source: staging +# Client certificate for the gated pgEdge repositories. Read from files on the +# controller rather than passed on the command line, so the PEM never lands in +# argv. Override the paths with PGEDGE_CLIENT_CERT_FILE / PGEDGE_CLIENT_KEY_FILE. +pgedge_client_cert_file: "{{ lookup('env', 'PGEDGE_CLIENT_CERT_FILE') | default('~/.pgedge/client.crt', true) }}" +pgedge_client_key_file: "{{ lookup('env', 'PGEDGE_CLIENT_KEY_FILE') | default('~/.pgedge/client.key', true) }}" +pgedge_client_cert: "{{ lookup('file', pgedge_client_cert_file | expanduser, errors='ignore') | default('', true) }}" +pgedge_client_key: "{{ lookup('file', pgedge_client_key_file | expanduser, errors='ignore') | default('', true) }}" diff --git a/e2e/fixtures/roles/install_systemd_prerequisites/tasks/main.yaml b/e2e/fixtures/roles/install_systemd_prerequisites/tasks/main.yaml index 1b84731c..abb01dc3 100644 --- a/e2e/fixtures/roles/install_systemd_prerequisites/tasks/main.yaml +++ b/e2e/fixtures/roles/install_systemd_prerequisites/tasks/main.yaml @@ -8,9 +8,21 @@ when: ansible_os_family == 'RedHat' changed_when: true +# Imported explicitly rather than left to dnf's auto-import from the repo's +# gpgkey=. The RPM and DEB repositories are signed with different keys, so this +# is keys/dnf specifically. +- name: Install the pgEdge package signing key (RPM) + ansible.builtin.rpm_key: + key: https://downloads.pgedge.com/keys/dnf/pgedge-rsa.pub + state: present + when: ansible_os_family == 'RedHat' + +# downloads.pgedge.com, not dnf.pgedge.com: the gated repository cannot serve +# the package that configures access to it. The repo package itself is +# unsigned, hence disable_gpg_check here. - name: Install pgEdge release RPM dnf: - name: https://dnf.pgedge.com/reporpm/pgedge-release-latest.noarch.rpm + name: https://downloads.pgedge.com/reporpm/pgedge-release-latest.noarch.rpm state: present disable_gpg_check: true when: ansible_os_family == 'RedHat' @@ -22,18 +34,6 @@ replace: 'staging' when: ansible_os_family == 'RedHat' and cp_source == 'staging' -- name: Install pgEdge packages (RPM) - dnf: - name: "{{ _rpm_packages }}" - state: present - when: ansible_os_family == 'RedHat' - -- name: Install awscli (RPM) - dnf: - name: awscli - state: present - when: ansible_os_family == 'RedHat' - # ── DEB (Debian) ────────────────────────────────────────────────────────────── - name: Install apt prerequisites (Debian) @@ -46,9 +46,11 @@ update_cache: true when: ansible_os_family == 'Debian' +# downloads.pgedge.com, not apt.pgedge.com: the gated repository cannot serve +# the package that configures access to it. - name: Download pgEdge release package (Debian) ansible.builtin.get_url: - url: https://apt.pgedge.com/repodeb/pgedge-release_latest_all.deb + url: https://downloads.pgedge.com/repodeb/pgedge-release_latest_all.deb dest: /tmp/pgedge-release.deb mode: '0644' when: ansible_os_family == 'Debian' @@ -66,6 +68,68 @@ replace: 'staging' when: ansible_os_family == 'Debian' and cp_source == 'staging' +# ── Repository client certificate ──────────────────────────────────────────── + +- name: Install the pgEdge client certificate and enable the repositories + when: pgedge_client_cert | default('') | length > 0 + and pgedge_client_key | default('') | length > 0 + block: + - name: Create the pgEdge configuration directory + ansible.builtin.file: + path: "{{ _pgedge_client_cert_dir }}" + state: directory + owner: root + group: root + mode: '0755' + - name: Write the client certificate + ansible.builtin.copy: + content: "{{ pgedge_client_cert | trim }}\n" + dest: "{{ _pgedge_client_cert_dir }}/client.crt" + owner: root + group: root + mode: '0644' + no_log: true + # Ownership and mode are left to pgedge-subscription-manager: apt reads the + # key as _apt, dnf as root. + - name: Write the client key + ansible.builtin.copy: + content: "{{ pgedge_client_key | trim }}\n" + dest: "{{ _pgedge_client_cert_dir }}/client.key" + owner: root + group: root + mode: '0600' + no_log: true + - name: Validate the certificate and enable the pgEdge repositories + ansible.builtin.command: >- + pgedge-subscription-manager install + {{ _pgedge_client_cert_dir }}/client.crt {{ _pgedge_client_cert_dir }}/client.key --force + changed_when: true + +- name: Warn when no pgEdge client certificate was supplied + ansible.builtin.debug: + msg: >- + No pgEdge client certificate supplied for this run. Any existing + repository configuration is left as it is, and installing pgEdge packages + may fail. Put the certificate and key at ~/.pgedge/client.crt and + ~/.pgedge/client.key, or point PGEDGE_CLIENT_CERT_FILE and + PGEDGE_CLIENT_KEY_FILE at them. + when: not (pgedge_client_cert | default('') | length > 0 + and pgedge_client_key | default('') | length > 0) + +# ── pgEdge packages ─────────────────────────────────────────────────────────── + +- name: Install pgEdge packages (RPM) + dnf: + name: "{{ _rpm_packages }}" + state: present + when: ansible_os_family == 'RedHat' + +- name: Install awscli (RPM) + dnf: + name: awscli + state: present + when: ansible_os_family == 'RedHat' + - name: Install pgEdge packages (DEB) apt: name: "{{ _deb_packages }}" diff --git a/e2e/fixtures/roles/install_systemd_prerequisites/vars/main.yaml b/e2e/fixtures/roles/install_systemd_prerequisites/vars/main.yaml index 3eceb34c..7276701e 100644 --- a/e2e/fixtures/roles/install_systemd_prerequisites/vars/main.yaml +++ b/e2e/fixtures/roles/install_systemd_prerequisites/vars/main.yaml @@ -5,6 +5,9 @@ _arch_transform: aarch64: arm64 arm64: arm64 +# Where the repository client certificate and key are written +_pgedge_client_cert_dir: "{{ '/etc/pki/pgedge' if ansible_os_family == 'RedHat' else '/etc/pgedge' }}" + # RPM package names _rpm_packages: - "pgedge-postgresql{{ pg_version }}" diff --git a/lima/roles/deb_prerequisites/tasks/main.yaml b/lima/roles/deb_prerequisites/tasks/main.yaml index fa7290fd..5087fb5f 100644 --- a/lima/roles/deb_prerequisites/tasks/main.yaml +++ b/lima/roles/deb_prerequisites/tasks/main.yaml @@ -15,9 +15,10 @@ - wget - git - chrony +# downloads.pgedge.com, not apt.pgedge.com -- see rhel_prerequisites. - name: Install pgEdge repository ansible.builtin.apt: - deb: https://apt.pgedge.com/repodeb/pgedge-release_latest_all.deb + deb: https://downloads.pgedge.com/repodeb/pgedge-release_latest_all.deb state: present - name: Reconfigure pgEdge repository for staging packages ansible.builtin.replace: @@ -33,10 +34,57 @@ replace: release when: not (use_staging_packages | bool) register: repo_reconfigured_to_release +- name: Install the pgEdge client certificate and enable the repositories + when: pgedge_client_cert | default('') | length > 0 + and pgedge_client_key | default('') | length > 0 + block: + - name: Create the pgEdge configuration directory + ansible.builtin.file: + path: "/etc/pgedge" + state: directory + owner: root + group: root + mode: '0755' + - name: Write the client certificate + ansible.builtin.copy: + content: "{{ pgedge_client_cert | trim }}\n" + dest: "/etc/pgedge/client.crt" + owner: root + group: root + mode: '0644' + no_log: true + # Ownership and mode are left to pgedge-subscription-manager: apt reads the + # key as _apt, dnf as root. + - name: Write the client key + ansible.builtin.copy: + content: "{{ pgedge_client_key | trim }}\n" + dest: "/etc/pgedge/client.key" + owner: root + group: root + mode: '0600' + no_log: true + - name: Validate the certificate and enable the pgEdge repositories + ansible.builtin.command: >- + pgedge-subscription-manager install + /etc/pgedge/client.crt /etc/pgedge/client.key --force + changed_when: true + +- name: Warn when no pgEdge client certificate was supplied + ansible.builtin.debug: + msg: >- + No pgEdge client certificate supplied for this run. Any existing + repository configuration is left as it is, and installing pgEdge packages + may fail. Put the certificate and key at ~/.pgedge/client.crt and + ~/.pgedge/client.key, or point PGEDGE_CLIENT_CERT_FILE and + PGEDGE_CLIENT_KEY_FILE at them. + when: not (pgedge_client_cert | default('') | length > 0 + and pgedge_client_key | default('') | length > 0) + - name: Update apt cache again ansible.builtin.apt: update_cache: yes changed_when: false + - name: Track configured Spock major for reinstall detection ansible.builtin.copy: content: "{{ spock_major | default('50') }}" diff --git a/lima/roles/rhel_prerequisites/tasks/main.yaml b/lima/roles/rhel_prerequisites/tasks/main.yaml index 2bbf32d0..0a03ccf5 100644 --- a/lima/roles/rhel_prerequisites/tasks/main.yaml +++ b/lima/roles/rhel_prerequisites/tasks/main.yaml @@ -13,9 +13,19 @@ community.general.dnf_config_manager: name: crb state: enabled +# Imported explicitly rather than left to dnf's auto-import from the repo's +# gpgkey=. The RPM and DEB repositories are signed with different keys, so this +# is keys/dnf specifically. +- name: Install the pgEdge package signing key + ansible.builtin.rpm_key: + key: https://downloads.pgedge.com/keys/dnf/pgedge-rsa.pub + state: present +# downloads.pgedge.com, not dnf.pgedge.com: the gated repository cannot serve +# the package that configures access to it. The repo package itself is +# unsigned, hence disable_gpg_check here and nowhere else. - name: Install pgEdge repository ansible.builtin.package: - name: https://dnf.pgedge.com/reporpm/pgedge-release-latest.noarch.rpm + name: https://downloads.pgedge.com/reporpm/pgedge-release-latest.noarch.rpm state: present disable_gpg_check: true - name: Reconfigure pgEdge repository for staging packages @@ -32,6 +42,52 @@ replace: release when: not (use_staging_packages | bool) register: repo_reconfigured_to_release +- name: Install the pgEdge client certificate and enable the repositories + when: pgedge_client_cert | default('') | length > 0 + and pgedge_client_key | default('') | length > 0 + block: + - name: Create the pgEdge configuration directory + ansible.builtin.file: + path: "/etc/pki/pgedge" + state: directory + owner: root + group: root + mode: '0755' + - name: Write the client certificate + ansible.builtin.copy: + content: "{{ pgedge_client_cert | trim }}\n" + dest: "/etc/pki/pgedge/client.crt" + owner: root + group: root + mode: '0644' + no_log: true + # Ownership and mode are left to pgedge-subscription-manager: apt reads the + # key as _apt, dnf as root. + - name: Write the client key + ansible.builtin.copy: + content: "{{ pgedge_client_key | trim }}\n" + dest: "/etc/pki/pgedge/client.key" + owner: root + group: root + mode: '0600' + no_log: true + - name: Validate the certificate and enable the pgEdge repositories + ansible.builtin.command: >- + pgedge-subscription-manager install + /etc/pki/pgedge/client.crt /etc/pki/pgedge/client.key --force + changed_when: true + +- name: Warn when no pgEdge client certificate was supplied + ansible.builtin.debug: + msg: >- + No pgEdge client certificate supplied for this run. Any existing + repository configuration is left as it is, and installing pgEdge packages + may fail. Put the certificate and key at ~/.pgedge/client.crt and + ~/.pgedge/client.key, or point PGEDGE_CLIENT_CERT_FILE and + PGEDGE_CLIENT_KEY_FILE at them. + when: not (pgedge_client_cert | default('') | length > 0 + and pgedge_client_key | default('') | length > 0) + - name: Track configured Spock major for reinstall detection ansible.builtin.copy: content: "{{ spock_major | default('50') }}" diff --git a/lima/vars.yaml b/lima/vars.yaml index 1e1a09ac..05261d0d 100644 --- a/lima/vars.yaml +++ b/lima/vars.yaml @@ -1,5 +1,13 @@ --- use_staging_packages: false +# Client certificate for the gated pgEdge repositories. Read from files on the +# controller rather than passed on the command line, so the PEM never lands in +# argv. Override the paths with PGEDGE_CLIENT_CERT_FILE / PGEDGE_CLIENT_KEY_FILE. +pgedge_client_cert_file: "{{ lookup('env', 'PGEDGE_CLIENT_CERT_FILE') | default('~/.pgedge/client.crt', true) }}" +pgedge_client_key_file: "{{ lookup('env', 'PGEDGE_CLIENT_KEY_FILE') | default('~/.pgedge/client.key', true) }}" +pgedge_client_cert: "{{ lookup('file', pgedge_client_cert_file | expanduser, errors='ignore') | default('', true) }}" +pgedge_client_key: "{{ lookup('file', pgedge_client_key_file | expanduser, errors='ignore') | default('', true) }}" + os: rocky-9 machines: - name: control-plane-dev-1