Skip to content

Instantly share code, notes, and snippets.

@ca4ti
Forked from jaytaylor/LXC-LXD-2.x-curl-API.md
Created September 8, 2024 14:19
Show Gist options
  • Save ca4ti/80c5705d7f14006569dff02049934c55 to your computer and use it in GitHub Desktop.
Save ca4ti/80c5705d7f14006569dff02049934c55 to your computer and use it in GitHub Desktop.
HOWTO: Curl the LXD unix.socket file.

It is possible to use curl to query the LXD unix.socket directly:

curl --unix-socket /var/lib/lxd/unix.socket http:/1.0/containers | jq .

Example output:

{
  "type": "sync",
  "status": "Success",
  "status_code": 200,
  "operation": "",
  "error_code": 0,
  "error": "",
  "metadata": [
    "/1.0/containers/base",
    "/1.0/containers/jay-test-99",
    "/1.0/containers/jays-awesome-container-2"
  ]
}
@ca4ti
Copy link
Author

ca4ti commented Sep 8, 2024

@ca4ti
Copy link
Author

ca4ti commented Sep 8, 2024

sudo lxc config set core.https_address [::]:8443 # , it can be your port of choice.
sudo lxc config set core.https_allowed_origin "*" # Ideally replace the start with the domain from with the API would be accessed. * would make it accessible from everywhere.
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

openssl genrsa -out lxd-webui.key 4096 #, this would generate a private key for you.
openssl req -new -key lxd-webui.key -out lxd-webui.csr #, This would create a certificate request.
openssl x509 -req -days 3650 -in lxd-webui.csr -signkey lxd-webui.key -out lxd-webui.crt #. Generate an auto signed certificate.
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"# , #This would export the keys in .pfx format that can be used inside browser for authentication.
#Now download the lxd-webui.pfx file. Locally.

lxc config trust add lxd-webui.crt

@ca4ti
Copy link
Author

ca4ti commented Sep 8, 2024

@ca4ti
Copy link
Author

ca4ti commented Sep 8, 2024

@ca4ti
Copy link
Author

ca4ti commented Sep 8, 2024

I know that this is an old question, but for someone ending up here while searching for how to copy files between host and container, this might help.

To pull a file 'my-file' from the container 'container-name' to the current folder, use:

lxc file pull container-name/any-path/my-file .
To push 'my-file', use:

lxc file push my-file container-name/any-path/
To push a folder 'my-dir' recursive, use:

lxc file push -r my-dir container-name/any-path/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment