GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Quoting is broken for `PGADMIN_CONFIG_CONFIG_DATABASE_URI` environment variable. · Issue #8529 · pgadmin-org/pgadmin4

Quoting is broken for PGADMIN_CONFIG_CONFIG_DATABASE_URI environment variable. #8529

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Quoting is broken for PGADMIN_CONFIG_CONFIG_DATABASE_URI environment variable.#8529
Copy link
Labels
Bug

Description

@troplin
troplin
opened on Mar 9, 2025
Issue body actions

Please note that security bugs or issues should be reported to [email protected].

Describe the bug

Using an external database by setting the PGADMIN_CONFIG_CONFIG_DATABASE_URI environment variable only works if the value is enclosed in single quotes.
This not how environment variables are usually used for configuration and it's also not documented anywhere, which makes it very difficult to find the issue.

I also tried double quotes but that also doesn't work (for a different reason).

To Reproduce

Steps to reproduce the behavior:

  1. Run docker container with external DB:
    docker run -p 80:80 \
        -e '[email protected]' \
        -e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
        -e 'PGADMIN_CONFIG_CONFIG_DATABASE_URI=postgresql://user:pw@host:5432/db'
        dpage/pgadmin4
  2. See the error

Expected behavior

Container starting normally without error.

Error message

  File "<string>", line 1
    from check_external_config_db import check_external_config_db; val = check_external_config_db(postgresql://user:pw@host:5432/db); print(val)
                                                                                                            ^
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 954, in <module>
    from pgadmin.evaluate_config import evaluate_and_patch_config
  File "/pgadmin4/pgadmin/evaluate_config.py", line 63, in <module>
    config_distro = import_module_from_path('config_distro',
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/pgadmin4/pgadmin/evaluate_config.py", line 37, in import_module_from_path
    spec.loader.exec_module(module)
  File "/pgadmin4/config_distro.py", line 12
    CONFIG_DATABASE_URI = postgresql://user:pw@host:5432/db
                                    ^
SyntaxError: invalid syntax
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: argument -t/--timeout: invalid int value: ''

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Host OS X 15.3.1, Linux Container
  • Version: 9.1
  • Mode: Both
  • Package type: Container

Additional context

The problem is the quoting in the following code in entrypoint.sh:

if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" ]; then
     external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)")
fi

specifically the string that is passed to python3:

"from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)"

This is already a quoted string so using double quotes for "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" doesn't work.

The result is that the environment variable is interpreted literally, surrounded by two separate strings:

  • "from check_external_config_db import check_external_config_db; val = check_external_config_db("
  • ${PGADMIN_CONFIG_CONFIG_DATABASE_URI}
  • "); print(val)"

The 3 values are then concatenated and the quotes are lost.

You can either use single quotes

"from check_external_config_db import check_external_config_db; val = check_external_config_db('${PGADMIN_CONFIG_CONFIG_DATABASE_URI}'); print(val)"

or else the double quotes have to be escaped with a backslash \" s.t. they are actually part of the string (or maybe even a double backslash \\", I'm not sure):

"from check_external_config_db import check_external_config_db; val = check_external_config_db(\"${PGADMIN_CONFIG_CONFIG_DATABASE_URI}\"); print(val)"

The same pattern is also used for many other variables, which makes the whole script very fragile.

Activity

  1. troplin
    added
    Bug
    on Mar 9, 2025
  2. akshay-joshi
    added this to Not Refinedon Mar 10, 2025
  3. yogeshmahajan-1903 commented on Mar 10, 2025

    @yogeshmahajan-1903
    yogeshmahajan-1903
    on Mar 10, 2025
    Contributor
    More actions

    @troplin
    Value of CONFIG_DATABASE_URI contains string with special symbols, hence it needs quoting. Use double quotes for the value in the environment switch with key and value.
    E.g -

     -e 'PGADMIN_CONFIG_CONFIG_DATABASE_URI="postgresql://user:pw@host:5432/db"'
    
  4. yogeshmahajan-1903
    closed this as not plannedon Mar 10, 2025
  5. github-project-automation
    moved this to Done in Not Refinedon Mar 10, 2025
  6. troplin commented on Mar 10, 2025

    @troplin
    troplin
    on Mar 10, 2025
    Author
    More actions

    @yogeshmahajan-1903 except that also doesn't work.

    It also messes up quoting, just in a different way.
    Now the email address from the environment variable is not recognized anymore. It tries to read it from the command line instead which fails eventually:

      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 623, 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
    

    I guess it's because if the string contains quotes, this line

    if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" ]; then
    

    doesn't work anymore.

    Proper quoting should be the responsibility of the application, not the user.

    This will probably bite most users that try to use an external config DB, most of them will just silently move on.
    I encourage you to try to get it to work yourself with a fresh external DB. For an actual DB administration tool this shouldn't be that difficult.

    No other application I know that uses a database requires the environment variable to be quoted.
    Examples:

    • Grafana: GF_DATABASE_URL=postgresql://user:pw@host:5432/db
    • Outline Wiki: DATABASE_URL=postgresql://user:pw@host:5432/db
    • Rallly: DATABASE_URL=postgresql://user:pw@host:5432/db
    • Vaultwarden: DATABASE_URL=postgresql://user:pw@host:5432/db

    Just to name a few that I use personally. I'm not saying that requiring quotes is inherently wrong, but it's unexpected for most users and not even documented.

    I'm only trying to help, I've even analyzed to code for you.
    But now I'm also moving on to a different software.

  7. yogeshmahajan-1903 commented on Mar 11, 2025

    @yogeshmahajan-1903
    yogeshmahajan-1903
    on Mar 11, 2025
    Contributor
    More actions

    @troplin
    I guess you database has some issue. I am not able to reproduce the issue with command you have provided. Also it is documented here. Kindly refer section PGADMIN_CONFIG_*

  8. troplin commented on Mar 11, 2025

    @troplin
    troplin
    on Mar 11, 2025
    Author
    More actions

    @yogeshmahajan-1903 Ok so I've found this comment in a old issue: #7973 (comment)

    For whatever reason I need to specify a driver in the URL: postgresql+psycopg://user:pw@host:5432/db

    Also it is documented here.

    Yes, but it's not easy to find and it's also not obvious that it's part of the actual syntax. They're not even the correct type of quotes: ‘string value’ (at least in my browser).

    The fact that a driver has to be specified explicitly is also documented if you search for it: https://www.pgadmin.org/docs/pgadmin4/9.1/external_database.html
    But if you look at that page, the first thing you see is the 4 examples in section "Use PostgreSQL Database" that don't have a driver specified. And it's completely unclear what drivers are available and why there isn't a default one.

    So yes, you are technically correct. But it's way too easy to get wrong and the error messages are not helpful.

    And no matter how well documented everything is:
    You are still using unsanitized user data directly in an application script. And rely on the user to do all the quoting and escaping.
    That's not exactly very confidence-inspiring for a database-heavy application.

    Reacted by P. Sai Vinay
  9. akshay-joshi
    removed this from Not Refinedon Mar 21, 2025
  10. AlxDroidDev commented on Jul 1, 2025

    @AlxDroidDev
    AlxDroidDev
    on Jul 1, 2025
    More actions

    I have the same problem trying to deploy PostgreSQL 17.5 + PGAdmin4 v9.5 from a docker compose stack. I want to have it all on the same stack, and have PGAdmin4 use the PG database, but this bug is preventing me from doing so.

  11. adityatoshniwal commented on Jul 1, 2025

    @adityatoshniwal
    adityatoshniwal
    on Jul 1, 2025
    Contributor
    More actions

    I have the same problem trying to deploy PostgreSQL 17.5 + PGAdmin4 v9.5 from a docker compose stack. I want to have it all on the same stack, and have PGAdmin4 use the PG database, but this bug is preventing me from doing so.

    Can you share sample PGADMIN_CONFIG_CONFIG_DATABASE_URI?

  12. AlxDroidDev commented on Jul 4, 2025

    @AlxDroidDev
    AlxDroidDev
    on Jul 4, 2025
    More actions

    I have the same problem trying to deploy PostgreSQL 17.5 + PGAdmin4 v9.5 from a docker compose stack. I want to have it all on the same stack, and have PGAdmin4 use the PG database, but this bug is preventing me from doing so.

    Can you share sample PGADMIN_CONFIG_CONFIG_DATABASE_URI?

    Previous answer deleted. I got it working on docker-compose by specifying the driver, like @troplin did, and double quoting:

    PGADMIN_CONFIG_CONFIG_DATABASE_URI: "'postgresql+psycopg://admin:abc123@db:5432/pgadmindb'"

    Thanks again.

  13. joachimtingvold commented on Feb 9, 2026

    @joachimtingvold
    joachimtingvold
    on Feb 9, 2026
    More actions

    The suggested workaround doesn't work if you also encorporate other ENV-variables in the connect-string, like having the following in a .env-file:

    PGADMIN_CONFIG_CONFIG_DATABASE_URI="postgresql+psycopg://${PG_USER}:${PG_PASSWORD}@${PG_HOST}/${PG_DATABASE}"

    This is an approach that works for "all the other" projects/applications, currently pgadmin4 is the only system that doesn't deal with this properly.

    Changing the string to incorporate the values directly of course works, but that's not really a good "workaround".

    PGADMIN_CONFIG_CONFIG_DATABASE_URI="'postgresql+psycopg://pgadmin:[email protected]/pgadmin'"

    edit: This seems to affect a lot of other variables used by pgadmin, if not all of them:

    PGADMIN_CONFIG_SECURITY_EMAIL_SENDER='no-reply@localhost'

    Results in:

    pgadmin  | Traceback (most recent call last):
    pgadmin  |   File "<string>", line 1, in <module>
    pgadmin  |     import config; print(config.SESSION_EXPIRATION_TIME * 60 * 60 * 24)
    pgadmin  |     ^^^^^^^^^^^^^
    pgadmin  |   File "/pgadmin4/config.py", line 976, in <module>
    pgadmin  |     from pgadmin.evaluate_config import evaluate_and_patch_config
    pgadmin  |   File "/pgadmin4/pgadmin/evaluate_config.py", line 63, in <module>
    pgadmin  |     config_distro = import_module_from_path('config_distro',
    pgadmin  |                                             config_distro_path)
    pgadmin  |   File "/pgadmin4/pgadmin/evaluate_config.py", line 37, in import_module_from_path
    pgadmin  |     spec.loader.exec_module(module)
    pgadmin  |     ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
    pgadmin  |   File "/pgadmin4/config_distro.py", line 13, in <module>
    pgadmin  |     SECURITY_EMAIL_SENDER = no-reply@localhost
    pgadmin  |                             ^^
    pgadmin  | NameError: name 'no' is not defined
    

    PGADMIN_CONFIG_MAIL_SERVER='localhost'

    Results in:

    pgadmin  | Traceback (most recent call last):
    pgadmin  |   File "/pgadmin4/run_pgadmin.py", line 4, in <module>
    pgadmin  |     from pgAdmin4 import app
    pgadmin  |   File "/pgadmin4/pgAdmin4.py", line 38, in <module>
    pgadmin  |     import config
    pgadmin  |   File "/pgadmin4/config.py", line 976, in <module>
    pgadmin  |     from pgadmin.evaluate_config import evaluate_and_patch_config
    pgadmin  |   File "/pgadmin4/pgadmin/evaluate_config.py", line 63, in <module>
    pgadmin  |     config_distro = import_module_from_path('config_distro',
    pgadmin  |                                             config_distro_path)
    pgadmin  |   File "/pgadmin4/pgadmin/evaluate_config.py", line 37, in import_module_from_path
    pgadmin  |     spec.loader.exec_module(module)
    pgadmin  |     ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
    pgadmin  |   File "/pgadmin4/config_distro.py", line 15, in <module>
    pgadmin  |     MAIL_SERVER = localhost
    pgadmin  |                   ^^^^^^^^^
    

    Seems like all PGADMIN_CONFIG_* variables need to be double-quoted to work? Not really practical...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.