pkg/rpm: look up current owner in %posttrans shell, not via a broken %global#68965
pkg/rpm: look up current owner in %posttrans shell, not via a broken %global#68965SAY-5 wants to merge 1 commit into
Conversation
|
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here's some information that may help as you continue your Salt journey. There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. |
| _MS_CUR_USER=$(ls -dl /etc/salt/cloud.deploy.d 2>/dev/null | cut -d ' ' -f 3) | ||
| _MS_CUR_GROUP=$(ls -dl /etc/salt/cloud.deploy.d 2>/dev/null | cut -d ' ' -f 4) |
There was a problem hiding this comment.
Using stat is preferable to trying to manually parse ls output with cut
_MS_CUR_USER=$(stat --format '%U' /etc/salt/cloud.deploy.d)
_MS_CUR_GROUP=$(stat --format '%G' /etc/salt/cloud.deploy.d)(use lowercase %u and %g for uid and gid instead of names)
There was a problem hiding this comment.
If we are only trying to use the user and group to set the permissions of other files with chown then the --reference argument to chown can just be used instead of doing extra manual lookups.
chown --reference /etc/salt/cloud.deploy.d -R /var/log/salt/cloud /opt/saltstack/salt/lib/python${PY_VER}/site-packages/salt/cloud/deploy…lookup bdrx312 on saltstack#68965 pointed out that shell-parsing ls is fragile (locale-dependent padding, extra-info rows) and that chown --reference reads the reference path's owner directly from stat(2). Replace the ls|cut lookups in the four %posttrans scriptlets (cloud, master, syndic/api, minion) with chown --reference against the same reference path each block already used for the ls lookup. The fresh-install branch is unchanged - it still uses the %{_SALT_USER}:%{_SALT_GROUP} macros, which are fine in that path. Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
|
@bdrx312 good point, thanks - |
|
Re: the ls -dl | cut pattern in %pre sections (comment 3111482241): those variable lookups were dead code since all posttrans sections now use chown --reference. Removed the %pre if-blocks entirely in the latest push. Re: chown --reference suggestion (comment 3111505370): already applied in the previous commits for all posttrans sections. |
|
@SAY-5 This PR should be targeting 3006.x |
…ce in %posttrans
The %pre scriptlets for master, syndic, and cloud all attempt to capture
the current owner via shell-variable assignment followed by %global:
_MS_LCUR_USER=$(ls -dl /run/salt/master | cut -d ' ' -f 3)
%global _MS_CUR_USER %{_MS_LCUR_USER}
RPM macro expansion happens at parse time, not shell execution time.
%{_MS_LCUR_USER} is not a defined macro, so the %global body expands to
the literal string "%{_MS_LCUR_USER}". In %posttrans, chown is invoked
with that literal and exits with "invalid user" (salt#68646).
Remove the now-dead %pre blocks for master, syndic, and cloud.
Replace the upgrade branches in %posttrans cloud/master/syndic/api with
chown --reference, which reads the existing owner directly from the
filesystem at scriptlet execution time without shell-parsing ls output.
Fixes saltstack#68646
69b0f8d to
2ca095e
Compare
Fixes #68646.
Problem
The
%prescriptlets formaster,minion,syndic,cloudandapiall do:with the intent that the matching
%posttransscriptlet picks up those values via%{_MS_CUR_USER}. RPM macro expansion runs at scriptlet parse time, not at shell execution time, and the%globalbody is not a shell context:%{_MS_LCUR_USER}is not a defined macro, so the redefinition yields the literal string%{_MS_LCUR_USER}. In%posttrans,chownis invoked with that literal and exits with:which is exactly the failure reported on AlmaLinux 10.1 against
salt-minion-3007.11when runningdnf -y reinstall salt-minion. On a reinstall or upgrade, everychown -Rin%posttrans master,minion,syndic,cloudandapifails, which leaves the resulting install with whatever ownership rpm picked during file extraction (typicallyroot) instead of the salt service user.Fix
Drop the broken
%globaltrick and compute the current owner inside each%posttransscriptlet, falling back to%{_SALT_USER}/%{_SALT_GROUP}when the/rundirectory is absent. This runs in the correct shell context on the target system, so the value survives tochownand reinstall/upgrade flows restore the previous ownership as intended. Fresh installs still go through theelsebranch with%{_SALT_USER}and are unchanged.