From dbe44144990314db2140d03cec23ea46b371e981 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Thu, 2 Oct 2025 23:56:52 +0200 Subject: [PATCH 1/2] feat: Add LXD host socket profile for container management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This profile allows containers to access the host LXD daemon via Unix socket, enabling centralized LXD management from within containers. Features: - Proxy host LXD socket to container at same path - Automatic LXD client installation via snap - No additional configuration required - Practical guide and example script included 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- docs/create-lxd-manager-container.md | 65 +++++++++++++++++++ examples/scripts/create-lxd-manager.bash | 19 ++++++ .../lxd-host-socket.profile.yaml | 18 +++++ 3 files changed, 102 insertions(+) create mode 100644 docs/create-lxd-manager-container.md create mode 100755 examples/scripts/create-lxd-manager.bash create mode 100644 profiles/containerization/lxd-host-socket.profile.yaml diff --git a/docs/create-lxd-manager-container.md b/docs/create-lxd-manager-container.md new file mode 100644 index 0000000..5352b77 --- /dev/null +++ b/docs/create-lxd-manager-container.md @@ -0,0 +1,65 @@ +# Create LXD Manager Container + +## Install Profile + +Install the lxd-host-socket profile : + +```bash +lxc profile create lxd-host-socket +curl https://gitea.cloud.logerais.com/cloud.logerais.com/lxd-profiles/raw/branch/main/profiles/containerization/lxd-host-socket.profile.yaml | lxc profile edit lxd-host-socket +``` + +Or use the local profile: + +```bash +./install.bash profiles/containerization/lxd-host-socket.profile.yaml +``` + +## Launch Container + +Create and start an LXD manager container: + +```bash +lxc launch ubuntu:lts -p default -p lxd-host-socket lxd-manager +``` + +### Fix IP Address (Optional) + +To assign a static IP address: + +```bash +lxc network attach lxdbr0 lxd-manager eth0 eth0 +lxc config device set lxd-manager eth0 ipv4.address 10.0.1.20 +``` + +## Use the Container + +Access the container and manage host LXD: + +```bash +# Wait for cloud-init to complete +lxc exec lxd-manager -- cloud-init status --wait + +# Access the container +lxc shell lxd-manager + +# Inside the container - verify LXD client is installed +lxc version + +# List containers on the host +lxc list + +# Create a new container from the manager +lxc launch ubuntu:22.04 test-container + +# Manage the new container +lxc info test-container +lxc stop test-container +lxc delete test-container +``` + +## Security Warning + +⚠️ **This container has full access to the host LXD daemon**. Use only in trusted environments and limit access to this management container. + +Your LXD manager container is now ready for centralized container management. \ No newline at end of file diff --git a/examples/scripts/create-lxd-manager.bash b/examples/scripts/create-lxd-manager.bash new file mode 100755 index 0000000..a0ef388 --- /dev/null +++ b/examples/scripts/create-lxd-manager.bash @@ -0,0 +1,19 @@ +#!/bin/bash + +CONTAINER_NAME="${1:-lxd-manager}" + +echo "Creating LXD manager container: $CONTAINER_NAME" + +# Install the profile using the helper script +./install.bash profiles/containerization/lxd-host-socket.profile.yaml + +# Launch the container +lxc launch ubuntu:lts -p default -p lxd-host-socket "$CONTAINER_NAME" + +# Wait for cloud-init +echo "Waiting for cloud-init to complete..." +lxc exec "$CONTAINER_NAME" -- cloud-init status --wait + +echo "LXD manager container '$CONTAINER_NAME' is ready!" +echo "Access with: lxc shell $CONTAINER_NAME" +echo "WARNING: This container has full access to host LXD daemon" \ No newline at end of file diff --git a/profiles/containerization/lxd-host-socket.profile.yaml b/profiles/containerization/lxd-host-socket.profile.yaml new file mode 100644 index 0000000..2168b03 --- /dev/null +++ b/profiles/containerization/lxd-host-socket.profile.yaml @@ -0,0 +1,18 @@ +name: lxd-host-socket +description: "Permet à un container d'accéder au démon LXD de l'hôte via le socket Unix" +devices: + lxd-socket: + type: proxy + listen: unix:/var/snap/lxd/common/lxd/unix.socket + connect: unix:/var/snap/lxd/common/lxd/unix.socket + uid: 0 + gid: 0 + mode: "0660" +config: + cloud-init.vendor-data: | + #cloud-config + package_update: true + packages: + - snapd + runcmd: + - snap install lxd --channel=latest/stable \ No newline at end of file -- 2.43.0 From 736d47ee7206bbda56702e0bec9a66196327774a Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Fri, 3 Oct 2025 00:15:18 +0200 Subject: [PATCH 2/2] fix: Use ubuntu:lts for consistency in documentation examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace ubuntu:22.04 with ubuntu:lts in test container creation example to maintain consistency with other examples in the documentation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- docs/create-lxd-manager-container.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/create-lxd-manager-container.md b/docs/create-lxd-manager-container.md index 5352b77..4bd1243 100644 --- a/docs/create-lxd-manager-container.md +++ b/docs/create-lxd-manager-container.md @@ -50,7 +50,7 @@ lxc version lxc list # Create a new container from the manager -lxc launch ubuntu:22.04 test-container +lxc launch ubuntu:lts test-container # Manage the new container lxc info test-container -- 2.43.0