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

Microsoft SQL server token login and Flyway placeholder results in a login error. #3884

Open
User7845 opened this issue Apr 26, 2024 · 2 comments

Comments

@User7845
Copy link

Which version and edition of Flyway are you using?

Flyway Community Edition 10.11.1 by Redgate

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)
Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Command-line

Which database are you using? (Type & version)

Azure Microsoft SQL server

Which operating system are you using?

WIndows

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

I am running into a login issue once I add a Flyway placeholder to the environment variable or to my toml file.

I use the token login from sql server by setting an environment variable FLYWAY_JDBC_PROPERTIES_accessToken.
This works correctly but once I add a Flyway placeholder I run into the error:

If I remove the error disappears when I remove the placeholder from the environment variables and the TOML file.

What did you expect to see?

That I can correctly login and execute my migration files

What did you see instead?

The error:

ERROR: Unable to obtain connection from database (jdbc:sqlserver://xxxxxx.database.windows.net:1433;databaseName=xxxxx) for user 'null': Login failed for
user ''. ClientConnectionId:a20e1e0f-02c5-4e12-a347-f35e1b777fc4

SQL State : S0001
Error Code : 18456
Message : Login failed for user ''. ClientConnectionId:a20e1e0f-02c5-4e12-a347-f35e1b777fc4

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:a20e1e0f-02c5-4e12-a347-f35e1b777fc4

@Barry-RG
Copy link
Contributor

Would you be able to provide us with a minimal reproduction?
From your description I am unsure as to what you are trying to achieve.
For example, you say you are trying to add a Flyway placeholder to the environment variable or to my toml file. Do you mean you are trying to configure a placeholder as a environment variable or in your toml configuration.
I am unsure as to what connection that has to setting an accessToken for SQLServer in the environment variable FLYWAY_JDBC_PROPERTIES_accessToken

@User7845
Copy link
Author

User7845 commented May 2, 2024

I have the following configuration:
flyway.toml:

[flyway]
locations = ["filesystem:./sql"]
validateMigrationNaming = true
baselineOnMigrate = true
baselineVersion = "0"
table = "infra_schema_history"
placeholderReplacement = true
defaultSchema = "dbo"


[environments.d]
url = "jdbc:sqlserver://{server}.database.windows.net:1433;databaseName={dbname}"

In powershell I retrieve the access token and add it to the environment variables:
$Env:FLYWAY_JDBC_PROPERTIES_accessToken = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token

Then I execute the migration step:

        flyway migrate `
          -environment="${{ parameters.environment }}" `
          -workingDirectory="${{ parameters.flywayDeploymentsLocation }}/${{ parameters.flywayDeployment }}/"

This works correctly.

Once I add an environment variable containing the FLYWAY_PLACEHOLDERS prefix the login fails.
$Env:FLYWAY_PLACEHOLDERS_HOSTINGTEAM="test"

This also happends when I add the variable to the flyway.toml file:

[flyway.placeholders]
HOSTINGTEAM= "test"

The login works correctly again once I remove the placeholders

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

2 participants