Skip to content

[Bug]: env var with $ parsing #3946

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

Open
iiAku opened this issue Oct 17, 2024 · 4 comments
Open

[Bug]: env var with $ parsing #3946

iiAku opened this issue Oct 17, 2024 · 4 comments
Labels
🐛 Bug Reported issues that need to be reproduced by the team.

Comments

@iiAku
Copy link

iiAku commented Oct 17, 2024

Error Message and Logs

Hello

Thanks for building Coolify.

I've tried to install https://github.com/wg-easy/wg-easy through a docker-compose.
To secure the installation it requires a PASSWORD_HASH which is a bcrypt hash so for instance:


❯ docker run -it ghcr.io/wg-easy/wg-easy wgpw foobar                        
PASSWORD_HASH='$2a$12$mSNGEiOT7urQP/Xs10XzPurl5cmVj6tavHRZQUK0jIFXRWFBGmssu'

However I never been able to set that environment variable properly, it seems there is a bug.

For instance if you:

  1. Uncheck Escape special characters in labels?
  2. Double all the $ char yourself

This

    environment:
      WG_HOST: '${WG_HOST}'
      PASSWORD_HASH: $$2a$$12$$mSNGEiOT7urQP/Xs10XzPurl5cmVj6tavHRZQUK0jIFXRWFBGmssu
      WG_DEFAULT_DNS: 1.1.1.1
      WG_ALLOWED_IPS: '0.0.0.0/0, ::/0'

will be translated to

    environment:
      WG_HOST: '${WG_HOST}'
      PASSWORD_HASH: $$2a$$12$$mSNGEiOT7urQP/Xs10XzPurl5cmVj6tavHRZQUK0jIFXRWFBGmssu
      WG_DEFAULT_DNS: 1.1.1.1
      WG_ALLOWED_IPS: '0.0.0.0/0, ::/0'
      $2a$$12$$mSNGEiOT7urQP/Xs10XzPurl5cmVj6tavHRZQUK0jIFXRWFBGmssu: null
      COOLIFY_CONTAINER_NAME: '"wg-easy-ussck40c4s8kgc0o4coc0ww0"'
      COOLIFY_URL: 'https://example.com'
      COOLIFY_FQDN: exampple.com

There is this extra line:
$2a$$12$$mSNGEiOT7urQP/Xs10XzPurl5cmVj6tavHRZQUK0jIFXRWFBGmssu: null

I tried also without doubling the $ sign and tick the box but same issue

You can remove the created var from environment variable but it seems there is something that recreate if you play with different save/update.

I also tried to set variable that way PASSWORD_HASH: "${WIREGUARD_PASSWORD_HASH}"

However when I'm getting into the container through the terminal the value is never the hash injected through environment variable (truncated or mutated).

Steps to Reproduce

  1. Start a docker-compose.yml project or any project
  2. Try to set an environment variable like this $2a$12$mSNGEiOT7urQP/Xs10XzPurl5cmVj6tavHRZQUK0jIFXRWFBGmssu
  3. Validate it's possible and that the injected value is the proper one from the container

Example Repository URL

No response

Coolify Version

v4.0.0-beta.360

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

Ubuntu 24.04.1 LTS

Additional Information

No response

@iiAku iiAku added 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Oct 17, 2024
@peaklabs-dev peaklabs-dev removed the 🔍 Triage Issues that need assessment and prioritization. label Nov 20, 2024
@peaklabs-dev peaklabs-dev added this to the v4.0.0 Stable Release milestone Nov 20, 2024
@axelbdt
Copy link

axelbdt commented Jan 17, 2025

There is indeed a workaround, if you edit the docker-compose file.

Image

For instance, if the password hash generation utility generated the following:
PASSWORD_HASH='$2a$12$mk4KzSVnsuI5k5gapHdleeBXLO9EOTPXgG0JKyvZl4Cfcz2NUpdDO'
A docker-compose file containing this environment section will work (I added the last line):

environment:
      - SERVICE_FQDN_WIREGUARDEASY_8000
      - 'WG_HOST=${SERVICE_FQDN_WIREGUARDEASY}'
      - 'LANG=${LANG:-en}'
      - PORT=8000
      - WG_PORT=51820
      - 'PASSWORD_HASH=$$2a$$12$$mk4KzSVnsuI5k5gapHdleeBXLO9EOTPXgG0JKyvZl4Cfcz2NUpdDO'

Note: I single quoted the whole line AND doubled all the $ signs from the original hash.

The PASSWORD_HASH variable will be accessible unmodified in the terminal, and login with the corresponding password will work.

However, the variable will show up akwardly in the environment variables GUI.

Image

You can indeed remove it and even restart the container, password will still work. It does reappear every time I save the dockerfile though.

Ideally, I'd like to be able to enter the PASSWORD_HASH variable in the env var GUI, despite the dollar signs, either in normal or dev mode. Maybe the UI should stop trimming the single-quotes?

Related issue: #4321

@uebmaster
Copy link

@axelbdt It works, thanks.

@HachiroSan
Copy link

just an extra note for those who use @axelbdt solution,

if you have slash '/' in your password hash, you will get below error. this is caused by variable showing in env var as mentioned.

Image

hash used :-
Image

what you need to do is keep generating the password hash until you get password hash that doesn't contain slash like below
Image

@bigfather98
Copy link

what you need to do is keep generating the password hash until you get password hash that doesn't contain slash like below

can confirm this workaround works for me too. thanks @HachiroSan

@peaklabs-dev peaklabs-dev marked this as a duplicate of #5112 Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Reported issues that need to be reproduced by the team.
Projects
None yet
Development

No branches or pull requests

6 participants