我试图通过networking访问LXD REST API。
遵循: 链接到Doc 。
lxc config set core.https_address "[::]:8443" lxc config set core.trust_password <some random password> curl -s -k --cert ~/.config/lxc/client.crt --key ~/.config/lxc/client.key https://127.0.0.1:8443/1.0/certificates -X POST -d '{"type": "client", "password": "some-password"}' | jq 如此处所述,官方的REST API Doc。
GET to / is allowed for everyone (lists the API endpoints)
但指向浏览器(Chrome)
http://<server-ip>:8443 https://<server-ip>:8443 两者都导致ERR_INVALID_HTTP_RESPONSE 。
添加client.crt到Windows 10authentication,通过Chrome>设置>pipe理authentication和导入。
用POSTMAN试了一下
仍是同样的问题。
从服务器内部访问时,工作都很好。
curl -s -k --cert ~/.config/lxc/client.crt --key ~/.config/lxc/client.key https://127.0.0.1:8443/1.0 | jq .metadata.auth
上面的命令工作正常。
我对基于证书的身份validation的理解是非常有限的。 任何指针将非常感激。
通过大量的试验和错误。 我终于偶然发现了这个链接 。 这是LXDconfiguration工作的一部分。 以下是我遵循的步骤。
安装ZFS , LXD然后执行sudo LXD init来完成正常的configuration。
之后,
sudo lxc config set core.https_address [::]:8443 ,它可以是你的select端口。 sudo lxc config set core.https_allowed_origin "*"理想情况下用API访问将开始replace为域。 *将使其无处不在。 sudo lxc config set core.https_allowed_methods "GET, POST, PUT, DELETE, OPTIONS" sudo lxc config set core.https_allowed_headers "Content-Type" sudo service lxd restart # sometimes is required mkdir lxd-api-access-cert-key-files cd lxd-api-access-cert-key-files 这只是为了将与身份validation相关的文件保存在一个单独的目录中。
openssl genrsa -out lxd-webui.key 4096 ,这会为你生成一个私钥。 openssl req -new -key lxd-webui.key -out lxd-webui.csr ,这将创build一个证书请求。 openssl x509 -req -days 3650 -in lxd-webui.csr -signkey lxd-webui.key -out lxd-webui.crt 。 生成一个自动签名的证书。 openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in lxd-webui.crt -inkey lxd-webui.key -out lxd-webui.pfx -name "LXD WebUI" ,这将导出可以在浏览器内用于validation的.pfx格式的密钥。 lxd-webui.pfx文件。 本地。 lxc config trust add lxd-webui.crt LXC使用此证书进行身份validation。 https://[serveri-ip]:[port-defined-earlier]/1.0/networks 这应该会给出类似于下面的回答{"type":"sync","status":"Success","status_code":200,"operation":"","error_code":0,"error":"","metadata":["/1.0/networks/lo","/1.0/networks/ens33","/1.0/networks/lxdbr0"]}