pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

PGADMIN_CONFIG_CONFIG_DATABASE_URI from docker secrets

Open Mimikoo opened this issue 3 years ago • 5 comments

Hello.

There is PGADMIN_DEFAULT_PASSWORD_FILE which can be used to pass default password from docker secrets.

There is no way to pass default password for PGADMIN_CONFIG_CONFIG_DATABASE_URI from docker secrets. So the docker inspect shows the password for connecting to postgresql.

Is there an option to set DATABASE_URI from docket secrets and not use config_local.py ?

Mimikoo avatar Feb 16 '23 15:02 Mimikoo

Found a workaround, but is not good for regular use.

PGADMIN_CONFIG_CONFIG_DATABASE_URI: str(import('pathlib').Path("/run/secrets/pgadmin_config_config_database_uri").read_text())

Mimikoo avatar Feb 19 '23 19:02 Mimikoo

Hello i try to set PGADMIN_CONFIG_CONFIG_DATABASE_URI in Helm Release, ex :

env:
  - name: PGADMIN_CONFIG_CONFIG_DATABASE_URI
    value: postgresql://postgres:${password}@${name}-db-postgresql-hl.${namespace}:5432/postgres

But i have this error when PGadmin boot :/

SyntaxError: invalid syntax                                                                                                                                                                                                                  
postfix/postlog: starting the Postfix mail system                                                                                                                                                                                            
Traceback (most recent call last):                                                                                                                                                                                                           
  File "<string>", line 1, in <module>                                                                                                                                                                                                       
  File "/pgadmin4/config.py", line 906, in <module>                                                                                                                                                                                          
    from pgadmin.evaluate_config import evaluate_and_patch_config                                                                                                                                                                            
  File "/pgadmin4/pgadmin/evaluate_config.py", line 49, in <module>                                                                                                                                                                          
    import config_distro                                                                                                                                                                                                                     
  File "/pgadmin4/config_distro.py", line 12                                                                                                                                                                                                 
    CONFIG_DATABASE_URI = postgresql://postgres:[email protected]:5432/postgres

Have you idea how to fix this ? :/

m4dm4rtig4n avatar Nov 11 '23 01:11 m4dm4rtig4n

I tried setting the ENV variable to PGADMIN_CONFIG_CONFIG_DATABASE_URI which worked as far as connecting to the database, but it looks like it ignores the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD variables when doing this. The server fails to start:

NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin user account:

[2024-08-29 13:39:43 -0400] [98] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/venv/lib/python3.12/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
  worker.init_process()
File "/venv/lib/python3.12/site-packages/gunicorn/workers/gthread.py", line 95, in init_process
  super().init_process()
File "/venv/lib/python3.12/site-packages/gunicorn/workers/base.py", line 134, in init_process
  self.load_wsgi()
File "/venv/lib/python3.12/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
  self.wsgi = self.app.wsgi()
              ^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/app/base.py", line 67, in wsgi
  self.callable = self.load()
                  ^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
  return self.load_wsgiapp()
         ^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
  return util.import_app(self.app_uri)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/util.py", line 371, in import_app
  mod = importlib.import_module(module)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/pgadmin4/run_pgadmin.py", line 4, in <module>
  from pgAdmin4 import app
File "/pgadmin4/pgAdmin4.py", line 103, in <module>
  app = create_app()
        ^^^^^^^^^^^^
File "/pgadmin4/pgadmin/__init__.py", line 471, in create_app
  run_migration_for_others()
File "/pgadmin4/pgadmin/__init__.py", line 456, in run_migration_for_others
  db_upgrade(app)
File "/pgadmin4/pgadmin/setup/db_upgrade.py", line 25, in db_upgrade
  flask_migrate.upgrade(migration_folder)
File "/venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 111, in wrapped
  f(*args, **kwargs)
File "/venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 200, in upgrade
  command.upgrade(config, revision, sql=sql, tag=tag)
File "/venv/lib/python3.12/site-packages/alembic/command.py", line 406, in upgrade
  script.run_env()
File "/venv/lib/python3.12/site-packages/alembic/script/base.py", line 582, in run_env
  util.load_python_file(self.dir, "env.py")
