nextcloud / docker

⛴ Docker image of Nextcloud
https://hub.docker.com/_/nextcloud/
GNU Affero General Public License v3.0
6k stars 1.82k forks source link

Postgres autoconfig does not work #1506

Closed giomf closed 3 months ago

giomf commented 3 years ago

I have discovered an error in the autoconfig via environment variables. I want to connect a postgres database and create an admin on first start.

I use the environment variables as specified in the documentation and I can confirm that they are correctly passed into the containers. All are transferred correctly except POSTGRES_USER and POSTGRES_PASSWORD. When I look at config.php the fields dbuser and dbpassword are incorrect.

dbuser is set as oc_{NEXTCLOUD_ADMIN_USER}. dbpassword seems to be generated.

I use the 20 fpm version. But i also had no success with the 21. or with the 19 version. If I use MYSQL as database everything works as expected.

Rob-Meijeren commented 3 years ago

Had the same issue with the stable image. By downgrading to 20.0.9 I got it initializing on startup again. But obviously this should be fixed in the image.

giomf commented 3 years ago

I find it strange that no one else is commenting on this. Doesn't anyone use postgres? Especially because the error stretches over several releases.

Rob-Meijeren commented 3 years ago

maybe they think well someone already pointed it out it will be fixed soon? 🤷‍♂️ I just wanted the maintainers to know I also found this happening on the apache version and its not a fpm only thing. (and to bring a bit more attention to this)

Alukardz commented 3 years ago

Same Issue, I spent almost an hour trying to fix it, thinking I messed up the build.

JuniorJPDJ commented 3 years ago

welp, nextcloud is very good at not fixing issues like this for a long time :)

giomf commented 3 years ago

I know and this is really annoying.

Alukardz commented 3 years ago

Nevermind, my error was that I downloaded the nextcloud zip from the Main site and after unpacking it, I had docker-compose share the volume, but even if the versions match, it seems for autoconfig to work, it needs to download the nextcloud code itself, so the volume should have no folder on the host.

john-TC commented 3 years ago

I have the same issue. My docker-compose.yml:

version: '3.9'

services:
  postgres:
    image: postgres:13.4-alpine
    volumes: 
      - postgres:/var/lib/postgresql/data
    environment: 
      - POSTGRES_USER=postgres
        POSTGRES_PASSWORD=postgres
        POSTGRES_DB=nextcloud

  nextcloud:
    image: nextcloud:22.1.0-apache
    ports: 
      - 80:80
    volumes: 
      - nextcloud:/var/www/html
    environment: 
      - NEXTCLOUD_ADMIN_USER=admin
        NEXTCLOUD_ADMIN_PASSWORD=admin
        POSTGRES_DB=nextcloud
        POSTGRES_USER=postgres
        POSTGRES_PASSWORD=postgres
        POSTGRES_HOST=postgres

volumes: 
  nextcloud:
  postgres:
shadow00 commented 3 years ago

Same issue but worse on 22.1.0-fpm. I deployed it a few days ago, and it seemed to work fine at first. After a restart yesterday, all I get is 500 Server Error because the database authentication keeps failing.

This is what I get every time I try to load the site:

ncloud-app | 10.0.6.4 -  28/Aug/2021:21:39:21 +0000 "GET /index.php" 500
ncloud-nginx | 10.0.6.1 - - [28/Aug/2021:21:39:22 +0000] "GET / HTTP/1.1" 500 301 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0" "-"
ncloud-nginx | 10.0.6.1 - - [28/Aug/2021:21:39:22 +0000] "GET /favicon.ico HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0" "-"
ncloud-db | 2021-08-28 21:39:22.158 UTC [46] FATAL:  password authentication failed for user "oc_{admin user}"
ncloud-db | 2021-08-28 21:39:22.158 UTC [46] DETAIL:  Role "oc_{admin user}" does not exist.
ncloud-db |     Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-28 21:39:22.162 UTC [47] FATAL:  password authentication failed for user "oc_{admin user}"
ncloud-db | 2021-08-28 21:39:22.162 UTC [47] DETAIL:  Role "oc_{admin user}" does not exist.
ncloud-db |     Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-28 21:39:22.167 UTC [48] FATAL:  password authentication failed for user "oc_{admin user}"
ncloud-db | 2021-08-28 21:39:22.167 UTC [48] DETAIL:  Role "oc_{admin user}" does not exist.
ncloud-db |     Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-28 21:39:22.171 UTC [49] FATAL:  password authentication failed for user "oc_{admin user}"
ncloud-db | 2021-08-28 21:39:22.171 UTC [49] DETAIL:  Role "oc_{admin user}" does not exist.
ncloud-db |     Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-28 21:39:22.176 UTC [50] FATAL:  password authentication failed for user "oc_{admin user}"
ncloud-db | 2021-08-28 21:39:22.176 UTC [50] DETAIL:  Role "oc_{admin user}" does not exist.
ncloud-db |     Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"

