-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database.sqlite Permission denied #210
Comments
UPDATE: Problem is solved after doing the following:
getting the same error. Here is my
|
I have been experiencing the same problem. My solution was |
I'm using Portainer & I've just run into this problem as well. Who should be the owner of the folder that we map to? I have a separate user called
in my docker compose file's volume section, but I've just realised that there was no mention of those two environment variables. What user/group should own the folder that the volume maps to? @phoenix1184 how did you end up with database.sqlite (file), installed (file), storage (folder) in your 2fauth folder? Did they get created when you were somehow able to successfully start the container? Every time I try to start the container I get the same error message that you mentioned. If I manually create the file/folders that are indicated in the error messages, I still end up with a "permission denied" for the log file it's trying to create.
I wonder if this could be related to issue 192? |
Running into similar problems after making some config changes on my server. Are there environment variables for PUID and PGID? There really should be. I was able to work around it by doing a brute force chmod 700 and chown 1000 with the -R switch on my 2fauth appdata folder to fix it, just as a side note. |
No there is not. What would be the purpose ? Getting their values at run time? Setting them? |
The idea is such that it is not running as the godmode/root user, as the openmediavault guide suggests. It's a security best practice. |
The image runs as 1000:1000. But without env vars, this is hard coded in the Dockerfile. |
That should be able to be overidden by env variables. I'm installing this on a Synology NAS & there is no user or group whose id is Not all systems have 1000:1000. Would it be that difficult to allow them to be set by PIUD & GUID env variables? Unless you have 1000:1000 hard coded throughout your docker image it shouldn't cause any problems for your code. |
Please have a look at the Dockerfile. All commands are run as 1000:1000. Is this what you called "Unless you have 1000:1000 hard coded throughout your docker image..."? I'm not an advanced Docker user, the Docker stuff for 2FAuth is not my contribution, so I need to understand how it works. To me, using specific uid:gid in the Dockerfile only impacts the build. It gives an image which will run with these ids. The only way to change something at runtime is by applying some changes through the entrypoint file. Is that correct? |
I had a look at the docker file in the link you provided. I'm a developer with almost 40 years of software development experience, but my docker experience is limited to consuming docker images, I've never put one together myself. I've never needed to. First off yes, sort of, that's what I meant for the 1000:1000, but I also agree with your statement that being in the dockerfile they should only be applicable to the build process, not being relevant at runtime. The problem with doing it like that in the dockerfile is that it assumes that 1000:1000 is going to match any volumes that we add to persist data between restarts etc (like 1000:1000 is pretty common for Open Media Vault users (or there's another OS) and I see it mentioned in youtube tutorials, so for those consumers of your image it would "just work". Then there are other systems, like Synology, where those user/group ids just don't exist, and that's why some people are having the permissions problem. The permissions for commands to use or for mapped volumes should be set/overridden at runtime. I don't think I even have the option of creating a user/group with an id of 1000. As users are added you just end up with the next number after the last one AFAIK. From what I understand, many, if not most, docker images have some sort of user/group id env variable (I've seen PUID/PGID, PID/GID, USER_ID/GROUP_ID) through which the application can use those values so they match the permissions of the user running it. It doesn't matter what they're called, we just have to use whatever the creator of the image has decided to make available. I didn't manage to find a quick example to show you how those env variables are then used for the permissions at runtime (as you rightly assumed) but what then happens is the application can run code that uses the values that are provided to it by the consumer of the image instead of assuming anything, like the 1000:1000 set in the dockerfile. So whoever wrote the application code might be the person who would know what to do to override 1000:1000 at runtime. I find it a little unusual to have the puid/guid variables declared multiple times in the dockerfile. Usually you'd declare something like that at the beginning of the file. But there's nothing "wrong" about that per se, it's just unnecessary extra lines. It could be a style thing, or an experience thing, but it just seemed odd to me. I don't think I've been terribly helpful. But having said that I just did a quick search online because I wanted to understand it a bit more myself (even though I can't imagine a scenario where I'd need to create a docker image myself, but never say never). Here's a short explanation Understanding PUID and PGID. |
Thx @yannduran, this was really helpful. It's now clear to me why you expect UID/GID vars and thanks to more searches how this permissions issue is commonly addressed in the docker world. To all |
@Bubka I'm glad you found what I wrote helpful. However, we absolutely shouldn't need to have to build our own images. The 2 changes that I describe below can be implemented without any disruption to existing users, or even future users. The All folders/files etc INSIDE the container have nothing to do with the permissions used on the docker host, so apart from some questionable practices in the dockerfile itself, only ONE thing needs to be changed there. Then some modifications will need to be made in the application itself, to use the environment variable values instead of assuming I found that the
Change #1 (dockerfile): To enable the application to have the correct permissions to access our mapped folder, simply add the following lines between the ENV \ command and the APP_NAME definition:
So it would end up looking like this:
These Change #2 (application): The endpoint application needs to be changed to use these environment variable values to add/edit/update folders/files inside our mapped folder on the docker host. In the dockerfile the defaults get to
So if our I'm guessing that these env variables then get somehow magically passed through to the endpoint application. Recommendations: This is not required for fixing our issue, it's just a best practice recommendation. It will help in understanding/maintaining this dockerfile in the future.
I hope that some of this may be helpful. I haven't looked at the application code yet, but I'll see if I can determine what needs to be changed to use the newly added environment variables. The language is PHP, which I've never used. But I'm hoping to be able to follow it well enough to see what might need to be changed. A quick look (searching for chown 1000:1000 /yourpath/2fauth/database.sqlite
chmod 700 /yourpath/2fauth/database.sqlite
So instead of using Maybe you can discuss this with the author of the application code? They should be able to find any places where the folder is being accessed easier/quicker than I could. They should be familiar with using the environment variable values as there are quite a few env variables already provided by the container. |
I'm the author of 2FAuth. What I can't figure out is how I can have 2FAuth (so php code) to have permission over the Regarding your recommendations:
The Dockerfile uses multiple build stages (the |
This issue is not resolved for me. |
Hey
I trie to use docker rootless and docker compose.
With normal docker, everything works fine.
Since then I got error message when docker compose up:
2fauth | touch: /2fauth/database.sqlite: Permission denied
I've a folder $DOCKERDIR/APPDATA/2fauth. Inside is file database.sqlite (file), installed (file), storage (folder)
Here is my compose file:
2fauth:
image: 2fauth/2fauth
restart: always
networks:
- default
container_name: 2fauth
volumes:
- $DOCKERDIR/appdata/2fauth:/2fauth
- /etc/localtime:/etc/localtime:ro
ports:
- 8300:8000/tcp
environment:
- ASSET_URL=$fauth_URL
- TZ=$TZ
- APP_NAME=$fauth_APP_NAME
- APP_ENV=local
- APP_DEBUG=true
- SITE_OWNER=$fauth_SITE_OWNER
- APP_KEY=$fauth_APP_KEY
- APP_URL=$fauth_URL
- IS_DEMO_APP=false
- LOG_CHANNEL=daily
- LOG_LEVEL=debug
- DB_CONNECTION=sqlite
- DB_DATABASE="/srv/database/database.sqlite"
- CACHE_DRIVER=file
- SESSION_DRIVER=file
- MAIL_DRIVER=smtp
- MAIL_HOST=$fauth_MAIL_HOST
- MAIL_PORT=$fauth_MAIL_PORT
- MAIL_FROM=$fauth_SITE_OWNER
- MAIL_USERNAME=$fauth_SITE_OWNER
- MAIL_PASSWORD=$fauth_MAIL_PASSWORD
- MAIL_ENCRYPTION=tls
- MAIL_FROM_NAME=$fauth_MAIL_FROM_NAME
- MAIL_FROM_ADDRESS=$fauth_SITE_OWNER
- AUTHENTICATION_GUARD=web-guard
- AUTH_PROXY_HEADER_FOR_USER=null
- AUTH_PROXY_HEADER_FOR_EMAIL=null
- PROXY_LOGOUT_URL=null
# WebAuthn settings
- WEBAUTHN_NAME=$fauth_WEBAUTHN_NAME
- WEBAUTHN_ID=null
- WEBAUTHN_ICON=null
- WEBAUTHN_USER_VERIFICATION=preferred
- TRUSTED_PROXIES=$fauth_TRUSTED_PROXIES
- BROADCAST_DRIVER=log
- QUEUE_DRIVER=sync
- SESSION_LIFETIME=120
- REDIS_HOST=$fauth_REDIS_HOST
- REDIS_PASSWORD=$fauth_REDIS_PASSWORD
- REDIS_PORT=6379
- PUSHER_APP_ID=$fauth_PUSHER_APP_ID
- PUSHER_APP_KEY=$fauth_PUSHER_APP_KEY
- PUSHER_APP_SECRET=$fauth_PUSHER_APP_SECRET
- PUSHER_APP_CLUSTER=$fauth_PUSHER_APP_CLUSTER
- MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
- MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
- MIX_ENV=local
Any tips why it is not working?
database.sqlite is permission rwx
The text was updated successfully, but these errors were encountered: