Skip to content

Commit

Permalink
Random password generation sometimes uses incompatible characters
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
iarenaza committed Apr 28, 2024
1 parent 605f0e3 commit f4b8b88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## [UNRELEASED]
- [aws profile] Correctly handle environment variables with '$'
characters in them (and other potentially problematic characters in
them) [issue #24]

## [0.1.11] - 2024-04-12
- [deployment S3]: Fixed incomplete S3 policy [issue #19]
Expand Down
5 changes: 4 additions & 1 deletion src/hop_cli/aws/env_vars.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

(defn- env-var->string-env-var
[{:keys [name value]}]
(format "%s=%s" name value))
(let [env-file-quoted-val (-> value
(str/replace "\\" "\\\\")
(str/replace "'" "\\'"))]
(format "%s='%s'" name env-file-quoted-val)))

(defn- get-env-var-diff
[ssm-env-vars file-env-vars]
Expand Down

0 comments on commit f4b8b88

Please sign in to comment.