fix(roles/repo_*): deploy repository files carrying mirror credentials with mode 0600 - #321
Open
markuslf wants to merge 1 commit into
Open
fix(roles/repo_*): deploy repository files carrying mirror credentials with mode 0600#321markuslf wants to merge 1 commit into
markuslf wants to merge 1 commit into
Conversation
…s with mode 0600
25 template tasks across 21 repo roles render a mirror password into a repository
file below /etc/yum.repos.d or /etc/zypp/repos.d and left it world-readable at
0644, so every local account could read the credentials of our package mirror.
The mode is conditional on the role's basic_auth_login rather than a flat 0600,
because 0600 has a price: an unprivileged dnf silently skips a repository file it
cannot read, so `dnf list` and `dnf repolist` stop showing those repositories
without saying why. That is worth paying where there is a secret to protect and
not worth paying on the hosts, the majority, that use the vendor repositories
without authentication. A file without credentials therefore keeps 0644.
The expression was measured rather than assumed, since the obvious spelling is
silently wrong: `mode: "{{ 0o600 if ... }}"` renders the integer and ends up as
0644, while the quoted form yields 600 and 644 as intended, for a credential that
is set, for an undefined variable and for an empty one.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
25 template tasks across 21
repo_*roles render a mirror password into a repository file below/etc/yum.repos.dor/etc/zypp/repos.dand left it world-readable at0644, so every local account on the host could read the credentials of our package mirror.The mode is now conditional on the role's
basic_auth_logininstead of a flat0600:Why conditional and not simply 0600
0600has a price that is easy to miss. An unprivilegeddnfskips a repository file it cannot read without a single word on stderr, sodnf listanddnf repoliststop showing those repositories and give no hint why. Measured on Rocky Linux 9.7 withdnf-4.14.0-31.el9andlibdnf-0.69.0-16.el9,/etc/yum.repos.d/rocky.reposet to0600:That is worth paying where there is a secret to protect, and not worth paying on the majority of hosts, which use the vendor repositories without authentication. A repository file without credentials therefore keeps
0644.Why the skip is silent
Reading
dnfalone suggests the opposite, becausednf/conf/read.pydoes have a warning path:The exception never gets that far.
libdnfthrowsIniParser::CantOpenFileonEACCES,ConfigParser::readre-throws it asConfigParser::CantOpenFile, and the SWIG layer maps it to a PythonIOError. Butbindings/swig/conf.ithen replacesConfigParser.readwith a Python shim that swallows exactly that:The parser is left with zero sections,
dnfiterates zero repositories, and nothing is logged. Calling the binding directly confirms it, as an unprivileged user:Rocky Linux 10.1 still ships
dnf4 withlibdnf, so this holds across RHEL 8, 9 and 10.dnf5 behaves differently
On Fedora 43 with
dnf5-5.2.18an unreadable repository file is fatal rather than silent:A single
0600repository file breaks every unprivilegeddnfcall on the host, not just the one repository. Norepo_*role lists Fedora inCOMPATIBILITY.md, so nothing here is affected today, but the conditional mode matters more oncednf5reaches RHEL, not less.Why the expression looks the way it does
The obvious spelling is silently wrong, so both forms were measured with
ansible-playbookrather than assumed:Notes for the reviewer
0644, only the repository files change.| length > 0and the0ooctal notation follow CONTRIBUTING; the one existing precedent for a mode inside Jinja isroles/nfs_client.