Skip to content

Commit 029af5b

Browse files
andytson-inviqakierenevans
authored andcommitted
A possible alternative abstraction for permissions
Assumes for facl/stickybit that all users are umask 0002 It doesn't have the performance improvements of #332 yet, though I'm unsure if that's possible with setfacl
1 parent 4c00aaa commit 029af5b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ubuntu/16.04/usr/local/share/bootstrap/common_functions.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,44 @@ function canonical_port() {
237237
echo "$PORT"
238238
}
239239

240+
function set_path_permissions() {
241+
local -r READABLE_USERS=($1)
242+
local -r WRITEABLE_USERS=($2)
243+
local -r PATHS=("${@:3}")
244+
245+
case "$PERMISSION_MODE" in
246+
facl)
247+
setfacl -R $(printf '-m user:%s:rwX ' "${WRITEABLE_USERS[@]}") \
248+
$(printf '-m default:user:%s:rwX ' "${WRITEABLE_USERS[@]}") \
249+
$(printf '-m user:%s:rX ' "${READABLE_USERS[@]}") \
250+
$(printf '-m default:user:%s:rX ' "${READABLE_USERS[@]}") \
251+
"${PATHS[@]}"
252+
chmod -R ug+rw,o-rwx "${PATHS[@]}"
253+
;;
254+
stickybit)
255+
GROUP="$(printf '%s' "${WRITEABLE_USERS[@]}")"
256+
257+
if ! getent group "$GROUP" >/dev/null; then
258+
groupadd "$GROUP"
259+
fi
260+
261+
for USER in "${WRITEABLE_USERS[@]}"; do
262+
usermod -a -G "$GROUP" "$USER"
263+
done
264+
265+
chgrp -R "$GROUP" "${PATHS[@]}"
266+
find "${PATHS[@]}" -type d -exec chmod g+ws \;
267+
find "${PATHS[@]}" -type f -exec chmod g+w \;
268+
;;
269+
chmod)
270+
chmod -R a+rw "${PATHS[@]}"
271+
;;
272+
*)
273+
echo "unsupported permission mode '$PERMISSION_MODE'" >&2
274+
;;
275+
esac
276+
}
277+
240278
function wait_for_remote_ports() (
241279
set +x
242280

0 commit comments

Comments
 (0)