Fix Sudo Log Ownership for non-'jenkins' users 51/66651/4
authorTrevor Bramwell <tbramwell@linuxfoundation.org>
Wed, 27 Jan 2021 22:37:51 +0000 (14:37 -0800)
committerAnil Belur <abelur@linuxfoundation.org>
Thu, 28 Jan 2021 04:26:00 +0000 (14:26 +1000)
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 <tbramwell@linuxfoundation.org>
releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml [new file with mode: 0644]
shell/sudo-logs.sh

diff --git a/releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml b/releasenotes/notes/sudo-log-owner-03e7cf690e867482.yaml
new file mode 100644 (file)
index 0000000..1a67dec
--- /dev/null
@@ -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.
index 29e54df..257ee23 100755 (executable)
@@ -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"