JSON-RPC over WebSocket significantly complicates the process. I likely can’t use the ubiquitous cURL so I’ve turned to websocat. After several hours of struggling and revoking like five tokens, this approach seems to be working:
You can use ssh inside the agent to execute a script on the truenas host. Inside the script (post_deploy.sh in the example above) you can use midclt commands as usual.
Currently I have disabled ssh service, but this might work for me. It seems more straightforward to use either. However I have a bit of a problem with configuring ssh, since I don’t want my user configurations like ssh keys etc on storage pools, and truenas gui won’t let me configure home folder for user other than in /mnt. The thing is, I want my administrator users to be able to log in and do stuff even if storage pools are out. I could just configure home folders directly in /etc/passwd, but who knows if that would survive restart/updates etc.