mirror of
https://github.com/YunoHost-Apps/cinny_ynh.git
synced 2024-09-03 18:16:13 +02:00
Properly manage folder/file permissions
This commit is contained in:
parent
611e69cd71
commit
6deb6f1f14
3 changed files with 68 additions and 41 deletions
|
@ -113,6 +113,14 @@ ynh_script_progression --message="Installing dependencies..." --time --weight=1
|
||||||
|
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
||||||
|
|
||||||
|
# Create a system user
|
||||||
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A MYSQL DATABASE
|
# CREATE A MYSQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -145,6 +153,17 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir="$final_path"
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
|
|
||||||
|
# FIXME: this should be managed by the core in the future
|
||||||
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
||||||
|
# such that the appropriate users (e.g. maybe www-data) can access
|
||||||
|
# files in some cases.
|
||||||
|
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
|
||||||
|
# this will be treated as a security issue.
|
||||||
|
chmod 750 "$final_path"
|
||||||
|
chmod -R o-rwx "$final_path"
|
||||||
|
chown -R root: "$final_path"
|
||||||
|
chown root:$app "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -155,14 +174,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --time --weig
|
||||||
# Create a dedicated NGINX config
|
# Create a dedicated NGINX config
|
||||||
ynh_add_nginx_config
|
ynh_add_nginx_config
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CREATE DEDICATED USER
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
|
||||||
|
|
||||||
# Create a system user
|
|
||||||
ynh_system_user_create --username=$app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PHP-FPM CONFIGURATION
|
# PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -246,6 +257,12 @@ ynh_permission_update --permission="main" --remove="visitors"
|
||||||
|
|
||||||
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
|
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
|
||||||
|
|
||||||
|
# FIXME: this should be handled by the core in the future
|
||||||
|
# You may need to use chmod 600 instead of 400,
|
||||||
|
# for example if the app is expected to be able to modify its own config
|
||||||
|
chmod 400
|
||||||
|
chown $app:$app "$final_path/some_config_file"
|
||||||
|
|
||||||
### For more complex cases where you want to replace stuff using regexes,
|
### For more complex cases where you want to replace stuff using regexes,
|
||||||
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
|
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
|
||||||
### When doing so, you also need to manually call ynh_store_file_checksum
|
### When doing so, you also need to manually call ynh_store_file_checksum
|
||||||
|
@ -255,17 +272,6 @@ ynh_add_config --template="some_config_file" --destination="$final_path/some_con
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
|
||||||
# SECURE FILES AND DIRECTORIES
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
### For security reason, any app should set the permissions to root: before anything else.
|
|
||||||
### Then, if write authorization is needed, any access should be given only to directories
|
|
||||||
### that really need such authorization.
|
|
||||||
|
|
||||||
# Set permissions to app files
|
|
||||||
chown -R root: $final_path
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -53,6 +53,14 @@ test ! -d $final_path \
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RECREATE THE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
|
||||||
|
|
||||||
|
# Create the dedicated user (if not existing)
|
||||||
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE APP MAIN DIR
|
# RESTORE THE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -60,20 +68,16 @@ ynh_script_progression --message="Restoring the app main directory..." --time --
|
||||||
|
|
||||||
ynh_restore_file --origin_path="$final_path"
|
ynh_restore_file --origin_path="$final_path"
|
||||||
|
|
||||||
#=================================================
|
# FIXME: this should be managed by the core in the future
|
||||||
# RECREATE THE DEDICATED USER
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
||||||
#=================================================
|
# such that the appropriate users (e.g. maybe www-data) can access
|
||||||
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
|
# files in some cases.
|
||||||
|
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
|
||||||
# Create the dedicated user (if not existing)
|
# this will be treated as a security issue.
|
||||||
ynh_system_user_create --username=$app
|
chmod 750 "$final_path"
|
||||||
|
chmod -R o-rwx "$final_path"
|
||||||
#=================================================
|
chown -R root: "$final_path"
|
||||||
# RESTORE USER RIGHTS
|
chown root:$app "$final_path"
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Restore permissions on app files
|
|
||||||
chown -R root: $final_path
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE PHP-FPM CONFIGURATION
|
# RESTORE THE PHP-FPM CONFIGURATION
|
||||||
|
|
|
@ -101,6 +101,14 @@ ynh_script_progression --message="Stopping a systemd service..." --time --weight
|
||||||
|
|
||||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
|
||||||
|
|
||||||
|
# Create a dedicated user (if not existing)
|
||||||
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -113,6 +121,17 @@ then
|
||||||
ynh_setup_source --dest_dir="$final_path"
|
ynh_setup_source --dest_dir="$final_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# FIXME: this should be managed by the core in the future
|
||||||
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
||||||
|
# such that the appropriate users (e.g. maybe www-data) can access
|
||||||
|
# files in some cases.
|
||||||
|
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
|
||||||
|
# this will be treated as a security issue.
|
||||||
|
chmod 750 "$final_path"
|
||||||
|
chmod -R o-rwx "$final_path"
|
||||||
|
chown -R root: "$final_path"
|
||||||
|
chown root:$app "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -128,14 +147,6 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
||||||
|
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CREATE DEDICATED USER
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
|
|
||||||
|
|
||||||
# Create a dedicated user (if not existing)
|
|
||||||
ynh_system_user_create --username=$app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PHP-FPM CONFIGURATION
|
# PHP-FPM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -169,6 +180,12 @@ ynh_add_systemd_config
|
||||||
|
|
||||||
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
|
ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
|
||||||
|
|
||||||
|
# FIXME: this should be handled by the core in the future
|
||||||
|
# You may need to use chmod 600 instead of 400,
|
||||||
|
# for example if the app is expected to be able to modify its own config
|
||||||
|
chmod 400
|
||||||
|
chown $app:$app "$final_path/some_config_file"
|
||||||
|
|
||||||
### For more complex cases where you want to replace stuff using regexes,
|
### For more complex cases where you want to replace stuff using regexes,
|
||||||
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
|
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
|
||||||
### When doing so, you also need to manually call ynh_store_file_checksum
|
### When doing so, you also need to manually call ynh_store_file_checksum
|
||||||
|
|
Loading…
Reference in a new issue