camptocamp / puppet-accounts

11 stars 40 forks source link

issue adding private key from hiera #28

Closed teleivo closed 8 years ago

teleivo commented 8 years ago

Hello!

I am having trouble adding a private key from hiera. The ~/.ssh/id_rsa is created and it contains the data but in a different format than the original key because newlines are not passed on to the echo command.

My yaml file looks like this:


---
accounts::ssh_keys:
  paul:
    type: ssh-rsa
    private: -----BEGIN RSA PRIVATE KEY-----
      xxxxx

which leads to ~/.ssh/id_rsa being:

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

As an alternative I tried


---
accounts::ssh_keys:
  paul:
    type: ssh-rsa
    private: |
      -----BEGIN RSA PRIVATE KEY-----
      xxxxx

which leads to ~/.ssh/id_rsa being:

-----BEGIN RSA PRIVATE KEY-----\n xxxxx

understandable, since the command writing the file content is echo not interpreting the newline character https://github.com/camptocamp/puppet-accounts/blob/master/manifests/account.pp#L134

I would be very grateful if somebody could tell me how to add a private key via hiera :)

teleivo commented 8 years ago

Hi, so with hiera eyaml and gpg plugin https://github.com/TomPoulton/hiera-eyaml https://github.com/sihil/hiera-eyaml-gpg

I got it to work :+1:

It then looks like this

---
accounts::ssh_keys:
  paul:
    type: ssh-rsa
    public: DEC(1)::GPG[xxxxxxx]!
    private: |
      DEC(3)::GPG[-----BEGIN RSA PRIVATE KEY-----
xxxxx
xxxxx
xxxxx
-----END RSA PRIVATE KEY-----
]!