Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount: allow [ro|rw|rq|sw|xx] as available mount options #802

Merged
merged 19 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/chapters/subcommands/mount.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Syntax follows standard `/etc/fstab` format:

Usage: bastille mount TARGET HOST_PATH JAIL_PATH [filesystem_type options dump pass_number]

The 'options' string can include a comma-separated list of mount options, but must start with 'ro' or 'rw'.
The 'options' string can include a comma-separated list of mount options, but must include one of (rw,ro,rq,sw,xx) according to fstab documentation.

Example: Mount a tmpfs filesystem with options.
.. code-block:: shell
Expand Down
29 changes: 19 additions & 10 deletions usr/local/share/bastille/mount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@
. /usr/local/etc/bastille/bastille.conf

usage() {
error_exit "Usage: bastille mount TARGET HOST_PATH JAIL_PATH [filesystem_type options dump pass_number]"
error_exit "Usage: bastille mount [option(s)] TARGET HOST_PATH JAIL_PATH [filesystem_type options dump pass_number]"
}

# Handle special-case commands first.
case "${1}" in
help|-h|--help)
usage
;;
esac
# Handle options.
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
--*|-*)
error_notify "Unknown Option."
usage
;;
*)
break
;;
esac
done

if [ "$#" -lt 3 ] || [ "$#" -gt 7 ]; then
usage
Expand Down Expand Up @@ -91,8 +100,8 @@ elif [ ! -e "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then
usage
fi

# Mount permissions,options need to start with "ro" or "rw"
if ! echo "${_perms}" | grep -Eq 'r[w|o](,.*)?$'; then
# Mount permissions,options must include one of "ro, rw, rq, sw, xx"
if ! echo "${_perms}" | grep -Eq '(ro|rw|rq|sw|xx)(,.*)?$'; then
error_notify "Detected invalid mount permissions in FSTAB."
warn "Format: /host/path /jail/path nullfs ro 0 0"
warn "Read: ${_fstab}"
Expand All @@ -117,7 +126,7 @@ for _jail in ${JAILS}; do

# Check if mount point has already been added
_existing_mount="$(echo ${_fullpath_fstab} 2>/dev/null | sed 's#\\#\\\\#g')"
if grep -Eq "[[:blank:]]${_existing_mount}.*[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"; then
if grep -Eq "[[:blank:]]${_existing_mount}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"; then
warn "Mountpoint already present in ${bastille_jailsdir}/${_jail}/fstab"
grep -E "[[:blank:]]${_existing_mount}" "${bastille_jailsdir}/${_jail}/fstab"
continue
Expand Down