Spring-cloud-config: Reason: Property 'spring.cloud.config.server.git.privateKey' is not a valid private key

Created on 22 May 2019  路  5Comments  路  Source: spring-cloud/spring-cloud-config

I am trying to integrate config server with BitBucket and I am using below properties.

spring.cloud.config.server.git.uri={ssh URL of git repository }
spring.cloud.config.server.git.ignoreLocalSshSettings=false
spring.cloud.config.server.git.privateKey=|

-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----

but I am getting error as below:

Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.config.server.git' to org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties failed:

Reason: Property 'spring.cloud.config.server.git.privateKey' is not a valid private key

why I am getting this error?
Am I missing any other properties over here?

same code working fine when I am pointing to local git repository.

feedback-provided

Most helpful comment

JGit requires RSA keys in PEM format. Below is an example ssh-keygen (from openssh) command that will generate a key in the corect format:

ssh-keygen -m PEM -t rsa -b 4096

All 5 comments

I have exactly the same situation

Solved in other way. The non-working key vas generated with ssh-keygen on my Mac (10.14.5) so I used a raspberry pi to generate a new key and that is worked. It seems the problem is around the SSH versions.

@dilipsingh1306 could it be something similar? Can you provide the full exception?

when we are passing private key property value as mentioned in below inside properties file, I have got this error always.

spring.cloud.config.server.git.privateKey=|
-----BEGIN RSA PRIVATE KEY-----
---- key content --
-----key content --
-----END RSA PRIVATE KEY-----

The above format works fine with .yml file format but not with .properties file configuration.

I have resolved this issue after debugging JGit api, we should append "\n" for each line of key like shown in below when we are proceeding with properties file configuration.

When we are using .yml file with above-mentioned format, finally they are also appending newline character "\n" so applied same format for properties file directly and then it's started working fine.

spring.cloud.config.server.git.privateKey= -----BEGIN RSA PRIVATE KEY-----\n
---- key content --\n
-----key content --\n
-----END RSA PRIVATE KEY-----

After only this change, Error got resolved.

JGit requires RSA keys in PEM format. Below is an example ssh-keygen (from openssh) command that will generate a key in the corect format:

ssh-keygen -m PEM -t rsa -b 4096

Was this page helpful?
0 / 5 - 0 ratings