1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/my_webapp_ynh.git synced 2024-09-03 19:46:26 +02:00

Merge pull request #64 from YunoHost-Apps/testing

Testing: Use sftp.app group from 4.2 to manage sftp access, + fix permissions
This commit is contained in:
Alexandre Aubin 2021-05-10 17:43:12 +02:00 committed by GitHub
commit a56a7ba378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 111 deletions

View file

@ -6,12 +6,12 @@
*[Lire ce readme en français.](./README_fr.md)* *[Lire ce readme en français.](./README_fr.md)*
> *This package allow you to install Custom Webapp quickly and simply on a YunoHost server. > *This package allow you to install Custom Webapp quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* If you don't have YunoHost, please see [here](https://yunohost.org/install) to know how to install and enjoy it.*
## Overview ## Overview
This application allows you to easily install a custom Web application, This application allows you to easily install a custom Web application,
providing files access with [SFTP](https://yunohost.org/#/filezilla). It can also create a MySQL database - providing files access with [SFTP](https://yunohost.org/en/filezilla). It can also create a MySQL database -
which will be backed up and restored with your application. The connection which will be backed up and restored with your application. The connection
details will be stored in the file `db_accesss.txt` located in the root details will be stored in the file `db_accesss.txt` located in the root
directory. directory.
@ -28,7 +28,7 @@ of your custom Web application inside.
## Documentation ## Documentation
* YunoHost documentation: https://github.com/YunoHost/doc/blob/master/app_my_webapp.md * YunoHost documentation: https://yunohost.org/en/app_my_webapp
## YunoHost specific features ## YunoHost specific features
@ -45,8 +45,8 @@ of your custom Web application inside.
#### SFTP port #### SFTP port
You may have change the SSH port as described You may have change the SSH port as described in this section:
[here section "Modifier le port SSH"](https://yunohost.org/#/security_fr) ; [Modify the SSH port](https://yunohost.org/en/security#modify-the-ssh-port);
then you should use this port to update your website with SFTP. then you should use this port to update your website with SFTP.
## Links ## Links

View file

@ -6,12 +6,12 @@
*[Read this readme in english.](./README.md)* *[Read this readme in english.](./README.md)*
> *Ce package vous permet d'installer une Application vide avec accès SFTP au répertoire Web personnalisé rapidement et simplement sur un serveur YunoHost. > *Ce package vous permet d'installer une Application vide avec accès SFTP au répertoire Web personnalisé rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/install) pour savoir comment l'installer et en profiter.*
## Vue d'ensemble ## Vue d'ensemble
Cette application vous permet d'installer facilement une application vide personnalisée, Cette application vous permet d'installer facilement une application vide personnalisée,
fourni un accès aux fichiers avec [SFTP](https://yunohost.org/#/filezilla). Elle peut également créer une base de données MySQL - fourni un accès aux fichiers avec [SFTP](https://yunohost.org/fr/filezilla). Elle peut également créer une base de données MySQL -
qui sera sauvegardée et restaurée avec votre application. Les détails de connexion qui sera sauvegardée et restaurée avec votre application. Les détails de connexion
seront stockés dans le fichier `db_accesss.txt` situé dans le répertoire racine. seront stockés dans le fichier `db_accesss.txt` situé dans le répertoire racine.
@ -21,7 +21,7 @@ seront stockés dans le fichier `db_accesss.txt` situé dans le répertoire raci
## Documentation ## Documentation
* Documentation YunoHost : https://yunohost.org/#/app_my_webapp * Documentation YunoHost : https://yunohost.org/fr/app_my_webapp
## Caractéristiques spécifiques YunoHost ## Caractéristiques spécifiques YunoHost
@ -36,6 +36,12 @@ seront stockés dans le fichier `db_accesss.txt` situé dans le répertoire raci
## Informations additionnelles ## Informations additionnelles
#### Port SFTP
Vous avez peut-être changé le port SSH comme décrit dans cette section :
[Modifier le port SSH](https://yunohost.org/fr/security#modify-the-ssh-port) ;
alors vous devriez utiliser ce port pour mettre à jour votre site Web avec SFTP.
## Liens ## Liens
* Signaler un bug : https://github.com/YunoHost-Apps/my_webapp_ynh/issues * Signaler un bug : https://github.com/YunoHost-Apps/my_webapp_ynh/issues

View file

@ -1,21 +0,0 @@
#!/bin/bash
action=$1
pending_dir=$4
ssh_conf=$pending_dir/../ssh/etc/ssh/sshd_config
[[ $action == "pre" ]] || exit 0
[[ -e $ssh_conf ]] || exit 0
echo "
##-> __APP__
# Hardening user connection
Match User __APP__
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
PermitTunnel no
X11Forwarding no
PasswordAuthentication yes
##<- __APP__" >> $ssh_conf

View file

@ -6,7 +6,7 @@
"en": "Custom Web app with SFTP access", "en": "Custom Web app with SFTP access",
"fr": "Application Web personnalisée avec accès SFTP" "fr": "Application Web personnalisée avec accès SFTP"
}, },
"version": "1.0~ynh4", "version": "1.0~ynh5",
"url": "https://github.com/YunoHost-Apps/my_webapp_ynh", "url": "https://github.com/YunoHost-Apps/my_webapp_ynh",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"maintainer": { "maintainer": {
@ -18,7 +18,7 @@
"email": "maniackc_dev@crudelis.fr" "email": "maniackc_dev@crudelis.fr"
}], }],
"requirements": { "requirements": {
"yunohost": ">= 4.1.7" "yunohost": ">= 4.2.3"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [

View file

@ -63,17 +63,6 @@ then
ynh_mysql_dump_db --database="$db_name" > db.sql ynh_mysql_dump_db --database="$db_name" > db.sql
fi fi
#=================================================
# BACKUP SPECIFIC FILES
#=================================================
if [ $with_sftp -eq 1 ]
then
ynh_print_info --message="Backup specific files..."
ynh_backup "/usr/share/yunohost/hooks/conf_regen/90-ssh_$app"
fi
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -85,7 +85,14 @@ ynh_add_nginx_config
#================================================= #=================================================
ynh_script_progression --message="Configuring system user..." ynh_script_progression --message="Configuring system user..."
ynh_system_user_create --username=$app --home_dir="$final_path" if [ $with_sftp -eq 1 ]
then
groups="sftp.app"
else
groups=""
fi
ynh_system_user_create --username=$app --home_dir="$final_path" --groups="$groups"
if [ $with_sftp -eq 1 ] if [ $with_sftp -eq 1 ]
then then
@ -96,18 +103,6 @@ fi
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#=================================================
# CONFIGURE SSH
#=================================================
if [ $with_sftp -eq 1 ]
then
ynh_script_progression --message="Configuring SSH..."
ynh_add_config --template="../conf/ssh_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/90-ssh_$app"
yunohost tools regen-conf ssh
fi
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
@ -133,6 +128,14 @@ name: ${db_name}\nuser: ${db_name}\npass: ${db_pwd}" > ../sources/db_access.txt
cp -r "../sources/db_access.txt" "$final_path/db_access.txt" cp -r "../sources/db_access.txt" "$final_path/db_access.txt"
fi fi
chown -R $app:www-data "$final_path"
# Home directory of the user needs to be owned by root to allow
# SFTP connections
chown root:root "$final_path"
setfacl -m g:$app:r-x "$final_path"
setfacl -m g:www-data:r-x "$final_path"
chmod o-rwx "$final_path"
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
@ -144,15 +147,6 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R $app: "$final_path"
# Home directory of the user needs to be owned by root to allow
# SFTP connections
chown root: "$final_path"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================

View file

@ -64,15 +64,6 @@ ynh_remove_fpm_config
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
#================================================= #=================================================
# REMOVE THE CUSTOM SSH CONFIG
#=================================================
if [ $with_sftp -eq 1 ]
then
ynh_script_progression --message="Removing the custom SSH config..."
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/90-ssh_$app"
yunohost tools regen-conf ssh
fi
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -50,13 +50,6 @@ 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"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RESTORE THE MYSQL DATABASE
#================================================= #=================================================
@ -74,7 +67,14 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2 ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
ynh_system_user_create --username=$app --home_dir="$final_path" if [ $with_sftp -eq 1 ]
then
groups="sftp.app"
else
groups=""
fi
ynh_system_user_create --username=$app --home_dir="$final_path" --groups="$groups"
if [ -n "$password" ] if [ -n "$password" ]
then then
@ -83,14 +83,20 @@ then
fi fi
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path"
# Restore permissions on app files # Restore permissions on app files
chown -R $app: "$final_path" chown -R $app:www-data "$final_path"
# Home directory of the user need to be owned by root to allow # Home directory of the user needs to be owned by root to allow
# SFTP connections # SFTP connections
chown root: "$final_path" chown root:root "$final_path"
setfacl -m g:$app:r-x "$final_path"
setfacl -m g:www-data:r-x "$final_path"
chmod o-rwx "$final_path"
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION
@ -101,17 +107,6 @@ ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#================================================= #=================================================
# CONFIGURE SSH
#=================================================
if [ $with_sftp -eq 1 ]
then
ynh_script_progression --message="Configuring SSH..."
ynh_restore_file "/usr/share/yunohost/hooks/conf_regen/90-ssh_$app"
yunohost tools regen-conf ssh
fi
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -145,9 +145,16 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2 ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2
ynh_system_user_create --username=$app --home_dir="$final_path"
if [ $with_sftp -eq 1 ] if [ $with_sftp -eq 1 ]
then
groups="sftp.app"
else
groups=""
fi
ynh_system_user_create --username=$app --home_dir="$final_path" --groups="$groups"
if [ -n "$password" ]
then then
# Add the password to this user # Add the password to this user
chpasswd <<< "${app}:${password}" chpasswd <<< "${app}:${password}"
@ -173,17 +180,6 @@ fi
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# CONFIGURE SSH
#=================================================
if [ $with_sftp -eq 1 ]
then
ynh_script_progression --message="Configuring SSH..." --weight=1
ynh_add_config --template="../conf/ssh_regenconf_hook" --destination="/usr/share/yunohost/hooks/conf_regen/90-ssh_$app"
yunohost tools regen-conf ssh
fi
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -191,10 +187,13 @@ fi
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
chown -R $app: "$final_path" chown -R $app:www-data "$final_path"
# Home directory of the user needs to be owned by root to allow # Home directory of the user needs to be owned by root to allow
# SFTP connections # SFTP connections
chown root: "$final_path" chown root:root "$final_path"
setfacl -m g:$app:r-x "$final_path"
setfacl -m g:www-data:r-x "$final_path"
chmod o-rwx "$final_path"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX