"sshkeys":"invalid format - invalid urlencoded string

LexyJexon

New Member
Apr 21, 2023
4
1
1
Hello everyone! I'm trying to set template's cloud-init configs via proxmox-api-go package's proxmox.Client.SetVmConfig() method. I need to set username, password, ssh-key and network configs. I created variable map[string]interface{} with content:
{
"ipconfig0": NewNet0Cfg,
"ciuser": username,
"cipassword": password,
"sshkeys": encodedKey,
}

all these keys's values hane type string
I have problem only whith sshkey. First I created variable SshKey := "ssh-rsa AAAAB3...."
Then I tried to urlencode it wirh net/url package :
encodedKey := url.QueryEscape(SshKey)
But when I call SetVmConfig() method I get this responce:
RESULT:
HTTP/1.1 400 Parameter verification failed.
Connection: close
Content-Length: 698
Cache-Control: max-age=0
Content-Type: application/json;charset=UTF-8
Date: Fri, 21 Apr 2023 11:57:08 GMT
Expires: Fri, 21 Apr 2023 11:57:08 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
{"errors":{"sshkeys":"invalid format - invalid urlencoded string: ssh-rsa+AAAAB3NzaC1yc2EAAAADAQABAAABgQD02Ls76J6njonSYyWAovbUYJnLrNzt%2F6fiXZp1Pbae0egMTb8UgdOrecharIy6EKLmjCGfyZs8Klhg%2BEaDA9O8iTRn%2BHpRUrJhmFdxwaraQ2xEvL6slburbu9vB3vgJxT0oFAHW4osobLPXrZ%2BYZHRZjK9zi%2BW%2FxnLJZFOokWAWKCbYa52%2B7i%2Fk5a605LkZnbO5So3urTurvmdAD7mgBDyngQ2dCUajoAE8RW4aUfkfJoTd9aS6x663%2F19jtR3iyOMsaAxIw4QbRLK3%2FEZBA88cySYglx8xzy4tSXwag1KxXHrWNqiE%2BYSRuhHybfeL22ZXwDmx3zWMLgfZDu3bcOX%2FifVOpCqTMPECT03lIX1HBF%2FSTJQN0IVKPyFFOzLmAfge%2BaP3DopjEL2JHAsA9BSKETO76IeAZNtcKt%2FAFs5KugqMxCLIWQ0Q4uyFp8bJ2f8DOLDV8VvOeHM9aaVOhbXZ%2Fe%2FM%2BmsmV8cl1CWex3kWG7CZLq77FDR1d7qbhfYVH8%3D+kochevoy%40kochevoy-gen2\n"},"data":null}
Can you help me solve this problem please?
 
  • Like
Reactions: iamralf
seems like you have a newline (\n) at the end of your sshkeys string, which seems to be the problem since \ is not valid in an urlencoded string - you should probably remove it completely
 
seems like you have a newline (\n) at the end of your sshkeys string, which seems to be the problem since \ is not valid in an urlencoded string - you should probably remove it completely
Thanks for your reply, I tried to remove \n from the end of string with my ssh key with strings.TrimRight(encodedKey, "\n") But problem still exists.
In request there is no \n:
REQUEST: POST /api2/json/nodes/hw-proxmox-it-2/qemu/109/config
HTTP/1.1 Host: hw-proxmox-it-2.alahd.kz.prod.bash.kz:8006
User-Agent: Go-http-client/1.1
Content-Length: 856
Accept: application/json
Authorization: PVEAuthCookie=PVE:testapi@pve:64461157::kacbwCcbzHnrFrWQ80sGeFWuM67MawiEDBTy4GVDuHs/vH8kii6hP/MmZxg1cf+y9uPhmzTk4ez453Ex1Uvi119XrcQILVLZtrXjFlh3akecV50TxpU3RITtCzD4zLpIcDEKMbc7xj7xGyIFrYC5RYWYmpE/77dl41rT7/qKvGgqhs9DL8ZVyKP1c1VKY6KY6yoq/zMM2uAEyaNlNSSYqzaFgKFQH/7kgyurOyLzJOUQZv+67YP9myPR+dbX7aeKWPiSlM+pdl852GyjFkszSuVEj0R7d+yT1XYyF5FjlveDn202wEDdeXZzfN3Syf5YtQC9oFKKsJsgogBgh8ZUpQ== CSRFPreventionToken: 64461157:pb3Gw/C0zX7kwSVZDdX0vQVAjdvNn9O2N6+hRg3v0RM
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip cipassword=%246%24FhcddHFVZ7ABA4Gi%24l.35ro0JtgQOVq6x9VP7pA2SDYWIAGMWJPCXD1zjIheQn8bnMNjIlrrpfv5ZkhNbbJR2YzBALsDV2kO7Q4jeS1&ciuser=adm-jira&ipconfig0=ip%3D10.7.7.242%2F24%2Cgw%3D10.7.7.254&sshkeys=ssh-rsa%2BAAAAB3NzaC1yc2EAAAADAQABAAABgQD02Ls76J6njonSYyWAovbUYJnLrNzt%252F6fiXZp1Pbae0egMTb8UgdOrecharIy6EKLmjCGfyZs8Klhg%252BEaDA9O8iTRn%252BHpRUrJhmFdxwaraQ2xEvL6slburbu9vB3vgJxT0oFAHW4osobLPXrZ%252BYZHRZjK9zi%252BW%252FxnLJZFOokWAWKCbYa52%252B7i%252Fk5a605LkZnbO5So3urTurvmdAD7mgBDyngQ2dCUajoAE8RW4aUfkfJoTd9aS6x663%252F19jtR3iyOMsaAxIw4QbRLK3%252FEZBA88cySYglx8xzy4tSXwag1KxXHrWNqiE%252BYSRuhHybfeL22ZXwDmx3zWMLgfZDu3bcOX%252FifVOpCqTMPECT03lIX1HBF%252FSTJQN0IVKPyFFOzLmAfge%252BaP3DopjEL2JHAsA9BSKETO76IeAZNtcKt%252FAFs5KugqMxCLIWQ0Q4uyFp8bJ2f8DOLDV8VvOeHM9aaVOhbXZ%252Fe%252FM%252BmsmV8cl1CWex3kWG7CZLq77FDR1d7qbhfYVH8%253D%2Bkochevoy%2540kochevoy-gen2
I think it appears only in response output, and problem in anything alse, I still need help.
 
