Skip to content

Commit f701210

Browse files
authored
Add pot group to protect pot root (#240)
* Remove mkdir when ZFS create the directory This was introduced in b2fb5d7 and wasn't a good approach after all. Left in the mkdir function in common.sh and used it in places where mkdir was also necessary beforehand. * Add pot group and require it to access /opt/pot This is the correct fix to #218, as discussed in #233 (comment) Fixes #218
1 parent 38e7654 commit f701210

File tree

14 files changed

+63
-173
lines changed

14 files changed

+63
-173
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
echo pass >>/etc/pf.conf
7070
service pf enable
7171
service pf start
72+
pw groupadd pot
7273
bin/pot init
7374
#
7475
### Run CI tests ################################################

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- flavours: scripts are made executable when loading
1414
- destroy: remove status file when destroying
1515
- vnet: use unique epaira interface names (#232)
16+
- Add pot group to protect pot root (#240)
1617

1718
### Fixed
1819
- Reverted the change of permissions of pot root mountpoint to fix a regression (#233)

etc/pot/pot.conf.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# This is where pot is going to store temporary files
1414
# POT_TMP=/tmp
1515

16+
# This is the group owning POT_FS_ROOT
17+
# POT_GROUP=pot
18+
1619
# This is the suffix added to temporary files created using mktemp,
1720
# X is a placeholder for a random character, see mktemp(1)
1821
# POT_MKTEMP_SUFFIX=.XXXXXXXX

etc/pot/pot.default.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ POT_CACHE=/var/cache/pot
1313
# This is where pot is going to store temporary files
1414
POT_TMP=/tmp
1515

16+
# This is the group owning POT_FS_ROOT
17+
POT_GROUP=pot
18+
1619
# This is the suffix added to temporary files created using mktemp,
1720
# X is a placeholder for a random character, see mktemp(1)
1821
POT_MKTEMP_SUFFIX=.XXXXXXXX

share/pot/clone.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ _cj_zfs()
9999
fi
100100
_debug "clone $_dset@$_snap into $_jdset/m"
101101
zfs clone -o mountpoint="$_pdir/m" "$_dset@$_snap" "$_jdset/m"
102-
_fix_pot_mountpoint_permissions "$_pdir/m"
103102
touch "$_pdir/conf/fscomp.conf"
104103
while read -r line ; do
105104
_dset=$( echo "$line" | awk '{print $1}' )

share/pot/common.sh

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ _conf_check()
171171
_qerror "$1" "POT_FS_ROOT is mandatory"
172172
return 1 # false
173173
fi
174+
if ! getent group "${POT_GROUP:-pot}" >/dev/null 2>&1; then
175+
_qerror "$1" "Group '${POT_GROUP:-pot}' is missing, create it or change POT_GROUP"
176+
return 1 # false
177+
fi
174178
return 0 # true
175179
}
176180

@@ -238,6 +242,16 @@ _zfs_exist()
238242
return 0 # true
239243
}
240244

245+
# check if the dataset $1 is mounted
246+
# $1 the dataset NAME
247+
_zfs_mounted()
248+
{
249+
if [ "$(zfs get -Ho value mounted "$1")" != "yes" ]; then
250+
return 1; # false
251+
fi
252+
return 0 # true
253+
}
254+
241255
# given a dataset, look for the corresponding mountpoint
242256
# $1 the dataset
243257
_get_zfs_mountpoint()
@@ -938,22 +952,6 @@ _get_pot_snaps()
938952
done
939953
}
940954

941-
# $1 mountpoint to adjust permissions for
942-
_fix_pot_mountpoint_permissions()
943-
{
944-
local _mp _exp_perm
945-
_mp="$1"
946-
_exp_perm="755"
947-
948-
if [ "$(stat -f "%Lp" "${_mp}")" != "$_exp_perm" ]; then
949-
_debug "Setting mountpoint permission for $_mp"
950-
# chomd 755 allows everyone inside the jail to access the file system
951-
# permissions like 700 don't allow access to the file system to any non-user also in the jail
952-
# causing issue to applications like nginx
953-
chmod "$_exp_perm" "$_mp" || ${EXIT} 1
954-
fi
955-
}
956-
957955
# $1 mountpoint to create (proper permissions are applied)
958956
_create_pot_mountpoint()
959957
{
@@ -964,8 +962,6 @@ _create_pot_mountpoint()
964962
_debug "Creating mountpoint $_mp"
965963
mkdir -p "$_mp" || exit 1
966964
fi
967-
968-
_fix_pot_mountpoint_permissions "$_mp"
969965
}
970966

971967
# $1 pot name
@@ -1097,8 +1093,20 @@ pot-cmd()
10971093
shift
10981094
if [ ! -r "${_POT_INCLUDE}/${_cmd}.sh" ]; then
10991095
_error "Fatal error! $_cmd implementation not found!"
1100-
exit 1
1096+
${EXIT} 1
11011097
fi
1098+
1099+
if [ "$_cmd" != "init" ]&& [ "$_cmd" != "de-init" ] ; then
1100+
if [ ! -d "$POT_FS_ROOT" ]; then
1101+
_error "$POT_FS_ROOT does not exist, please run 'pot init'"
1102+
${EXIT} 1
1103+
fi
1104+
if [ ! -r "$POT_FS_ROOT" ]; then
1105+
_error "Current user has no read access to $POT_FS_ROOT"
1106+
${EXIT} 1
1107+
fi
1108+
fi
1109+
11021110
# shellcheck disable=SC1090
11031111
. "${_POT_INCLUDE}/${_cmd}.sh"
11041112
_func=pot-${_cmd}

share/pot/create.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ _c_zfs_single()
7979
_info "$_pdset exists already"
8080
fi
8181

82-
_create_pot_mountpoint "$_pdir/m"
83-
8482
if [ -z "$_potbase" ]; then
8583
# create an empty dataset
8684
if ! zfs create "$_pdset/m" ; then

share/pot/init.sh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ init-help()
1818

1919
pot-init()
2020
{
21-
local pf_file
21+
local pf_file dataset
2222
pf_file="$(sysrc -n pf_rules)"
2323
OPTIND=1
2424
while getopts "hvf:" _o ; do
@@ -42,6 +42,11 @@ pot-init()
4242
${EXIT} 1
4343
fi
4444

45+
if ! _conf_check "init" ; then
46+
_qerror "init" "Configuration not valid, please verify it"
47+
return 1 # false
48+
fi
49+
4550
if ! _zfs_exist "${POT_ZFS_ROOT}" "${POT_FS_ROOT}" ; then
4651
if _zfs_dataset_valid "${POT_ZFS_ROOT}" ; then
4752
_error "${POT_ZFS_ROOT} is an invalid POT root"
@@ -63,19 +68,21 @@ pot-init()
6368
fi
6469
fi
6570

71+
# set root directory permissions and ownership
72+
chmod 750 "${POT_FS_ROOT}" || ${EXIT} 1
73+
chown root:"${POT_GROUP:-pot}" "${POT_FS_ROOT}" || ${EXIT} 1
74+
6675
# create mandatory datasets
67-
if ! _zfs_dataset_valid "${POT_ZFS_ROOT}/bases" ; then
68-
_debug "creating ${POT_ZFS_ROOT}/bases"
69-
zfs create "${POT_ZFS_ROOT}/bases"
70-
fi
71-
if ! _zfs_dataset_valid "${POT_ZFS_ROOT}/jails" ; then
72-
_debug "creating ${POT_ZFS_ROOT}/jails"
73-
zfs create "${POT_ZFS_ROOT}/jails"
74-
fi
75-
if ! _zfs_dataset_valid "${POT_ZFS_ROOT}/fscomp" ; then
76-
_debug "creating ${POT_ZFS_ROOT}/fscomp"
77-
zfs create "${POT_ZFS_ROOT}/fscomp"
78-
fi
76+
for dataset in bases jails fscomp; do
77+
if ! _zfs_dataset_valid "${POT_ZFS_ROOT}/$dataset" ; then
78+
_debug "creating ${POT_ZFS_ROOT}/$dataset"
79+
zfs create "${POT_ZFS_ROOT}/$dataset" || ${EXIT} 1
80+
fi
81+
if ! _zfs_mounted "${POT_ZFS_ROOT}/$dataset"; then
82+
_debug "mounting ${POT_ZFS_ROOT}/$dataset"
83+
zfs mount "${POT_ZFS_ROOT}/$dataset" || ${EXIT} 1
84+
fi
85+
done
7986
if ! _zfs_exist "${POT_ZFS_ROOT}/cache" "${POT_CACHE}" ; then
8087
_debug "creating ${POT_ZFS_ROOT}/cache mounted as ${POT_CACHE}"
8188
if ! _zfs_dataset_valid "${POT_ZFS_ROOT}/cache" ; then

share/pot/mount-in.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ _mountpoint_validation()
6464
fi
6565
# if the mountpoint doesn't exist, make it
6666
if [ ! -d "$_mpdir/$_mnt_p" ]; then
67-
_create_pot_mountpoint "$_mpdir"
6867
if ! mkdir -p "$_mpdir/$_mnt_p" ; then
6968
if eval $_mounted ; then
7069
_pot_umount "$_pname" >/dev/null

share/pot/rename.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ _rn_zfs()
6767
zfs rename "$_dset" "$_nset"
6868

6969
#sudo zfs mount zroot/pot/jails/dns2
70-
_create_pot_mountpoint "${POT_FS_ROOT}/jails/$_newname/m"
7170
_debug "Mount $_nset"
7271
zfs mount "$_nset"
7372
#sudo zfs mount zroot/pot/jails/dns2/custom
@@ -88,7 +87,6 @@ _rn_zfs()
8887
fi
8988
_debug "Renaming $_dset in $_nset"
9089
zfs rename "$_dset" "$_nset"
91-
_create_pot_mountpoint "${POT_FS_ROOT}/jails/$_newname/m"
9290
_debug "Mount $_nset"
9391
zfs mount "$_nset"
9492
if _zfs_dataset_valid "$_nset/m" ; then

0 commit comments

Comments
 (0)