Compare commits

..

1 Commits

Author SHA1 Message Date
e8a8f636d0 add headers to embed nextcloud in frame on external site
This introduces new env variables to configure nextloud to be embedded via
iframe on an external site.
Setting X_FRAME_OPTIONS_ENABLED=1 will configure nginx and nextcloud to
set X-Frame-Options and CSP headers to allow the domain configured in
X_FRAME_OPTIONS_ALLOW_FROM.
2022-08-31 15:40:18 +02:00
11 changed files with 108 additions and 206 deletions

View File

@ -11,22 +11,14 @@ steps:
purge: true purge: true
deploy_key: deploy_key:
from_secret: drone_ssh_swarm_test from_secret: drone_ssh_swarm_test
networks:
- proxy
environment: environment:
DOMAIN: nextcloud.swarm-test.autonomic.zone DOMAIN: nextcloud.swarm-test.autonomic.zone
STACK_NAME: nextcloud STACK_NAME: nextcloud
LETS_ENCRYPT_ENV: production LETS_ENCRYPT_ENV: production
ADMIN_USER: foobar ADMIN_USER: foobar
FPM_TUNE_VERSION: v1
NGINX_CONF_VERSION: v1
MY_CNF_VERSION: v1
ENTRYPOINT_VERSION: v1
SECRET_DB_PASSWORD_VERSION: v1 SECRET_DB_PASSWORD_VERSION: v1
SECRET_DB_ROOT_PASSWORD_VERSION: v1 SECRET_DB_ROOT_PASSWORD_VERSION: v1
SECRET_ADMIN_PASSWORD_VERSION: v1 SECRET_ADMIN_PASSWORD_VERSION: v1
SECRET_ONLYOFFICE_JWT_VERSION: v1
SECRET_BBB_SECRET_VERSION: v1
EXTRA_VOLUME: "/dev/null:/tmp/.dummy" EXTRA_VOLUME: "/dev/null:/tmp/.dummy"
trigger: trigger:
branch: branch:

View File

@ -17,37 +17,5 @@ SECRET_ADMIN_PASSWORD_VERSION=v1
EXTRA_VOLUME=/dev/null:/tmp/.dummy EXTRA_VOLUME=/dev/null:/tmp/.dummy
# fpm-tune, see: https://spot13.com/pmcalculator/
FPM_MAX_CHILDREN=131
FPM_START_SERVERS=32
FPM_MIN_SPARE_SERVERS=32
FPM_MAX_SPARE_SERVERS=98
DEFAULT_QUOTA="10 GB"
# X_FRAME_OPTIONS_ENABLED=1 # X_FRAME_OPTIONS_ENABLED=1
# X_FRAME_OPTIONS_ALLOW_FROM=embedding-site.example.org # X_FRAME_OPTIONS_ALLOW_FROM=embedding-site.example.org
# COMPOSE_FILE="$COMPOSE_FILE:compose.smtp.yml"
# See https://github.com/nextcloud/docker#auto-configuration-via-environment-variables for default values
# SMTP_AUTHTYPE=
# SMTP_HOST=
# SMTP_SECURE=
# SMTP_NAME=
# SMTP_PORT=
# MAIL_FROM_ADDRESS=
# MAIL_DOMAIN=
# SECRET_SMTP_PASSWORD_VERSION=v1
# COMPOSE_FILE="$COMPOSE_FILE:compose.apps.yml"
# APPS="calendar sociallogin onlyoffice"
#
# ONLYOFFICE_URL=https://onlyoffice.example.com
# SECRET_ONLYOFFICE_JWT_VERSION=v1
#
# BBB_URL=https://talk.example.org/bigbluebutton/ # trailing slash!
# SECRET_BBB_SECRET_VERSION=v1
#
# OCC_CMDS="app:disable dashboard"
# OCC_CMDS="$OCC_CMDS|config:app:set sociallogin auto_create_groups --value 1"
# OCC_CMDS="$OCC_CMDS|config:app:set sociallogin hide_default_login --value 1"

130
abra.sh
View File

