From 16ef1e41bfc882abecc24d0c4c3feb54ed664764 Mon Sep 17 00:00:00 2001 From: Trevor Bramwell Date: Wed, 27 Jan 2021 14:37:51 -0800 Subject: [PATCH] Fix Sudo Log Ownership for non-'jenkins' users If builds are run with a user other than 'jenkins', chown'ing of the sudoers log will fail. Switching the command to use the current user (and user's default login group) fixes this. Note: See chown(1) DESCRIPTION for an explanation of using a colon after the username while omitting the group Change-Id: Ia9b96e93a250fd22eb36c94471a06c2e211dc9e3 Signed-off-by: Trevor Bramwell --- releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml | 7 +++++++ shell/sudo-logs.sh | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml diff --git a/releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml b/releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml new file mode 100644 index 00000000..1a67dec9 --- /dev/null +++ b/releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Updates the 'sudo-logs.sh' script to set ownerhsip to current build + user and user's login group, instead of the explicit + 'jenkins:jenkins'. This will allow sudoer log ownership to work on + builders not using 'jenkins' as their build username. diff --git a/shell/sudo-logs.sh b/shell/sudo-logs.sh index 29e54df7..257ee23a 100755 --- a/shell/sudo-logs.sh +++ b/shell/sudo-logs.sh @@ -31,7 +31,7 @@ function copy_log() ;; esac sudo_log=$(basename "$sudo_log") - sudo chown jenkins:jenkins "/tmp/$sudo_log" + sudo chown "$(id -nu)": "/tmp/$sudo_log" chmod 0644 "/tmp/$sudo_log" mkdir -p "$WORKSPACE/archives/sudo" mv "/tmp/$sudo_log" "$WORKSPACE/archives/sudo/$sudo_log" -- 2.16.6