Merge ~jsimpso/prometheus-snap:master into prometheus-snap:master

Proposed by James Simpson
Status: Merged
Approved by: Loïc Gomez
Approved revision: 5178dbeafc6d15ab8b4bee76697c0dbb8d9012c6
Merged at revision: 7ff4c5fc6e6674784c27cd04540fffe081bc3f27
Proposed branch: ~jsimpso/prometheus-snap:master
Merge into: prometheus-snap:master
Diff against target: 67 lines (+20/-8)
1 file modified
snap_config_wrapper (+20/-8)
Reviewer Review Type Date Requested Status
Loïc Gomez +1 Approve
prometheus-snap-developers Pending
Review via email: mp+431474@code.launchpad.net

Commit message

Improve file ownership logic (fixes lp:1992713)

To post a comment you must log in.
Revision history for this message
Loïc Gomez (kotodama) :
review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 7ff4c5fc6e6674784c27cd04540fffe081bc3f27

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/snap_config_wrapper b/snap_config_wrapper
2index a3a85ae..3392e57 100755
3--- a/snap_config_wrapper
4+++ b/snap_config_wrapper
5@@ -9,6 +9,10 @@ SNAP_DB_DIR="${SNAP_COMMON}/tsdb"
6 OWNER_USER="snap_daemon"
7 OWNER_GROUP="root"
8
9+# Drop privileges with setpriv and run as snap_daemon
10+# https://snapcraft.io/docs/system-usernames
11+DROP_PRIVS="${SNAP}/usr/bin/setpriv --clear-groups --reuid snap_daemon --regid snap_daemon --"
12+
13 # Snaps can't manage ownership of SNAP_COMMON directly, so we'll move the DB
14 # to a subdir of SNAP_COMMON -- https://forum.snapcraft.io/t/system-usernames/13386/12
15 if [ ! -d "${SNAP_DB_DIR}" ]; then
16@@ -17,16 +21,20 @@ if [ ! -d "${SNAP_DB_DIR}" ]; then
17 find "${SNAP_COMMON}" -maxdepth 1 -mindepth 1 -not -name tsdb -exec mv -t "${SNAP_DB_DIR}" {} +
18 fi
19
20-find "${SNAP_DB_DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 775 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
21-find "${SNAP_DB_DIR}" -type f \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 664 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
22+# Ensure ownership is as expected
23+find "${SNAP_DB_DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
24+
25
26 for DIR in ${SNAP_DATA_DIRS}
27 do
28 if [ ! -d "${SNAP_DATA}/${DIR}" ]; then
29 mkdir "${SNAP_DATA}/${DIR}"
30 fi
31- find "${SNAP_DATA}/${DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 775 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
32- find "${SNAP_DATA}/${DIR}" -type f \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 664 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
33+ # Ensure ownership is as expected
34+ find "${SNAP_DATA}/${DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
35+ # Ensure permissions are as expexted
36+ find "${SNAP_DATA}/${DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec ${DROP_PRIVS} chmod 775 {} \;
37+ find "${SNAP_DATA}/${DIR}" -type f \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec ${DROP_PRIVS} chmod 664 {} \;
38 done
39
40 for FILE in ${SNAP_DATA_FILES}
41@@ -36,8 +44,14 @@ do
42 fi
43 file_user=$(stat "${SNAP_DATA}/${FILE}" --format '%U')
44 file_group=$(stat "${SNAP_DATA}/${FILE}" --format '%G')
45+ file_mode=$(stat "%{SNAP_DATA}/${FILE}" --format '%a')
46+ # Ensure ownership is correct
47 if [ "${file_user}" != "${OWNER_USER}" ] || [ "${file_group}" != "${OWNER_GROUP}" ]; then
48- chmod 664 "${SNAP_DATA}/${FILE}" && chown "${OWNER_USER}:${OWNER_GROUP}" "${SNAP_DATA}/${FILE}"
49+ chown "${OWNER_USER}:${OWNER_GROUP}" "${SNAP_DATA}/${FILE}"
50+ fi
51+ # Ensure permissions are correct
52+ if [ "${file_mode}" != '664' ]; then
53+ ${DROP_PRIVS} chmod 664 "${SNAP_DATA}/${FILE}"
54 fi
55
56 done
57@@ -46,8 +60,6 @@ ulimit -n 65536
58 . "${SNAP_DATA}"/daemon_arguments
59
60 COMMAND="${SNAP}/bin/prometheus ${ARGS} --config.file ${SNAP_DATA}/prometheus.yml --storage.tsdb.path=${SNAP_COMMON}/tsdb"
61-# Drop privileges with setpriv and run as snap_daemon
62-# https://snapcraft.io/docs/system-usernames
63-DROP_PRIVS="${SNAP}/usr/bin/setpriv --clear-groups --reuid snap_daemon --regid snap_daemon --"
64+
65
66 exec ${DROP_PRIVS} ${COMMAND}
67\ No newline at end of file

Subscribers

People subscribed via source and target branches