@ -1,54 +1,106 @@
#!/bin/bash export FPM_TUNE_VERSION=v4
export NGINX_CONF_VERSION=v3
export FPM_TUNE_VERSION=v5
export NGINX_CONF_VERSION=v4
export MY_CNF_VERSION=v4 export MY_CNF_VERSION=v4
export ENTRYPOINT_VERSION=v3 export ENTRYPOINT_VERSION=v1
run_occ(){ NC_APP_DIR="app:/var/www/html"
su -p www-data -s /bin/sh -c "/var/www/html/occ $@"
sub_occ(){
# shellcheck disable=SC2034
abra__service_="app"
# shellcheck disable=SC2034
abra___user="www-data"
sub_app_run php /var/www/html/occ "$@"
} }
post_install_occ(){ _backup_app() {
IFS='|' read -ra CMD <<< "$OCC_CMDS" # Copied _abra_backup_dir to make UX better on restore and backup
for cmd in "${CMD[@]}"; do {
run_occ "$cmd" abra__src_="$1"
done abra__dst_="-"
}
# shellcheck disable=SC2154
FILENAME="$(basename "$1").tar"
debug "Copying '$1' to '$FILENAME'"
silence
mkdir -p /tmp/abra
sub_app_cp > /tmp/abra/$FILENAME
unsilence
} }
install_apps(){ next_maintenance_on() {
install_apps="$@" silence
if [ -z "$install_apps" ] sub_occ maintenance:mode --on > /dev/null
then unsilence
install_apps=$APPS debug "Nextcloud maintenance mode enabled"
fi
for app in $install_apps
do
run_occ "app:install $app"
done
} }
set_app_config(){ next_maintenance_off() {
APP=$1 silence
KEY=$2 sub_occ maintenance:mode --off > /dev/null
VALUE=$3 unsilence
run_occ "config:app:set $APP $KEY --value $VALUE" debug "Nextcloud maintenance mode disabled"
} }
install_bbb(){ abra_backup_app() {
install_apps bbb # shellcheck disable=SC2154
set_app_config bbb app.navigation true ARK_FILENAME="$ABRA_BACKUP_DIR/${abra__app_}_app_$(date +%F).tar.gz"
set_app_config bbb api.url "$BBB_URL" # Cant be FILENAME as that gets changed by something
set_app_config bbb api.secret "$(cat /run/secrets/bbb_secret)" next_maintenance_on
_backup_app $NC_APP_DIR/config
_backup_app $NC_APP_DIR/data
_backup_app $NC_APP_DIR/themes
# Combine archives
tar -Af /tmp/abra/config.tar /tmp/abra/data.tar
tar -Af /tmp/abra/config.tar /tmp/abra/themes.tar
gzip /tmp/abra/config.tar -c > "$ARK_FILENAME"
rm /tmp/abra/*.tar
success "Backed up 'app' to $ARK_FILENAME"
next_maintenance_off
} }
install_onlyoffice(){ abra_backup_db() {
install_apps onlyoffice next_maintenance_on
set_app_config onlyoffice DocumentServerUrl "$ONLYOFFICE_URL" _abra_backup_mysql "db" "nextcloud"
set_app_config onlyoffice jwt_secret "$(cat /run/secrets/onlyoffice_jwt)" next_maintenance_off
set_app_config onlyoffice customizationForcesave true
} }
set_default_quota(){ abra_backup() {
set_app_config files default_quota '"$DEFAULT_QUOTA"' abra_backup_app && abra_backup_db
} }
abra_restore_app() {
next_maintenance_on
# shellcheck disable=SC2034
{
abra__src_="-"
abra__dst_=$NC_APP_DIR
}
zcat "$@" | sub_app_cp
next_maintenance_off
sub_occ files:scan --all > /dev/null # Needs to be run in normal mode
success "Restored 'app'"
}
# abra_restore_db() {
# warning "Restoring the database is on a existing app and not a new one has not been tested. Use with caution."
# next_maintenance_on
# # 3wc: unlike abra_backup_db, we can assume abra__service_ will be 'db' if we
# # got this far..
# # shellcheck disable=SC2034
# abra___no_tty="true"
# DB_PASSWORD=$(sub_app_run cat /run/secrets/db_password)
# zcat "$@" | sub_app_run mysql -u root -p"$DB_PASSWORD" wordpress
# success "Restored 'db'"
# next_maintenance_off
# }

View File

@ -1,18 +0,0 @@
version: "3.8"
services:
app:
secrets:
- onlyoffice_jwt
- bbb_secret
environment:
- APPS
- ONLYOFFICE_URL
- BBB_URL
secrets:
onlyoffice_jwt:
external: true
name: ${STACK_NAME}_onlyoffice_jwt_${SECRET_ONLYOFFICE_JWT_VERSION}
bbb_secret:
external: true
name: ${STACK_NAME}_bbb_secret_${SECRET_BBB_SECRET_VERSION}

View File

@ -2,6 +2,7 @@ version: '3.8'
services: services:
app: app:
entrypoint: "sh -c 'sleep 10 && /entrypoint.sh php-fpm'" # tries to mitigate this error with postgres https://github.com/nextcloud/docker/issues/1204
environment: environment:
- POSTGRES_HOST=db - POSTGRES_HOST=db
- POSTGRES_DB=nextcloud - POSTGRES_DB=nextcloud

View File

@ -1,19 +0,0 @@
version: "3.8"
services:
app:
secrets:
- smtp_password
environment:
- SMTP_AUTHTYPE
- SMTP_HOST
- SMTP_SECURE
- SMTP_NAME
- SMTP_PORT
- SMTP_PASSWORD_FILE=/run/secrets/smtp_password
- MAIL_FROM_ADDRESS
- MAIL_DOMAIN
secrets:
smtp_password:
external: true
name: ${STACK_NAME}_smtp_password_${SECRET_SMTP_PASSWORD_VERSION}

View File

@ -1,7 +1,7 @@
version: "3.8" version: "3.8"
services: services:
web: web:
image: nginx:1.23.2 image: nginx:1.23.1
configs: configs:
- source: nginx_conf - source: nginx_conf
target: /etc/nginx/nginx.conf target: /etc/nginx/nginx.conf
@ -35,7 +35,7 @@ services:
- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}" - "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}"
app: app:
image: nextcloud:25.0.1-fpm image: nextcloud:24.0.3-fpm
depends_on: depends_on:
- db - db
configs: configs:
@ -49,8 +49,6 @@ services:
- db_password - db_password
- admin_password - admin_password
environment: environment:
- APPS
- OCC_CMDS
- X_FRAME_OPTIONS_ALLOW_FROM - X_FRAME_OPTIONS_ALLOW_FROM
- X_FRAME_OPTIONS_ENABLED - X_FRAME_OPTIONS_ENABLED
- DOMAIN - DOMAIN
@ -60,13 +58,12 @@ services:
- NEXTCLOUD_TRUSTED_DOMAINS=${DOMAIN} - NEXTCLOUD_TRUSTED_DOMAINS=${DOMAIN}
- TRUSTED_PROXIES=traefik - TRUSTED_PROXIES=traefik
- REDIS_HOST=cache - REDIS_HOST=cache
- SMTP_HOST
- MAIL_FROM_ADDRESS
- MAIL_DOMAIN
- SMTP_AUTHTYPE=PLAIN
- OVERWRITEPROTOCOL=https - OVERWRITEPROTOCOL=https
- PHP_MEMORY_LIMIT=1G - PHP_MEMORY_LIMIT=1G
- FPM_MAX_CHILDREN=131
- FPM_START_SERVERS=32
- FPM_MIN_SPARE_SERVERS=32
- FPM_MAX_SPARE_SERVERS=98
- DEFAULT_QUOTA
volumes: volumes:
- nextcloud:/var/www/html/ - nextcloud:/var/www/html/
- nextapps:/var/www/html/custom_apps:cached - nextapps:/var/www/html/custom_apps:cached
@ -80,12 +77,12 @@ services:
failure_action: rollback failure_action: rollback
order: start-first order: start-first
labels: labels:
- "coop-cloud.${STACK_NAME}.version=3.0.1+25.0.1-fpm" - "coop-cloud.${STACK_NAME}.version=2.1.2+24.0.3-fpm"
- "backupbot.backup=true" - "backupbot.backup=true"
- "backupbot.backup.path=/var/www/html/config/,/var/www/html/data/,/var/www/html/custom_apps/" - "backupbot.backup.path=/var/www/html/config/,/var/www/html/data/,/var/www/html/custom_apps/"
cron: cron:
image: nextcloud:25.0.1-fpm image: nextcloud:24.0.3-fpm
volumes: volumes:
- nextcloud:/var/www/html/ - nextcloud:/var/www/html/
- nextapps:/var/www/html/custom_apps:cached - nextapps:/var/www/html/custom_apps:cached
@ -97,7 +94,7 @@ services:
entrypoint: /cron.sh entrypoint: /cron.sh
cache: cache:
image: redis:7.0.5-alpine image: redis:7.0.4-alpine
networks: networks:
- internal - internal
volumes: volumes:
@ -109,7 +106,7 @@ secrets:
name: ${STACK_NAME}_db_root_password_${SECRET_DB_ROOT_PASSWORD_VERSION} name: ${STACK_NAME}_db_root_password_${SECRET_DB_ROOT_PASSWORD_VERSION}
db_password: db_password:
external: true external: true
name: ${STACK_NAME}_db_password_${SECRET_DB_PASSWORD_VERSION} name: ${STACK_NAME}_db_password_${SECRET_DB_ROOT_PASSWORD_VERSION}
admin_password: admin_password:
external: true external: true
name: ${STACK_NAME}_admin_password_${SECRET_ADMIN_PASSWORD_VERSION} name: ${STACK_NAME}_admin_password_${SECRET_ADMIN_PASSWORD_VERSION}
@ -130,7 +127,6 @@ configs:
fpm_tune: fpm_tune:
name: ${STACK_NAME}_fpm_tune_${FPM_TUNE_VERSION} name: ${STACK_NAME}_fpm_tune_${FPM_TUNE_VERSION}
file: fpm-tune.ini file: fpm-tune.ini
template_driver: golang
entrypoint: entrypoint:
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION} name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
file: entrypoint.sh.tmpl file: entrypoint.sh.tmpl

View File

@ -1,39 +1,9 @@
#!/bin/bash #!/bin/bash
set -eu
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env "SMTP_PASSWORD"
echo "Giving the db container some time to come up"; sleep 20
# see this issue with postgres db https://github.com/nextcloud/docker/issues/1204
{{ if eq (env "X_FRAME_OPTIONS_ENABLED") "1" }} {{ if eq (env "X_FRAME_OPTIONS_ENABLED") "1" }}
if ! [[ $(grep {{ env "X_FRAME_OPTIONS_ALLOW_FROM" }} lib/public/AppFramework/Http/ContentSecurityPolicy.php) ]]; then if ! [[ $(grep {{ env "X_FRAME_OPTIONS_ALLOW_FROM" }} lib/public/AppFramework/Http/ContentSecurityPolicy.php) ]]; then
sed -i "91 a\\\t\t'{{ env "X_FRAME_OPTIONS_ALLOW_FROM" }}', " lib/public/AppFramework/Http/ContentSecurityPolicy.php sed -i "91 a\\\t\t'{{ env "X_FRAME_OPTIONS_ALLOW_FROM" }}', " lib/public/AppFramework/Http/ContentSecurityPolicy.php
fi fi
{{ end }} {{ end }}
/entrypoint.sh php-fpm /entrypoint.sh php-fpm

View File

@ -1,5 +1,5 @@
pm = dynamic pm = dynamic
pm.max_children = {{ env "FPM_MAX_CHILDREN" }} pm.max_children = 131
pm.start_servers = {{ env "FPM_START_SERVERS" }} pm.start_servers = 32
pm.min_spare_servers = {{ env "FPM_MIN_SPARE_SERVERS" }} pm.min_spare_servers = 32
pm.max_spare_servers = {{ env "FPM_MAX_SPARE_SERVERS" }} pm.max_spare_servers = 98

View File

@ -67,7 +67,8 @@ http {
add_header X-XSS-Protection "1; mode=block" always; add_header X-XSS-Protection "1; mode=block" always;
{{ if eq (env "X_FRAME_OPTIONS_ENABLED") "1" }} {{ if eq (env "X_FRAME_OPTIONS_ENABLED") "1" }}
add_header Content-Security-Policy "frame-ancestors {{ env "X_FRAME_OPTIONS_ALLOW_FROM" }} {{ env "DOMAIN" }}"; add_header X-Frame-Options "{{ env "X_FRAME_OPTIONS_ALLOW_FROM" }}" always;
add_header Content-Security-Policy "frame-ancestors {{ env "X_FRAME_OPTIONS_ALLOW_FROM" }}";
{{ else }} {{ else }}
add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Frame-Options "SAMEORIGIN" always;
{{ end }} {{ end }}

View File

@ -1,41 +0,0 @@
## FPM Tune
The fpm-tune.ini settings are now configurable by `.env`. Please add this to your servers configs:
```
# fpm-tune, see: https://spot13.com/pmcalculator/
FPM_MAX_CHILDREN=131
FPM_START_SERVERS=32
FPM_MIN_SPARE_SERVERS=32
FPM_MAX_SPARE_SERVERS=98
```
## SMTP
Add SMTP Config to your .env file:
```
# COMPOSE_FILE="$COMPOSE_FILE:compose.smtp.yml"
# See https://github.com/nextcloud/docker#auto-configuration-via-environment-variables for default values
# SMTP_AUTHTYPE=
# SMTP_HOST=
# SMTP_SECURE=
# SMTP_NAME=
# SMTP_PORT=
# MAIL_FROM_ADDRESS=
# MAIL_DOMAIN=
# SECRET_SMTP_PASSWORD_VERSION=v1
```
## Post Deploy Commands
Some Apps can also be managed with abra app cmd!
```
# COMPOSE_FILE="$COMPOSE_FILE:compose.apps.yml"
# APPS="calendar sociallogin onlyoffice"
# ONLYOFFICE_URL=https://onlyoffice.example.com
# BBB_URL=https://talk.example.org/bigbluebutton/ # trailing slash!
```