admin管理员组文章数量:1376079
jobs:
- deployment: deployUat
timeoutInMinutes: 120
variables:
private_key: $(UAT_SF_PRIVATE_KEY_test)
pool:
vmImage: 'windows-latest'
environment: "$(System.TeamProject)-uat"
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: 'Clear Flyway Working Directory'
inputs:
targetType: 'inline'
script: |
Get-ChildItem -Path "$(Pipeline.Workspace)" -Directory -Recurse -Force |
Where-Object { $_.Name -like "*.flyway*" } |
Remove-Item -Recurse -Force -Verbose
- task: PowerShell@2
displayName: "Format Private Key"
name: setPrivateKey
inputs:
targetType: inline
script: |
$formattedKey = "$(UAT_SF_PRIVATE_KEY_test)" -replace "@", "`n"
Write-Host "##vso[task.setvariable variable=formattedKey;isOutput=true]$formattedKey"
Write-Host "Formatted key value stored"
- task: PowerShell@2
displayName: Get JDBC URL
inputs:
targetType: 'inline'
script: |
Write-Host "Formatted key value: $(setPrivateKey.formattedKey)"
$jdbcUrl = "jdbc:snowflake://xx.xx-europe.azure.snowflakecomputing/?warehouse=$(UAT_SF_WAREHOUSE)&role=$(UAT_SF_ROLE)&db=UAT_$(SF_DATABASE)&authenticator=snowflake_jwt"
Write-Host "Generated JDBC URL: $jdbcUrl"
Write-Host "##vso[task.setvariable variable=jdbcUrl;isOutput=true]$jdbcUrl"
name: property
When i put the key on hard code it works but when i try to get it from library it does not work , i tried to print the value of the variable in the task before but it return nothing. Error : Message : Private key provided is invalid or not supported: Use java.security.interfaces.RSAPrivateCrtKey.class for the private key
Caused by: net.snowflake.client.jdbc.SnowflakeSQLLoggedException: Private key provided is invalid or not supported: Use java.security.interfaces.RSAPrivateCrtKey.class for the private key
jobs:
- deployment: deployUat
timeoutInMinutes: 120
variables:
private_key: $(UAT_SF_PRIVATE_KEY_test)
pool:
vmImage: 'windows-latest'
environment: "$(System.TeamProject)-uat"
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: 'Clear Flyway Working Directory'
inputs:
targetType: 'inline'
script: |
Get-ChildItem -Path "$(Pipeline.Workspace)" -Directory -Recurse -Force |
Where-Object { $_.Name -like "*.flyway*" } |
Remove-Item -Recurse -Force -Verbose
- task: PowerShell@2
displayName: "Format Private Key"
name: setPrivateKey
inputs:
targetType: inline
script: |
$formattedKey = "$(UAT_SF_PRIVATE_KEY_test)" -replace "@", "`n"
Write-Host "##vso[task.setvariable variable=formattedKey;isOutput=true]$formattedKey"
Write-Host "Formatted key value stored"
- task: PowerShell@2
displayName: Get JDBC URL
inputs:
targetType: 'inline'
script: |
Write-Host "Formatted key value: $(setPrivateKey.formattedKey)"
$jdbcUrl = "jdbc:snowflake://xx.xx-europe.azure.snowflakecomputing/?warehouse=$(UAT_SF_WAREHOUSE)&role=$(UAT_SF_ROLE)&db=UAT_$(SF_DATABASE)&authenticator=snowflake_jwt"
Write-Host "Generated JDBC URL: $jdbcUrl"
Write-Host "##vso[task.setvariable variable=jdbcUrl;isOutput=true]$jdbcUrl"
name: property
When i put the key on hard code it works but when i try to get it from library it does not work , i tried to print the value of the variable in the task before but it return nothing. Error : Message : Private key provided is invalid or not supported: Use java.security.interfaces.RSAPrivateCrtKey.class for the private key
Caused by: net.snowflake.client.jdbc.SnowflakeSQLLoggedException: Private key provided is invalid or not supported: Use java.security.interfaces.RSAPrivateCrtKey.class for the private key
Share Improve this question edited Mar 28 at 12:43 DatagGirl asked Mar 27 at 17:13 DatagGirlDatagGirl 277 bronze badges 5 |2 Answers
Reset to default 1Add some commands in your YAML to print the values of variables to find out what is wrong. For example,
jobs:
- deployment: deployUat
timeoutInMinutes: 120
environment: "$(System.TeamProject)-uat"
variables:
private_key: $(UAT_SF_PRIVATE_KEY_test)
pool:
vmImage: 'windows-latest'
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: 'echo The value of UAT_SF_PRIVATE_KEY_test is $(UAT_SF_PRIVATE_KEY_test)'
- task: PowerShell@2
name: setPrivateKey
inputs:
targetType: 'inline'
script: |
$formattedKey = "$(UAT_SF_PRIVATE_KEY_test)" -replace "@", "`n"
Write-Output "The value of formattedKey is: $formattedKey"
Write-Host "##vso[task.setvariable variable=newformattedKey;isOutput=true]$formattedKey"
- task: CmdLine@2
inputs:
script: 'echo The value of newformattedKey is $(setPrivateKey.newformattedKey)'
If it's wrong in the first
CmdLine@2
task, check the variable in your variable group. You can share an example of yourUAT_SF_PRIVATE_KEY_test
, I want to know the format of it.If it's wrong in the second
PowerShell@2
task, verify whether the way to format secret is correct.
Based on your scripts, you are trying to replace @
in the UAT_SF_PRIVATE_KEY_test
with `n
. If so, I am not sure whether the actual value of formattedKey
is what you expect. Assume the value of UAT_SF_PRIVATE_KEY_test
is test@abc
.
The value of
$formattedKey
in thePowerShell@2 task
is multi-line, but output variables do not support multi-line variables, so the value of the output variable is the part before the newline character. As shown in the screenshot:In this example, the actual value of output variable
newformattedKey
is test.
I had problem to pass the variable from one task (powershell) to another one-flyway ) so i used a config file like that :
- task: PowerShell@2
displayName: "Format Private Key"
inputs:
targetType: inline
script: |
$tempFile = "$(Pipeline.Workspace)/formattedKey.txt"
"$(private_key)" | Out-File $tempFile
Write-Host "##vso[task.setvariable variable=keyFilePath]$tempFile"
- task: PowerShell@2
displayName: Get JDBC URL
inputs:
targetType: 'inline'
script: |
$jdbcUrl = "jdbc:snowflake://xx.xx-xx.azure.snowflakecomputing/?warehouse=$(PRD_SF_WAREHOUSE)&role=$(PRD_SF_ROLE)&db=PRD_$(SF_DATABASE)"
Write-Host "Generated JDBC URL: $jdbcUrl" # This will display the generated JDBC URL
Write-Host "##vso[task.setvariable variable=jdbcUrl;isOutput=true]$jdbcUrl"
#private key process
$formattedKey = Get-Content "$(keyFilePath)" -Raw
Write-Host "Private key loaded successfully : $formattedKey"
# Process the key formatting in separate statements
$formattedKey = $formattedKey -replace "-----BEGIN PRIVATE KEY-----", ""
$formattedKey = $formattedKey -replace "-----END PRIVATE KEY-----", ""
$formattedKey = $formattedKey -replace "\s+", " "
$formattedKey = $formattedKey.Trim()
$formattedKey = "@|@-----BEGIN PRIVATE KEY-----@$formattedKey@-----END PRIVATE KEY-----@"
Write-Host "Private key formated loaded successfully1: $formattedKey"
$formattedKey = $formattedKey -replace "@", "`n"
Write-Host "Private key formated loaded successfully2: $formattedKey"
$pemPath = "$(Pipeline.Workspace)/snowflake_key.pem" -replace "\\", "/"
[System.IO.File]::WriteAllText($pemPath, $formattedKey, [System.Text.Encoding]::UTF8)
Write-Host "##vso[task.setvariable variable=SNOWFLAKE_KEY_PATH]$pemPath"
Write-Host "Successfully created PEM file at: $pemPath"
name: property
- task: FlywayCLI@0
displayName: Flyway Repair (Pre-Deploy)
inputs:
command: 'repair'
workingDirectory: '$(Pipeline.Workspace)/drop/${{parameters.rootFolder}}'
url: "jdbc:snowflake://xx.xx-xx.azure.snowflakecomputing/?warehouse=$(PRD_SF_WAREHOUSE)&role=$(PRD_SF_ROLE)&db=PRD_$(SF_DATABASE)&private_key_file=$(SNOWFLAKE_KEY_PATH)"
user: $(PRD_SF_USERNAME)
...
本文标签: use authentification RSA instead of password in devOps azure using flyway on snowflakeStack Overflow
版权声明:本文标题:use authentification RSA instead of password in devOps azure using flyway on snowflake - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744077451a2587010.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
password
as a variable, you will encounter an error? Have you triedecho
the variable's value inside the pipeline? Is it the same as the hard-coded value? – Ziyang Liu-MSFT Commented Mar 28 at 9:53