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
diff --git a/snap_config_wrapper b/snap_config_wrapper
index a3a85ae..3392e57 100755
--- a/snap_config_wrapper
+++ b/snap_config_wrapper
@@ -9,6 +9,10 @@ SNAP_DB_DIR="${SNAP_COMMON}/tsdb"
9OWNER_USER="snap_daemon"9OWNER_USER="snap_daemon"
10OWNER_GROUP="root"10OWNER_GROUP="root"
1111
12# Drop privileges with setpriv and run as snap_daemon
13# https://snapcraft.io/docs/system-usernames
14DROP_PRIVS="${SNAP}/usr/bin/setpriv --clear-groups --reuid snap_daemon --regid snap_daemon --"
15
12# Snaps can't manage ownership of SNAP_COMMON directly, so we'll move the DB16# Snaps can't manage ownership of SNAP_COMMON directly, so we'll move the DB
13# to a subdir of SNAP_COMMON -- https://forum.snapcraft.io/t/system-usernames/13386/1217# to a subdir of SNAP_COMMON -- https://forum.snapcraft.io/t/system-usernames/13386/12
14if [ ! -d "${SNAP_DB_DIR}" ]; then18if [ ! -d "${SNAP_DB_DIR}" ]; then
@@ -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}" {} +21 find "${SNAP_COMMON}" -maxdepth 1 -mindepth 1 -not -name tsdb -exec mv -t "${SNAP_DB_DIR}" {} +
18fi22fi
1923
20find "${SNAP_DB_DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 775 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;24# Ensure ownership is as expected
21find "${SNAP_DB_DIR}" -type f \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 664 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;25find "${SNAP_DB_DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;
26
2227
23for DIR in ${SNAP_DATA_DIRS}28for DIR in ${SNAP_DATA_DIRS}
24do29do
25 if [ ! -d "${SNAP_DATA}/${DIR}" ]; then30 if [ ! -d "${SNAP_DATA}/${DIR}" ]; then
26 mkdir "${SNAP_DATA}/${DIR}"31 mkdir "${SNAP_DATA}/${DIR}"
27 fi32 fi
28 find "${SNAP_DATA}/${DIR}" -type d \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 775 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;33 # Ensure ownership is as expected
29 find "${SNAP_DATA}/${DIR}" -type f \( ! -user "${OWNER_USER}" -o ! -group "${OWNER_GROUP}" \) -exec chmod 664 {} \; -exec chown "${OWNER_USER}:${OWNER_GROUP}" {} \;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 {} \;
30done38done
3139
32for FILE in ${SNAP_DATA_FILES}40for FILE in ${SNAP_DATA_FILES}
@@ -36,8 +44,14 @@ do
36 fi44 fi
37 file_user=$(stat "${SNAP_DATA}/${FILE}" --format '%U')45 file_user=$(stat "${SNAP_DATA}/${FILE}" --format '%U')
38 file_group=$(stat "${SNAP_DATA}/${FILE}" --format '%G')46 file_group=$(stat "${SNAP_DATA}/${FILE}" --format '%G')
47 file_mode=$(stat "%{SNAP_DATA}/${FILE}" --format '%a')
48 # Ensure ownership is correct
39 if [ "${file_user}" != "${OWNER_USER}" ] || [ "${file_group}" != "${OWNER_GROUP}" ]; then49 if [ "${file_user}" != "${OWNER_USER}" ] || [ "${file_group}" != "${OWNER_GROUP}" ]; then
40 chmod 664 "${SNAP_DATA}/${FILE}" && chown "${OWNER_USER}:${OWNER_GROUP}" "${SNAP_DATA}/${FILE}"50 chown "${OWNER_USER}:${OWNER_GROUP}" "${SNAP_DATA}/${FILE}"
51 fi
52 # Ensure permissions are correct
53 if [ "${file_mode}" != '664' ]; then
54 ${DROP_PRIVS} chmod 664 "${SNAP_DATA}/${FILE}"
41 fi55 fi
4256
43done57done
@@ -46,8 +60,6 @@ ulimit -n 65536
46. "${SNAP_DATA}"/daemon_arguments60. "${SNAP_DATA}"/daemon_arguments
4761
48COMMAND="${SNAP}/bin/prometheus ${ARGS} --config.file ${SNAP_DATA}/prometheus.yml --storage.tsdb.path=${SNAP_COMMON}/tsdb"62COMMAND="${SNAP}/bin/prometheus ${ARGS} --config.file ${SNAP_DATA}/prometheus.yml --storage.tsdb.path=${SNAP_COMMON}/tsdb"
49# Drop privileges with setpriv and run as snap_daemon63
50# https://snapcraft.io/docs/system-usernames
51DROP_PRIVS="${SNAP}/usr/bin/setpriv --clear-groups --reuid snap_daemon --regid snap_daemon --"
5264
53exec ${DROP_PRIVS} ${COMMAND}65exec ${DROP_PRIVS} ${COMMAND}
54\ No newline at end of file66\ No newline at end of file

Subscribers

People subscribed via source and target branches