SSH private keys in an environment variable

I’m trying to follow the guide for setting up ssh keys in docker but I’m getting the error:

Validation failed

Variables value is invalid

when copying over the private key.

2 Likes

I’m seeing the same failure, and it completely blocks me from setting up CI!

1 Like

Same issue here. Our CI is broken because of that. Is there another method to register an ssh key as a variable?

1 Like

@dangirsh @dennis seems like the solution is to encode / decode base64 https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_15038961

2 Likes

For me, any variable entered in CI / CD Settings > Variables gives the failure:

Validation failed

Variables value is invalid

However, if I disable the “Masked” toggle, it goes through.

It seems that my issue is not specific to the name being SSH_PRIVATE_KEY or the contents of the variable.

Ah, seems like private SSH keys don’t meet the requirements for masked variables: https://docs.gitlab.com/ee/ci/variables/#masked-variables

I’m pretty sure this worked in the past…

1 Like

How can I do this?

1 Like

Agreed, why cannot we hide a private SSH key ? :confused:

1 Like

Ya whats up with this? There a numerous tutorials out there using masked variables to store private keys… is there a preferred way to deploy via SSH? Why can’t we make the variables private?

I have this set on a couple of repos.
Just today tried to set up the automatic deployment for a new project and it doesn’t work.

i solve this by encoding private key to base64, and in my yml file i add this

- echo "$PRIVATE_KEY" | base64 --decode > /root/.ssh/id_rsa

but it’s not masked :frowning: