通过networking对LXD rest API进行身份validation,证书身份validation保持失败

我试图通过networking访问LXD REST API。

遵循: 链接到Doc 。

  1. lxc config set core.https_address "[::]:8443"
  2. lxc config set core.trust_password <some random password>
  3. 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工作的一部分。 以下是我遵循的步骤。

安装ZFSLXD然后执行sudo LXD init来完成正常的configuration。

之后,

LXD的configuration

  1. sudo lxc config set core.https_address [::]:8443 ,它可以是你的select端口。
  2. sudo lxc config set core.https_allowed_origin "*"理想情况下用API访问将开始replace为域。 *将使其无处不在。
  3. sudo lxc config set core.https_allowed_methods "GET, POST, PUT, DELETE, OPTIONS"
  4. sudo lxc config set core.https_allowed_headers "Content-Type"
  5. sudo service lxd restart # sometimes is required

设置authentication证书(自签名)

  1. mkdir lxd-api-access-cert-key-files
  2. cd lxd-api-access-cert-key-files

这只是为了将与身份validation相关的文件保存在一个单独的目录中。


  1. openssl genrsa -out lxd-webui.key 4096 ,这会为你生成一个私钥。
  2. openssl req -new -key lxd-webui.key -out lxd-webui.csr ,这将创build一个证书请求。
  3. openssl x509 -req -days 3650 -in lxd-webui.csr -signkey lxd-webui.key -out lxd-webui.crt 。 生成一个自动签名的证书。
  4. 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格式的密钥。
  5. 现在下载lxd-webui.pfx文件。 本地。
  6. 将文件导入浏览器。
    1. Chrome Linux
    2. Chrome Windows
    3. 火狐
  7. lxc config trust add lxd-webui.crt LXC使用此证书进行身份validation。

testing

  • 现在closures并再次启动您的浏览器。
  • 将浏览器指向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"]}