Hi,
I didn't test the PEM key yet. That seems to be hot.
For some time this problem was bothering me and I tried to inspect it. Then, the problem went away. I wanted to debug ssh messages, so I did the following
1. Created the ssh keys as I found here https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html
# by default, it goes to .ssh folder
ssh-keygen -t rsa -b 4096 -N ''
2. Created a ssh config with LogLevel directive
cat > .ssh/config <<EOF
Host bitbucket.org
StrictHostKeyChecking no
HostName bitbucket.org
Port 22
User git
IdentityFile ~/.ssh/id_rsa
LogLevel DEBUG
EOF
3. Wrapped all to tar in base64 format
tar -czvf - .ssh/ | base64 -w0
4. I copied the base64 code and pasted it in Bitbucket as documented here https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html, in the "3: Add the key as a secure variable". The name I choose to the variable is "SSH_KEYS"
5. In the beginning of pipeline I put this in the script session
- echo "${SSH_KEYS}" | base64 -d | tar -C "${HOME}" -zxvf -
I was expecting to get the SSH errors, because I use git clone command in my pipeline. But I got no errors after that.
Fabio - I love your solution, very clever workaround for this! I was able to implement this idea in my codebase and it put an end to hours of debugging ssh keys.
In my case I was using attempting to deploy to a hosting provider that would only allow me to supply a 4096 bit public key. I tried quite a few different ways to get keys that would communicate with the deployment stack but got nowhere. I'm not sure if it was pipelines being incompatible with the key type but I've wasted so many hours and build minutes on this issue.
The idea of storing a private key in an environmental variable just sounds like bad practice. At least in this case the data is obfuscated to some degree. I'm sure this can be made more secure but at the end of the day this looks like more of a Bitbucket pipelines issue. We should be allowed to upload and use more secure ssh keys in a build environment.