File "/venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
  module = load_module_py(module_id, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
  spec.loader.exec_module(module)  # type: ignore
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/pgadmin4/pgadmin/setup/../../migrations/env.py", line 95, in <module>
  run_migrations_online()
File "/pgadmin4/pgadmin/setup/../../migrations/env.py", line 87, in run_migrations_online
  context.run_migrations()
File "<string>", line 8, in run_migrations
File "/venv/lib/python3.12/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
  self.get_context().run_migrations(**kw)
File "/venv/lib/python3.12/site-packages/alembic/runtime/migration.py", line 628, in run_migrations
  step.migration_fn(**kw)
File "/pgadmin4/migrations/versions/fdc58d9bd449_.py", line 38, in upgrade
  email, password = user_info()
                    ^^^^^^^^^^^
File "/pgadmin4/pgadmin/setup/user_info.py", line 75, in user_info
  email, p1 = user_info_server()
              ^^^^^^^^^^^^^^^^^^
File "/pgadmin4/pgadmin/setup/user_info.py", line 52, in user_info_server
  email = input(ENTER_EMAIL_ADDRESS)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
EOFError: EOF when reading a line

PaulChristophel avatar Aug 30 '24 13:08 PaulChristophel

I tried setting the ENV variable to PGADMIN_CONFIG_CONFIG_DATABASE_URI which worked as far as connecting to the database, but it looks like it ignores the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD variables when doing this. The server fails to start:

NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin user account:

[2024-08-29 13:39:43 -0400] [98] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/venv/lib/python3.12/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
  worker.init_process()
File "/venv/lib/python3.12/site-packages/gunicorn/workers/gthread.py", line 95, in init_process
  super().init_process()
File "/venv/lib/python3.12/site-packages/gunicorn/workers/base.py", line 134, in init_process
  self.load_wsgi()
File "/venv/lib/python3.12/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
  self.wsgi = self.app.wsgi()
              ^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/app/base.py", line 67, in wsgi
  self.callable = self.load()
                  ^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
  return self.load_wsgiapp()
         ^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
  return util.import_app(self.app_uri)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/gunicorn/util.py", line 371, in import_app
  mod = importlib.import_module(module)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/pgadmin4/run_pgadmin.py", line 4, in <module>
  from pgAdmin4 import app
File "/pgadmin4/pgAdmin4.py", line 103, in <module>
  app = create_app()
        ^^^^^^^^^^^^
File "/pgadmin4/pgadmin/__init__.py", line 471, in create_app
  run_migration_for_others()
File "/pgadmin4/pgadmin/__init__.py", line 456, in run_migration_for_others
  db_upgrade(app)
File "/pgadmin4/pgadmin/setup/db_upgrade.py", line 25, in db_upgrade
  flask_migrate.upgrade(migration_folder)
File "/venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 111, in wrapped
  f(*args, **kwargs)
File "/venv/lib/python3.12/site-packages/flask_migrate/__init__.py", line 200, in upgrade
  command.upgrade(config, revision, sql=sql, tag=tag)
File "/venv/lib/python3.12/site-packages/alembic/command.py", line 406, in upgrade
  script.run_env()
File "/venv/lib/python3.12/site-packages/alembic/script/base.py", line 582, in run_env
  util.load_python_file(self.dir, "env.py")
File "/venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
  module = load_module_py(module_id, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.12/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
  spec.loader.exec_module(module)  # type: ignore
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/pgadmin4/pgadmin/setup/../../migrations/env.py", line 95, in <module>
  run_migrations_online()
File "/pgadmin4/pgadmin/setup/../../migrations/env.py", line 87, in run_migrations_online
  context.run_migrations()
File "<string>", line 8, in run_migrations
File "/venv/lib/python3.12/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
  self.get_context().run_migrations(**kw)
File "/venv/lib/python3.12/site-packages/alembic/runtime/migration.py", line 628, in run_migrations
  step.migration_fn(**kw)
File "/pgadmin4/migrations/versions/fdc58d9bd449_.py", line 38, in upgrade
  email, password = user_info()
                    ^^^^^^^^^^^
File "/pgadmin4/pgadmin/setup/user_info.py", line 75, in user_info
  email, p1 = user_info_server()
              ^^^^^^^^^^^^^^^^^^
File "/pgadmin4/pgadmin/setup/user_info.py", line 52, in user_info_server
  email = input(ENTER_EMAIL_ADDRESS)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
EOFError: EOF when reading a line

Can you please share your docker-compose?

yogeshmahajan-1903 avatar Sep 12 '24 05:09 yogeshmahajan-1903

Can you please share your docker-compose?

I am using kubernetes, but this is the (scrubbed) deployment.

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "53"
    meta.helm.sh/release-name: pgadmin4
    meta.helm.sh/release-namespace: pgadmin4
  creationTimestamp: "2022-06-22T00:57:14Z"
  generation: 118
  labels:
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: pgadmin4
    app.kubernetes.io/version: "7"
    helm.sh/chart: pgadmin4-1.11.0
  name: pgadmin4
  namespace: pgadmin4
  resourceVersion: "609722366"
  selfLink: /apis/apps/v1/namespaces/pgadmin4/deployments/pgadmin4
  uid: efe0e59a-0eb9-4611-a5b1-68e8397deecc
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/instance: pgadmin4
      app.kubernetes.io/name: pgadmin4
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        checksum/secret: 8fdf906ba627854b39b457023b52dd6eaf7f51bb8805b7713ac19ac4c9faf2
        kubectl.kubernetes.io/restartedAt: "2024-08-29T13:42:24-04:00"
      creationTimestamp: null
      labels:
        app.kubernetes.io/instance: pgadmin4
        app.kubernetes.io/name: pgadmin4
    spec:
      containers:
      - env:
        - name: PGADMIN_CONFIG_LOG_LEVEL
          value: DEBUG
        - name: PGADMIN_CONFIG_CONFIG_DATABASE_URI
          value: ''
        - name: TZ
          value: America/New_York
        - name: PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION
          value: "True"
        - name: PGADMIN_DEFAULT_EMAIL
          value: ''
        - name: PGADMIN_DEFAULT_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: pgadmin4
        - name: PGADMIN_LISTEN_ADDRESS
          value: 0.0.0.0
        - name: PGADMIN_LISTEN_PORT
          value: "5512"
        - name: PGADMIN_CONFIG_AUTHENTICATION_SOURCES
          value: '[''ldap'', ''internal'']'
        - name: PGADMIN_CONFIG_LDAP_AUTO_CREATE_USER
          value: "True"
        - name: PGADMIN_CONFIG_LDAP_SERVER_URI
          value: ''
        - name: PGADMIN_CONFIG_LDAP_USERNAME_ATTRIBUTE
          value: '''sAMAccountName'''
        - name: PGADMIN_CONFIG_LDAP_SEARCH_BASE_DN
          value: ''
        - name: PGADMIN_CONFIG_LDAP_SEARCH_FILTER
          value: ''
        - name: PGADMIN_CONFIG_LDAP_SEARCH_SCOPE
          value: '''SUBTREE'''
        - name: PGADMIN_CONFIG_LDAP_BASE_DN
          value: ''
        - name: PGADMIN_CONFIG_LDAP_BIND_USER
          value: ''
        - name: PGADMIN_CONFIG_LDAP_BIND_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ldapPassword
              name: pgadmin4
        image: docker.io/dpage/pgadmin4:8
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /misc/ping
            port: http
            scheme: HTTP
          initialDelaySeconds: 30
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 15
        name: pgadmin4
        ports:
        - containerPort: 5512
          name: http
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /misc/ping
            port: http
            scheme: HTTP
          initialDelaySeconds: 30
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 15
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/lib/pgadmin
          name: pgadmin-data
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        fsGroup: 5050
        runAsGroup: 5050
        runAsUser: 5050
      terminationGracePeriodSeconds: 30
      volumes:
      - name: pgadmin-data
        persistentVolumeClaim:
          claimName: pgadmin4

PaulChristophel avatar Sep 12 '24 18:09 PaulChristophel

Getting below error when running docker container.

2024-10-07 16:14:02 Traceback (most recent call last):
2024-10-07 16:14:02   File "/pgadmin4/setup.py", line 32, in <module>
2024-10-07 16:14:02     import config
2024-10-07 16:14:02   File "/pgadmin4/config.py", line 951, in <module>
2024-10-07 16:14:02     from pgadmin.evaluate_config import evaluate_and_patch_config
2024-10-07 16:14:02   File "/pgadmin4/pgadmin/evaluate_config.py", line 50, in <module>
2024-10-07 16:14:02     import config_distro
2024-10-07 16:14:02   File "/pgadmin4/config_distro.py", line 16
2024-10-07 16:14:02     CONFIG_DATABASE_URI =
2024-10-07 16:14:02                          ^
2024-10-07 16:14:02 SyntaxError: invalid syntax

pravesh-sharma avatar Oct 08 '24 06:10 pravesh-sharma

Feature implemented. Tested on docker snapshot image and is working.

pravesh-sharma avatar Oct 14 '24 08:10 pravesh-sharma