I set up a git repo to backup n8n workflows and credentials via a bash script which exports via npx n8n export
and pushes the data to the repo. The script is started via crontab.
Now a while ago it was running perfectly, no issues. Then suddenly (I assume after package update or Cloudron update) it stopped. Git is not pushing anymore due to an repo ownership issue:
fatal: detected dubious ownership in repository at '/app/data/n8n-backup'
To add an exception for this directory, call:
git config --global --add safe.directory /app/data/n8n-backup
This is the directory content inkl. rights:
root@package:/app/data/n8n-backup# ll
total 28
drwxr-xr-x 5 cloudron cloudron 4096 Jul 7 06:00 ./
drwxr-xr-x 7 cloudron cloudron 4096 Jul 5 16:57 ../
drwxr-xr-x 8 cloudron cloudron 4096 Jul 6 20:47 .git/
-rw-r--r-- 1 cloudron cloudron 562 Jun 14 13:58 README.md
drwxr-xr-x 2 root root 4096 Jul 7 06:00 credentials/
-rwxr-xr-x 1 cloudron cloudron 710 Jun 14 13:58 start-backup.sh*
drwxr-xr-x 2 root root 4096 Jul 7 06:00 workflows/
The script start-backup.sh
is started by the crontab, setup via the app cron settings in Cloudron UI. So its run as root. Also the git command is then called as root. Since the ownership of .git/
is cloudron
git is having doubts and stops.
Now if I change the ownership of all content in /app/data/n8n-backup/
to root
, then start the script, all works fine. But after an update of the app the ownership is reset to cloudron
. Makes sense from security perspective I guess.
Following the suggested git solution (adding the repository directory to the safe list) I am facing the problem that I can not write in the file system:
root@package:/app/code# git config --global --add safe.directory /app/data/n8n-backup
error: could not lock config file /root/.gitconfig: Read-only file system
Now adding the setting to the local config of the repository and switching back to cloudron
ownership is not working either since git is not recognizing the git repository. Also if I run as user cloudron
no success:
root@package:/app/data/n8n-backup# runuser -l cloudron -c 'git status'
fatal: not a git repository (or any of the parent directories): .git
The su
command helps with the git issue but does not work completely since then the npx
command is not found.
Now I could probably add chown -R root:root /app/data/n8n-backup/
as first command to the script but I guess that is not the best way to go.
Anyone some ideas to help me solving this?