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

Environment variable substitution in flyway.conf yields weird experience #2580

Closed
tarciosaraiva opened this issue Nov 29, 2019 · 3 comments
Closed

Comments

@tarciosaraiva
Copy link

@tarciosaraiva tarciosaraiva commented Nov 29, 2019

Which version and edition of Flyway are you using?

6.1

If this is not the latest version, can you reproduce the issue with the latest one as well?

(Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Yes

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Command-line, docker based

Which database are you using (type & version)?

PostgreSQL 10

Which operating system are you using?

Docker under Mac OS and Amazon Linux

What did you do?

(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)

I have a simple configuration file that looks basically like this:

flyway.url=${JDBC_URL}
flyway.password=${FLYWAY_PASSWORD}
flyway.user=flyway

The password is dynamically generated and rotates every day and we are not discounting special characters. While testing the password contained the following special characters:

(,$[

Assigning the password to the environment variable FLYWAY_PASSWORD and running the Docker image was resulting in the Java-based error illegal group reference. An easy search gave me the SO result.

I then thought to myself that I needed to escape the characters. I did that (by hand) but forgot to escape the dollar sign and still got the same error. Tried again, this time escaping the dollar sign, and whatever Flyway does with the replacement worked but I got wrong password.

What did you expect to see?

I expected the password, passed in to the env variable, would be unescaped somehow or accounted for special characters.

What did you see instead?

I got a wrong password message.

@tarciosaraiva tarciosaraiva changed the title Issues with environment variable substitution in flyway.conf Environment variable substitution in flyway.conf yields weird experience Nov 29, 2019
@tarciosaraiva
Copy link
Author

@tarciosaraiva tarciosaraiva commented Nov 29, 2019

I thought I would mention that this problem goes away if I use the environment variable FLYWAY_PASSWORD without assigning to flyway.password in the configuration file.

Only now I noticed that Flyway actually expects an environment variable of that name anyway and I guess use them two caused a substitution error.

In any case, this is the debug info

DEBUG: Loading config file: /flyway/conf/flyway.conf
ERROR: Unexpected error
java.lang.IllegalArgumentException: Illegal group reference
	at java.util.regex.Matcher.appendReplacement(Matcher.java:857)
	at java.util.regex.Matcher.replaceAll(Matcher.java:955)
	at java.lang.String.replaceAll(String.java:2223)
	at org.flywaydb.core.internal.configuration.ConfigUtils.expandEnvironmentVariables(ConfigUtils.java:335)
	at org.flywaydb.core.internal.configuration.ConfigUtils.loadConfigurationFile(ConfigUtils.java:316)
	at org.flywaydb.commandline.Main.loadConfigurationFromConfigFiles(Main.java:423)
	at org.flywaydb.commandline.Main.main(Main.java:98)

Feel free to close this ticket if not relevant. I did not test the scenario using flyway.password=${MY_ENVVAR_PWD} where MY_ENVVAR_PWD has special characters.

@alextercete alextercete added this to the Flyway 6.1.1 milestone Dec 2, 2019
@alextercete
Copy link
Contributor

@alextercete alextercete commented Dec 3, 2019

@tarciosaraiva Thanks for reporting this! We have produced a fix which will be available in 6.1.1.

@tarciosaraiva
Copy link
Author

@tarciosaraiva tarciosaraiva commented Dec 3, 2019

That's great to hear @alextercete - happy to help!

dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants