pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

fix(operations.zypper): fix gpg validation, auto-import keys, and permissions

Open doraem-on opened this issue 5 months ago • 0 comments

Description:

Fixes #1830 Fixes #1831 Fixes #1832

Description

This PR addresses three related issues with zypper and repository management to ensure repositories and packages deploy correctly out-of-the-box.

  1. GPG Key URL Validation (#1830): ensure_yum_repo now parses the gpgkey argument to ensure it's a valid URL (or an absolute local path). If someone passes invalid text (like "INVALID TEXT"), it throws an OperationValueError early during the generation phase rather than failing silently during deployment.
  2. Key Auto-Import for Non-Interactive Installs (#1831): zypper --non-interactive automatically rejects unrecognized GPG keys by default. To fix failed package installations from new repositories, I added the --gpg-auto-import-keys flag to install_command and upgrade_command in zypper.packages(). Zypper will now correctly import valid keys instead of failing.
  3. World-Readable .repo Files (#1832): files.put was inheriting strict permissions from the internal string buffer, causing repo files to be created with restricted permissions (e.g., 0600). I added mode="0644" to the files.put call so that non-root users can correctly query and search repositories, matching native package manager defaults.

Testing

I updated the JSON test fixtures in accordance with Pyinfra's testing guidelines to verify all the changes:

  • Key Auto-Import Tests: Updated the expected command output in tests/operations/zypper.packages/add_packages.json, install_with_args.json, install_with_global_args.json, and update_clean.json to explicitly ensure the --gpg-auto-import-keys flag is present during installs and updates.

  • Validation Tests: Updated tests/operations/dnf.repo/add.json, yum.repo/add.json, and zypper.repo/add.json to use a valid dummy URL (https://test/key) so they pass the new URL validation checks.

  • Permissions Tests: Added the expected chmod 644 /etc/.../somerepo.repo command to the expected outputs of the dnf.repo, yum.repo, and zypper.repo test fixtures to mathematically verify the mode="0644" implementation.

  • [x] Pull request is based on the default branch (3.x at this time)

  • [x] Pull request includes tests for any new/updated operations/facts

  • [x] Pull request includes documentation for any new/updated operations/facts

  • [x] Tests pass (see scripts/dev-test.sh)

  • [x] Type checking & code style passes (see scripts/dev-lint.sh)

  • [x] Pull request title follows the conventional commits format

doraem-on avatar Jun 12 '26 13:06 doraem-on