Skip to content
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

Random password generation occasionally suffers from incompatible characters #24

Open
werenall opened this issue Apr 18, 2024 · 6 comments

Comments

@werenall
Copy link

(apply str (take length (repeatedly generate-random-character))))

If you're unlucky enough (like I was) you'll get APP_DB_PASSWORD that looks like this: ABCD=EFG)#)HIJ!(GRJ3P$oX'. I sanitized it mostly but the unchanged part are the last 3 characters: $oX. Apparently that doesn't go well with env variables readers because I got errors like:

time="2024-04-18T16:32:47Z" level=warning msg="The \"oX\" variable is not set. Defaulting to a blank string."

What I ended up doing was changing the password in AWS Parameter Store and altering the role:

ALTER ROLE app PASSWORD 'mynewpass';

The build is in progress now. Will post here with updates.

@iarenaza
Copy link
Contributor

Hi @werenall

do you get the error in the "shell phase" (while running the start-dev.sh shell script), in the "docker phase" (while docker starts up the containers), or in the "clojure phase" (when Duct or your application logic tries to use the value)?

It's to be able to narrow down which component is "holding it wrong". With proper quoting / handling of the value (which we should be doing, but apparently are not), almost any character in the ASCII range (maybe U+0000 and U+001F would be the exceptions here) should be usable. Granted, using characters in the control characters range would be a UX disaster (you won't see them easily, and typing them is a pain in the ass), but we don't use such characters.

Thanks a lot in advance!

@werenall
Copy link
Author

Local development starts just fine (because it doesn't really need to assume that test env role?)

It's the EB that crashes. I was getting Bad Gateway errors and upon logs inspection I realised that app container was immediately dying because of that APP_DB_PASSWORD.

Anyway, changing to a very long but no special characters password worked. So happy and excited to move forward now 🦜
image

@iarenaza
Copy link
Contributor

@werenall Thanks a lot for the feedback!

So it's actually AWS Elastic Beanstalk the one choking. We'll have a look into that. We are probably missing some quoting in the code that deals with setting up the environment variables from the values stored in AWS Parameter Store.

Nice finding! Again, thanks a lot!

@iarenaza
Copy link
Contributor

@werenall After analyzing this, it seems to be a change in the semantics in the "environment files" in docker-compose (and docker compose). In older versions, variable definitions didn't have any kind of expansion / interpolation. E.g.:

VAR=$OTHERVAR

would make VAR have exactly the string $OTHERVAR as its value. At some point this behavior was changed (but not documented). But it was changed in an inconsistent way (different verions having slightly different behaviors). And in Sept 2022, the documentation was updated to reflect the changes, and make them official.

It seems that our code pre-dates those changes in the documentation. In addition to that, we seem to be using older versions of docker-compose, so we didn't catch some edge cases.

We'll see what we can do, as we think it will not be possible to support both older versions and newer versions of docker-compose at the same time (their semantics for variable expansion / interpolation are not compatible in some cases).

iarenaza added a commit that referenced this issue Apr 28, 2024
Some background for the changes introduced in this commit.

The unexpected behavior detected by @werenall in #24 seems to be
related with a change in the semantics of the processing of
"environment files" in docker-compose (and `docker compose`). In older
versions, variable definitions didn't have any kind of expansion /
interpolation. E.g.:

   VAR=$OTHERVAR

would make VAR have exactly the string `$OTHERVAR` (verbatim) as its
value. At some point, this behavior was changed (but not documented!)
in docker-compose. But it was changed in an inconsistent
way (different versions having slightly different behaviors). And in
Sept 2022, the documentation was updated to reflect the changes, and
make them the official behavior.

It seems that our code for the creation of "environment files"
pre-dates those changes in the documentation. In addition to that, we
seem to be using older versions of docker-compose (i.e., not the
"latest and greatest"), so we didn't catch some edge cases.

Given that:

- the minimum required docker-compose version for HOP is 1.27.0,

- version 1.27.0 is the first version that fully implements the
  "compose specification"[1],

- and that the "compose specification" is where the change in the
  expansion / interpolation is standardized,

we have decided to quote the values of the variables in the
"environment file" we produce. For that, we need to make sure we quote
any single quotes that are part of the original value, which in turn
means we need to quote any quotes that were part of the original value.

[Re: #24]

[1] https://compose-spec.io/
@iarenaza
Copy link
Contributor

Closing as fixed in f4b8b88

iarenaza added a commit that referenced this issue Dec 7, 2024
When we fixed issue #24, we focused on the AWS ElasticBeanstalk use
case (where we populate the .env file from SSM Parameter Store). But
it turns out we missed the other big use case where the same problem
may happen: when creating the local development .env file (or the test
/ production .env files for on-premises deployments).

This commit addresses that second use case. There is a bit of code
churn in this commit because we wanted to handle both use cases using
the same utility functions (so we apply the quoting policy in a single
place). That in turn meant that we had to refactor a bunch of SSM
Parameter Store related code, because in that case we directly used
the data in the shape that Parameter Store returned. And that was
incompatible with the data shape used in the rest of the code dealing
with docker-compose environment variables.
@iarenaza
Copy link
Contributor

Reopening the issue, because we've hit another different use case that breaks with the current implementationm

@iarenaza iarenaza reopened this Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants