[RESOLVED] SSH key add API -- trim spaces on server side


#1

Hello,

I’d like to introduce the small improvement in SSH key add API. That would be great if the trailing (and, probably, leading) whitespaces are ignored. Both Terraform TLS provider and ssh-keygen tool generate SSH public keys in the form of a single line ending with a newline character. If the contents of a file (and the output of Terraform provider) is used as-is, it generates invalid_request_error with contents “Validation Error, Details: map[ssh_public_keys.1.key:[incorrect public key]]”. If a newline character is not present, everything works well. That small imperfection forces to use Terraform’s built-in ‘trimspace’ to clean up data on client side, but it could be equally run on server-side.

Here are some Terraform logs for reference.

1/ With newline – error:

module.base.scaleway_ssh_key.master: Creating...
key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC4NcFzXwkk132Ee65ifZdIlmFt9H/3RyH/La2F9BrB9A5upMDe2XyzFIX57YZXriUeY9nDrBUkyzqMITeEzt8SeBOmavgUX5n2aMvQGnislwH6YzOqs+qh+l31nDZ22+g1N+2Vkfv6HXoBw42Eu+9AUt9AghDTF6s1d1sazu0PvW2qvQhQVs47By3tGTiXvFveL0szVA4JanDGPrBJB9/owNTDPee8Wn7FPHfYry/X3lY7We4tLSGDf4t4La5/DsQq3SL9rhlAtutWjU3RAgO69NcmcrqhcZdymPQZ9ipu/7f7vRt5JH/aJpTz5OfW7sGdFIH4KJNgy6tt0Usgdxt8L8J0GoMcZtBlW02O6h7pDyH5mmusO69Uu/pjyHf99XWXSSLXZysTJdamC055xN//5M/vQIu1Ilea4ntLBobhlwbkuRLecgwa0trkPdayLzSEeapVqnelnIM1EdPuWIVb5slXWk9NlEcAJ51A6W+xXBE6JTGBVbItSa/X4Z1HK6n007rLzIAyRcdjMLo8dCj+O9dLkp3Zf5eziFztzbwzIR6LOZCWyU3hDMz+rC4lhbN3Si77VqqfmFiT8qqIWZ1jyLWnp1K0zvtP0TMGcKdtFr+I/dA6+sd1me9ArFQgoCEbxpzadmGSIqxo7ILqPtrq038d3KZ4WRORVRtOKEwR1Q==\n"

Error: Error applying plan:

1 error(s) occurred:

* module.base.scaleway_ssh_key.master: 1 error(s) occurred:

* scaleway_ssh_key.master: StatusCode: 400, Type: invalid_request_error, APIMessage: Validation Error, Details: map[ssh_public_keys.1.key:[incorrect public key]]

2/ Without newline – OK:

module.base.scaleway_ssh_key.master: Creating...
key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDD5jbYRkZrD8HwvX2jIDhADiKuZVokKXBAvs5vBstDpwD1xZGdOfX42HyJ/bCU1o5nIJ6/SBAqUfvf373MBsFN1jxIERdpv+0MwnbSCVSZA6IJrc9jmjFryVINMB2DrTeTVL3/x5UTjpB74QGyqhOHcyrRysee7V8X8e0RO3MqleuP4gE7PqW0b9nwUIOHRRTe5QUET+cxTei9XAdGyVSNptUlmOKqTKxHZxH8nFVV87dLUnDNEqgxudccbvbQ1Nk9/ZnvRbC/QXQnk9rrn5l577OW+I+XGxuTHjoLlMkwVUvyAH7K8NWCb2pgt0/IX9vcQYxgjptsiPMtarkr3eLOCnMATrHNebQlewwJ33BRR/keKmCzMlGHaaNNvJjIMSvFtPqJ8hqy+OQPYgwYAQhvBWRxZkQ+CUY396UtSijEyQ7UNzYslOseHWqj4nQNL4ZobmXNWnhPafBa5Z6pG4fmlQi4xdKT37RxoGuCtF7cHugw3uI9JCTVqACC+GziRamMiKkfKOYDSAKgmFrExUeNnd9mFJJARDPt1JP/JH9RdNPhe/P6R555GT/0wJPwUxtu6n+6Rb4baZB4zfsGjFXFXFwPFD+ELST3K6LPSWBzqc1Ix+MPfW1bxOUw8p6jb60aD2OjSIm0VmA+5gBppnickJ9/upePqv2G7ArmxOGVMw=="
module.base.scaleway_ssh_key.master: Creation complete after 7s (ID: 7c:04:23:0f:25:70:53:38:ad:4d:aa:dc:44:3e:4e:8e)

#2

It will help if you post Terraform file here. Maybe it is Scaleway module that needs to be fixed.


#3

Here is my terraform configuration, nothing unusual:

resource "tls_private_key" "scaleway" {
  algorithm = "RSA"
  rsa_bits = 4096
}

resource "scaleway_ssh_key" "master" {
  key = "${trimspace(tls_private_key.scaleway.public_key_openssh)}"
}

You’re right, fixing terraform plugin would solve the issue. Will try to submit a pull request.


#4

The issue is solved, PR merged, the fix will be avl in next Terraform provider release