Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 3bb7845

Browse files
committed
Improve vendor permissions fix
Vendor has executable file so let's only remove permissions for other users and fix ownership. See README for more info.
1 parent a796544 commit 3bb7845

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,23 @@ folders.
8383
If there are content folders outside the Drupal root folder you can use the
8484
`--files-path` option and the script will take care of it.
8585

86+
## Vendor folder
87+
8688
If a `vendor` folder and a `composer.json` file are detected in the parent
8789
folder of the Drupal root the script assumes the `vendor` folder is a code
88-
folder and fixes permissions accordingly.
90+
folder and fixes permissions accordingly: it fixes ownership (owner: deploy
91+
user, group: web server) and removes any permissions for other users.
92+
93+
It doesn't apply standard permissions of code files because in `vendor` folders
94+
there are some files that needs to be executable. It would be hard to detect all
95+
the cases that needs executable permissions so the script doesn't handle
96+
permissions for the owner or the group and just removes all permissions for
97+
other users.
98+
99+
In case of issues in the `vendor` folder, because the the script fixes ownership
100+
on the `vendor` folder, the deploy user should able to run `composer
101+
install` and let composer set the correct permissions. Later, the script can be
102+
run again to remove all permissions on other users.
89103

90104
## Performance
91105

drupal_fix_permissions.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,20 @@ function fix_code_permission_helper() {
196196
case $simulate in
197197
0)
198198
# Real action.
199-
find "$1" $detected_vendor_path \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print0 \) | xargs -r -0 -L4 chmod $3
199+
find "$1" \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print0 \) | xargs -r -0 -L4 chmod $3
200200
;;
201201

202202
1)
203203
# Simulate.
204-
num=$(find "$1" $detected_vendor_path \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \) | wc -l)
204+
num=$(find "$1" \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \) | wc -l)
205205
printf "\n Code items with wrong permissions: $num"
206206
;;
207207

208208
2)
209209
# Simulate verbosely.
210210
printf "\n Code files and directories that would have their permissions fixed: "
211211
# Use a variable to indent output.
212-
items=$(find "$1" $detected_vendor_path \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \))
212+
items=$(find "$1" \( -path "$1"/sites/*/$file_folder_name -prune \) -o \( -path "$1"/sites/*/$private_folder_name -prune \) -o \( -type $2 ! -perm $3 -print \))
213213
items=${items:-None}
214214
printf "\n ${items//$'\n'/$'\n' }\n"
215215
;;
@@ -268,6 +268,16 @@ function fix_code_permissions() {
268268
printf "\n Setting permissions on code files to $code_file_perms under '$name'"
269269
fix_code_permission_helper "$1" f "$code_file_perms"
270270

271+
272+
if [ ! -z "$detected_vendor_path" ]
273+
then
274+
printf "\n Setting permissions on vendor code directories to $code_dir_perms under '$detected_vendor_path'"
275+
fix_code_permission_helper "$detected_vendor_path" d "$code_dir_perms"
276+
277+
printf "\n Removing all permissions on vendor code files to other users ($vendor_code_file_perms) under '$detected_vendor_path'"
278+
fix_code_permission_helper "$detected_vendor_path" f "$vendor_code_file_perms"
279+
fi
280+
271281
}
272282

273283

@@ -368,6 +378,7 @@ fi
368378
# content files).
369379
code_dir_perms='u=rwx,g=rx,o='
370380
code_file_perms='u=rw,g=r,o='
381+
vendor_code_file_perms='o='
371382
content_dir_perms="u=rwx,g=rw${group_executable_mode},o="
372383
content_file_perms='ug=rw,o='
373384

0 commit comments

Comments
 (0)