Note that oc_{admin user} is NOT the same username that shows up in the actual database!

nextcloud=# SELECT * FROM pg_user;
  usename  | usesysid | usecreatedb | usesuper | userepl | usebypassrls |  passwd  | valuntil | useconfig
-----------+----------+-------------+----------+---------+--------------+----------+----------+-----------
 nextcloud |       10 | t           | t        | t       | t            | ******** |          |
(1 row)

Could this be related to #1360 ?

Edit: after changing 'dbuser' => 'nextcloud' in my config.php I still get:

ncloud-app | 10.0.6.4 -  29/Aug/2021:09:53:09 +0000 "GET /index.php" 500
ncloud-nginx | 10.0.6.1 - - [29/Aug/2021:09:53:09 +0000] "GET / HTTP/1.1" 500 301 "-" "curl/7.68.0" "-"
ncloud-db | 2021-08-29 09:57:03.337 UTC [45] FATAL:  password authentication failed for user "nextcloud"
ncloud-db | 2021-08-29 09:57:03.337 UTC [45] DETAIL:  Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-29 09:57:03.341 UTC [46] FATAL:  password authentication failed for user "nextcloud"
ncloud-db | 2021-08-29 09:57:03.341 UTC [46] DETAIL:  Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-29 09:57:03.345 UTC [47] FATAL:  password authentication failed for user "nextcloud"
ncloud-db | 2021-08-29 09:57:03.345 UTC [47] DETAIL:  Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-29 09:57:03.352 UTC [48] FATAL:  password authentication failed for user "nextcloud"
ncloud-db | 2021-08-29 09:57:03.352 UTC [48] DETAIL:  Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
ncloud-db | 2021-08-29 09:57:03.355 UTC [49] FATAL:  password authentication failed for user "nextcloud"
ncloud-db | 2021-08-29 09:57:03.355 UTC [49] DETAIL:  Connection matched pg_hba.conf line 99: "host all all all scram-sha-256"
sogajeffrey commented 2 years ago

Its November now and the latest image is still not fixed. Still getting a randomly generated psql password and username.

miko007 commented 2 years ago

i usually use mySQL to run nextcloud, but just recently i had to migrate an existing installation on bare metal using postgres to docker. this issue cost me two days of my life.

the docker image is basically useless when one tries to use postgres as a backend. as this looks like a simple issue with some invironment variables to me, i am amazed there has not been any progress on this since may.

is it possible for @tilosp or another maintainer to at least reply here, so we know we are not hanging in the ropes?

mpptx commented 2 years ago

Today I've launched Nextcloud on my Kubernetes cluster and after scaling down and up this issue showed up. The only thing that helps is to delete all of the instance's files and set it up again, which is really painful and annoying.

Please please please, do something with this issue, it really drivers me crazy as I was running the same instance for YEARS, when it was named OwnCloud.

TheTerrasque commented 2 years ago

I just tried setting up nextcloud today, and bumped into the same exact problem. Latest NextCloud docker image

Edit: I think I've found the specifics for this to happen. If nextcloud is given a global user, it will create a database-specific user too. It will then try to use that to set up nextcloud.

In my case it's a pgpool in front of my postgres server, which has it's own authentication layer. Since that new user is not added there, it can't connect with the new user and fails.

Edit2: https://github.com/nextcloud/server/blob/7acb438e428e5b0b3a79c2b7ce5a4283b0e805eb/lib/private/Setup/PostgreSQL.php#L64 has the logic. If the user given have rolcreaterole set to true in pg_roles, then a new user is created.

phagez commented 9 months ago

Still here in early 2024 with version 28....

sleibrock commented 7 months ago

Running into this as well. Would've liked to use Postgres, but MariaDB will have to do for now.

joshtrichards commented 3 months ago

I use the environment variables as specified in the documentation and I can confirm that they are correctly passed into the containers. All are transferred correctly except POSTGRES_USER and POSTGRES_PASSWORD. When I look at config.php the fields dbuser and dbpassword are incorrect.

dbuser is set as oc_{NEXTCLOUD_ADMIN_USER}. dbpassword seems to be generated.

This is upstream's documented behavior. POSTGRES_USER and POSTGRESPASSWORD are passed by the image to Nextcloud's Installer which uses it to create the `oc*` account you're seeing.

https://docs.nextcloud.com/server/latest/admin_manual/installation/installation_wizard.html#database-choice

If there is a problem with this behavior or some inconsistency, it needs to be taken up there: https://github.com/nextcloud/server

The Docker image itself is functioning as expected: if those variables weren't getting passed off to the Installer, the oc_* account would never even be created.