community-content icon indicating copy to clipboard operation
community-content copied to clipboard

Buggy Server creation with SSH

Open giuseppeveneziano opened this issue 2 years ago • 0 comments

I'm a developer and i have used Hetzner API to make the users of my website access several server features. It works quite well in 99% of the call i make in the servers that i created until now but that 1% refers to a very strange bug that Hetzner support doesn't seem to be able to find out, so i'm asking the community.

The problem happens when i try to create a server including the ssh_keys parameter. The error code is 422 error, unprocessable entity, that refers specifically to the ssh_keys parameter. If i don't specify this parameter everything works 100% times, when i specify it only about 5% times (so sometimes randomly the server creates without any problem making the same request make other 500 times and got the error, that's why i think there's a bug in the API code). All the procedure is made via nodejs using axios for requests.

The workflow is: (all numbers and strings are invented for the example) -i generate a SSH key {type: 'rsa', size: '4096',} -create it in hetzner via POST /ssh_keys named with the public key and the name of the server plus underscore plus the timestamp (ex: name.server.com_2022-11-09_04:58:40) -test if the key exists using /ssh_keys/{id} and the id is the one the POST /ssh_keys responded me, from this step i check if the name and the id are correct -create the server with this payload in the body of the request: { location: hel1, image: 5924233, name: name.server.com, server_type: 1, ssh_keys:° } ° here i tried: the id as int, string, array of int and array of strings, the name of the SSH key as string and array of strings

the result is: "SSH key 'name.server.com_2022-11-09_04:58:40' not found","code":"invalid_input","details":{"fields":[{"name":"ssh_keys","messages":["SSH key 'name.server.com_2022-11-09_04:58:40' not found"]}] (in this case i used the name but it is perfectly the same when i send the id)

The id and the name that i use is the one i get from POST /ssh_keys initially.

If i try to create a server selecting the SHH key from Hetzner official panel everything works, even if it's not possibile from API. I already tried to set the key as default for that project. I already tried with every combination of image, location and server type. I am sure to use the right API key in the right project with the right access (read+write).

I really can't figure out how to fix this, if i'm doing something wrong or if it's API fault, thanks in advance for your help

giuseppeveneziano avatar Nov 09 '22 16:11 giuseppeveneziano