Chrooted SFTP access also for suEXEC (mod_fcgid) sites
create_vhost.sh: - suEXEC (mod_fcgid) sites get the same chrooted SFTP setup as static suEXEC sites: web base directory root:root 755, DocumentRoot owned by suEXEC user/group, SFTP group membership, sshd and chroot path checks. - SFTP group: use $SFTP_CHROOT_GROUP if it exists, otherwise 'sftpusers' (if exists). If neither exists, skip that step (group is no longer created). fix_sftp_site_permissions.sh: - Also handle active '*.suexec' vhosts. PHP files (*.php, *.phtml, *.php5) are not touched there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76f0fe1a7a
commit
fec60403d1
3 files changed
+117
-47
No files matched your search
@@ -1,9 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# ----------
|
||||
# - Repair permissions of static websites with chrooted SFTP access
|
||||
# - (vhost type "static site with suEXEC (chrooted SFTP access)", vhost
|
||||
# - configuration files '*.static-suexec', see create_vhost.sh).
|
||||
# - Repair permissions of suEXEC websites with chrooted SFTP access
|
||||
# - (see create_vhost.sh):
|
||||
# -
|
||||
# - - vhost type "static site with suEXEC (chrooted SFTP access)",
|
||||
# - vhost configuration files '*.static-suexec'
|
||||
# - - vhost type "suEXEC (using mod_fcgid)",
|
||||
# - vhost configuration files '*.suexec'
|
||||
# -
|
||||
# - The webserver user is member of the suEXEC group of each such site. So
|
||||
# - apache can deliver every file of the suEXEC user, as long as the file
|
||||
@@ -16,6 +20,11 @@
|
||||
# - files : owned by suEXEC user --> group <suexec group>, g+r
|
||||
# - directories: owned by suEXEC user --> group <suexec group>, u+rx,g+rx
|
||||
# -
|
||||
# - '*.suexec' sites: PHP files ('*.php', '*.phtml', '*.php5') are NOT
|
||||
# - touched. They are executed as the suEXEC user (mod_fcgid), apache doesn't
|
||||
# - need to read them. So restrictive permissions (i.e. 600 for config files
|
||||
# - with passwords) stay.
|
||||
# -
|
||||
# - Security note:
|
||||
# - All changes inside the DocumentRoot are done AS THE SUEXEC USER (runuser),
|
||||
# - never as root. So a user cannot trick this script (i.e. by replacing a
|
||||
@@ -36,7 +45,11 @@ script_dir="$(dirname $(realpath $0))"
|
||||
log_file="$(mktemp)"
|
||||
lock_file="/run/lock/${script_name%.sh}.lock"
|
||||
|
||||
vhost_extension="static-suexec"
|
||||
# - vhost configuration extensions to handle
|
||||
# -
|
||||
# - Note: '*.static-suexec' does NOT match '*.suexec' (no dot before 'suexec').
|
||||
# -
|
||||
vhost_extensions="static-suexec suexec"
|
||||
|
||||
declare -a site_conf_arr
|
||||
|
||||
@@ -57,8 +70,14 @@ usage() {
|
||||
\033[1mDescription\033[m
|
||||
|
||||
Repairs group ownership and group permissions inside the DocumentRoot of
|
||||
all active vhosts of type '*.${vhost_extension}' (static site with suEXEC,
|
||||
chrooted SFTP access), so apache can deliver all files of the suEXEC user.
|
||||
all active vhosts of type
|
||||
|
||||
'*.static-suexec' (static site with suEXEC, chrooted SFTP access)
|
||||
'*.suexec' (suEXEC using mod_fcgid, chrooted SFTP access)
|
||||
|
||||
so apache can deliver all files of the suEXEC user. On '*.suexec' sites
|
||||
PHP files ('*.php', '*.phtml', '*.php5') are not touched (executed as the
|
||||
suEXEC user).
|
||||
|
||||
Only files/directories owned by the suEXEC user are touched. Changes are
|
||||
done as the suEXEC user, not as root.
|
||||
@@ -290,16 +309,20 @@ fi
|
||||
[[ -d "$_vhost_base_dir" ]] || fatal "VHost directory '${_vhost_base_dir}' not found."
|
||||
|
||||
|
||||
# - Collect active vhost configurations of type '*.static-suexec'
|
||||
# - Collect active vhost configurations of type '*.static-suexec' / '*.suexec'
|
||||
# -
|
||||
# - Active means: a symlink '<site>.conf' (as created by create_vhost.sh)
|
||||
# - points to '<site>.conf.static-suexec'.
|
||||
# - points to '<site>.conf.static-suexec' or '<site>.conf.suexec'.
|
||||
# -
|
||||
# - Ignore subdirectory 'DELETED' and hidden files.
|
||||
# -
|
||||
while IFS='' read -r -d '' _link ; do
|
||||
_target="$(realpath -e "$_link" 2> /dev/null)" || continue
|
||||
[[ "$_target" = *.${vhost_extension} ]] || continue
|
||||
_match=false
|
||||
for _ext in $vhost_extensions ; do
|
||||
[[ "$_target" = *.${_ext} ]] && _match=true && break
|
||||
done
|
||||
$_match || continue
|
||||
[[ -f "$_target" ]] || continue
|
||||
containsElement=false
|
||||
for _conf in "${site_conf_arr[@]}" ; do
|
||||
@@ -313,7 +336,7 @@ done < <(
|
||||
# - No such sites is not an error - just nothing to do
|
||||
# -
|
||||
if [[ ${#site_conf_arr[@]} -eq 0 ]] ; then
|
||||
info "No active '*.${vhost_extension}' vhosts found in '${_vhost_base_dir}' - nothing to do."
|
||||
info "No active '*.static-suexec' / '*.suexec' vhosts found in '${_vhost_base_dir}' - nothing to do."
|
||||
clean_up 0
|
||||
fi
|
||||
|
||||
@@ -324,7 +347,7 @@ if $terminal ; then
|
||||
echo ""
|
||||
echo " Apache VHost directory.............: $_vhost_base_dir"
|
||||
echo " Webserver user.....................: ${web_user:-unknown}"
|
||||
echo " Number of sites (*.${vhost_extension}).: ${#site_conf_arr[@]}"
|
||||
echo " Number of sites (*.[static-]suexec): ${#site_conf_arr[@]}"
|
||||
echo " Dry-run............................: $dry_run"
|
||||
echo " Verbose............................: $verbose"
|
||||
echo ""
|
||||
@@ -346,7 +369,19 @@ declare -i _total_errors=0
|
||||
for _conf in "${site_conf_arr[@]}" ; do
|
||||
|
||||
_site="$(basename "$_conf")"
|
||||
_site="${_site%.conf.${vhost_extension}}"
|
||||
|
||||
# - Type of site. Check 'static-suexec' first ('*.suexec' doesn't match
|
||||
# - it anyway, but be explicit).
|
||||
# -
|
||||
# - '*.suexec' sites: don't touch PHP files (see head of script)
|
||||
# -
|
||||
if [[ "$_site" = *.conf.static-suexec ]] ; then
|
||||
_site="${_site%.conf.static-suexec}"
|
||||
_exclude_args=()
|
||||
else
|
||||
_site="${_site%.conf.suexec}"
|
||||
_exclude_args=( ! -name '*.php' ! -name '*.phtml' ! -name '*.php5' )
|
||||
fi
|
||||
|
||||
echononl " Site \033[1m${_site}\033[m"
|
||||
|
||||
@@ -419,7 +454,7 @@ for _conf in "${site_conf_arr[@]}" ; do
|
||||
runuser -u "$_user" -- find "$_doc_root" -xdev -user "$_user" -type d \
|
||||
\( ! -group "$_group" -o ! -perm -g=rx -o ! -perm -u=rx \) -print \
|
||||
> "$_list_dirs" 2> "$log_file" || _failed=true
|
||||
runuser -u "$_user" -- find "$_doc_root" -xdev -user "$_user" -type f \
|
||||
runuser -u "$_user" -- find "$_doc_root" -xdev -user "$_user" -type f "${_exclude_args[@]}" \
|
||||
\( ! -group "$_group" -o ! -perm -g=r \) -print \
|
||||
> "$_list_files" 2>> "$log_file" || _failed=true
|
||||
else
|
||||
@@ -427,7 +462,7 @@ for _conf in "${site_conf_arr[@]}" ; do
|
||||
\( ! -group "$_group" -o ! -perm -g=rx -o ! -perm -u=rx \) -print \
|
||||
-exec chgrp "$_group" {} \; -exec chmod u+rx,g+rx {} \; \
|
||||
> "$_list_dirs" 2> "$log_file" || _failed=true
|
||||
runuser -u "$_user" -- find "$_doc_root" -xdev -user "$_user" -type f \
|
||||
runuser -u "$_user" -- find "$_doc_root" -xdev -user "$_user" -type f "${_exclude_args[@]}" \
|
||||
\( ! -group "$_group" -o ! -perm -g=r \) -print \
|
||||
-exec chgrp "$_group" {} + -exec chmod g+r {} + \
|
||||
> "$_list_files" 2>> "$log_file" || _failed=true
|
||||
|
||||
Reference in new issue
Block a user