Skip to content

Commit 50610d9

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 9f05272 commit 50610d9

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
@@ -255,6 +255,44 @@ function canonical_port() {
255255
echo "$PORT"
256256
}
257257

258+
function set_path_permissions() {
259+
local -r READABLE_USERS=($1)
260+
local -r WRITEABLE_USERS=($2)
261+
local -r PATHS=("${@:3}")
262+
263+
case "$PERMISSION_MODE" in
264+
facl)
265+
setfacl -R $(printf '-m user:%s:rwX ' "${WRITEABLE_USERS[@]}") \
266+
$(printf '-m default:user:%s:rwX ' "${WRITEABLE_USERS[@]}") \
267+
$(printf '-m user:%s:rX ' "${READABLE_USERS[@]}") \
268+
$(printf '-m default:user:%s:rX ' "${READABLE_USERS[@]}") \
269+
"${PATHS[@]}"
270+
chmod -R ug+rw,o-rwx "${PATHS[@]}"
271+
;;
272+
stickybit)
273+
GROUP="$(printf '%s' "${WRITEABLE_USERS[@]}")"
274+
275+
if ! getent group "$GROUP" >/dev/null; then
276+
groupadd "$GROUP"
277+
fi
278+
279+
for USER in "${WRITEABLE_USERS[@]}"; do
280+
usermod -a -G "$GROUP" "$USER"
281+
done
282+
283+
chgrp -R "$GROUP" "${PATHS[@]}"
284+
find "${PATHS[@]}" -type d -exec chmod g+ws \;
285+
find "${PATHS[@]}" -type f -exec chmod g+w \;
286+
;;
287+
chmod)
288+
chmod -R a+rw "${PATHS[@]}"
289+
;;
290+
*)
291+
echo "unsupported permission mode '$PERMISSION_MODE'" >&2
292+
;;
293+
esac
294+
}
295+
258296
function wait_for_remote_ports() (
259297
set +x
260298

0 commit comments

Comments
 (0)