I too was having this problem when using go's url.QueryEscape() function to encode an ssh key. The problem is that spaces are encoded as "+" so to get around this you can do something like the following:
Code:
strings.Replace(url.QueryEscape(sshKey), "+", "%20", 1)
 
Hello everyone! I'm trying to set template's cloud-init configs via proxmox-api-go package's proxmox.Client.SetVmConfig() method. I need to set username, password, ssh-key and network configs. I created variable map[string]interface{} with content:
{
"ipconfig0": NewNet0Cfg,
"ciuser": username,
"cipassword": password,
"sshkeys": encodedKey,
}

all these keys's values hane type string
I have problem only whith sshkey. First I created variable SshKey := "ssh-rsa AAAAB3...."
Then I tried to urlencode it wirh net/url package :
encodedKey := url.QueryEscape(SshKey)
But when I call SetVmConfig() method I get this responce:
RESULT:
HTTP/1.1 400 Parameter verification failed.
Connection: close
Content-Length: 698
Cache-Control: max-age=0
Content-Type: application/json;charset=UTF-8
Date: Fri, 21 Apr 2023 11:57:08 GMT
Expires: Fri, 21 Apr 2023 11:57:08 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
{"errors":{"sshkeys":"invalid format - invalid urlencoded string: ssh-rsa+AAAAB3NzaC1yc2EAAAADAQABAAABgQD02Ls76J6njonSYyWAovbUYJnLrNzt%2F6fiXZp1Pbae0egMTb8UgdOrecharIy6EKLmjCGfyZs8Klhg%2BEaDA9O8iTRn%2BHpRUrJhmFdxwaraQ2xEvL6slburbu9vB3vgJxT0oFAHW4osobLPXrZ%2BYZHRZjK9zi%2BW%2FxnLJZFOokWAWKCbYa52%2B7i%2Fk5a605LkZnbO5So3urTurvmdAD7mgBDyngQ2dCUajoAE8RW4aUfkfJoTd9aS6x663%2F19jtR3iyOMsaAxIw4QbRLK3%2FEZBA88cySYglx8xzy4tSXwag1KxXHrWNqiE%2BYSRuhHybfeL22ZXwDmx3zWMLgfZDu3bcOX%2FifVOpCqTMPECT03lIX1HBF%2FSTJQN0IVKPyFFOzLmAfge%2BaP3DopjEL2JHAsA9BSKETO76IeAZNtcKt%2FAFs5KugqMxCLIWQ0Q4uyFp8bJ2f8DOLDV8VvOeHM9aaVOhbXZ%2Fe%2FM%2BmsmV8cl1CWex3kWG7CZLq77FDR1d7qbhfYVH8%3D+kochevoy%40kochevoy-gen2\n"},"data":null}
Can you help me solve this problem please?
I get virtually the same error when sending an sshkey via URI in Ansible. There is no \n or "+" in the variable after {{ | urlencode }}.
But in the error message, as in the error output above, a \n is appended to the string.
How can I fix the error at all? Thanks for any help!

Ansible task:
- name: configure vm
uri:
url: "https://{{ server_url }}:8006/api2/json/nodes/{{ node }}/qemu/{{ vmid_next | trim }}/config"
method: POST
return_content: yes
body_format: json
use_proxy: no
validate_certs: no
timeout: 5
headers:
Authorization: "PVEAPIToken=..."
Content-Type: "application/json"
body:
vmid: "{{ vmid_next | trim }}"
[...]
ciuser: "{{ inventory_settings__pve_vm_username }}"
sshkeys: "{{ inventory_settings__pve_vm_public_key | trim | urlencode }}"
[...]
 
Last edited:
seems like you have a newline (\n) at the end of your sshkeys string, which seems to be the problem since \ is not valid in an urlencoded string - you should probably remove it completely
Stefan, can you check my issue (same with "\n") one line above (Monday) ? Thanks!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!