Error: LXD unix socket "/var/snap/lxd/common/lxd/unix.socket" not accessible: permission denied

Failed on linux arm64

https://github.com/picguard/picguard/actions/runs/10467052689/job/28985058227

log:

If this is your first time running LXD on this machine, you should also run: lxd init

Error: LXD unix socket "/var/snap/lxd/common/lxd/unix.socket" not accessible: permission denied
Error: Process completed with exit code 1.

workflow.yml

name: Test Linux Snapcraft (arm64)

on:
  workflow_dispatch:

# Declare default permissions as readonly.
permissions: read-all

jobs:
  snap:
    name: Create linux snap (aarch64)
    runs-on: buildjet-4vcpu-ubuntu-2204-arm
    env:
      LXD_GROUP: lxd
    steps:
      - uses: actions/checkout@v4

      - name: Install yq
        run: |
          if ! command -v yq >/dev/null 2>&1; then
            echo "yq not exists"
            sudo snap install -y yq
          fi
          yq --version
      - name: Configure .env
        run: |
          echo "$ENV_KEY" | base64 --decode > .env
        env:
          ENV_KEY: ${{ secrets.ENV_STG_BASE64 }}

      - name: Setup LXD
        uses: canonical/setup-lxd@main
        with:
          group: ${{ env.LXD_GROUP }}
          channel: latest/stable

      - name: Add user to the LXD (lxd) group
        run: |
          sudo usermod -a -G $LXD_GROUP $USER
          sudo snap services --global lxd
          newgrp $LXD_GROUP
          getent group $LXD_GROUP
      - name: Check LXD status
        run: lxc launch ubuntu:22.04 testlxd

      - name: Update snapcraft.yaml
        run: |
          rm -f snap/snapcraft.yaml
          mv snap/snapcraft-arm64.yaml snap/snapcraft.yaml
      - name: Install snapcraft
        run: sudo snap install snapcraft --classic

      - name: Build snap
        run: |
          # https://snapcraft.io/docs/flutter-applications
          version=$(yq '.version' pubspec.yaml)
          snapcraft --output "picguard_"$version"_linux_aarch64.snap"
      # Package the build.
      - name: Copy build for snap
        run: ls -la *.snap

      - uses: actions/upload-artifact@v4
        with:
          name: linux-snap-artifact
          path: |
            ./*.snap
      - name: Clean up
        if: ${{ always() }}
        run: |
          rm -f .env
          if which snapcraft >/dev/null 2>&1; then
            echo "snapcraft exists"
            snapcraft clean
          fi

Hi ! @kimmy214 .

Can you execute the init process before (only once for a vm or container) ?

lxd init


If this is the case, assign some perms and try again :

sudo usermod -aG lxd $USER

The following code contains the lxd init command

      - name: Setup LXD
        uses: canonical/setup-lxd@main
        with:
          group: ${{ env.LXD_GROUP }}
          channel: latest/stable

The following code contains the sudo usermod -a -G $LXD_GROUP $USER command, LXD_GROUP is an environment variable, and its value is lxd

      - name: Add user to the LXD (lxd) group
        run: |
          sudo usermod -a -G $LXD_GROUP $USER
          sudo snap services --global lxd
          newgrp $LXD_GROUP
          getent group $LXD_GROUP

Unless I’m mistaken, this part of the code seems incorrect, you added the user to the group before the group was even created or existed :face_with_monocle: :

 - name: Add user to the LXD (lxd) group
        run: |
          sudo usermod -a -G $LXD_GROUP $USER
          sudo snap services --global lxd
          newgrp $LXD_GROUP
          getent group $LXD_GROUP

The following code is to set the group

sudo snap set lxd daemon.group=${{ inputs.group }}

@kimmy214 Okay, I see .

@kimmy214, can you show the output of this command?

ls    -l    /var/snap/lxd/common/lxd/unix.socket

And this command too :

sudo systemctl status snapd

sudo snap services lxd
Run ls -l /var/snap/lxd/common/lxd/unix.socket
  ls -l /var/snap/lxd/common/lxd/unix.socket
  shell: /usr/bin/bash -e {0}
  env:
    LXD_GROUP: lxd
srw-rw---- 1 root lxd 0 Aug 20 11:30 /var/snap/lxd/common/lxd/unix.socket
Run sudo systemctl status snapd
â—Ź snapd.service - Snap Daemon
     Loaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2024-08-20 11:35:53 UTC; 23s ago
TriggeredBy: â—Ź snapd.socket
   Main PID: 1518 (snapd)
      Tasks: 12 (limit: 6132)
     Memory: 265.3M
        CPU: 9.996s
     CGroup: /system.slice/snapd.service
             └─1518 /usr/lib/snapd/snapd

Aug 20 11:35:53 ubuntu systemd[1]: Started Snap Daemon.
Aug 20 11:36:01 ubuntu snapd[1518]: storehelpers.go:923: cannot refresh: snap has no updates available: "core20", "snapd"
Aug 20 11:36:03 ubuntu snapd[1518]: services.go:1043: RemoveSnapServices - socket snap.lxd.daemon.unix.socket
Aug 20 11:36:03 ubuntu snapd[1518]: services.go:1067: RemoveSnapServices - disabling snap.lxd.daemon.service
Aug 20 11:36:03 ubuntu snapd[1518]: services.go:1067: RemoveSnapServices - disabling snap.lxd.activate.service
Aug 20 11:36:03 ubuntu snapd[1518]: services.go:1043: RemoveSnapServices - socket snap.lxd.user-daemon.unix.socket
Aug 20 11:36:03 ubuntu snapd[1518]: services.go:1067: RemoveSnapServices - disabling snap.lxd.user-daemon.service
Aug 20 11:36:07 ubuntu snapd[1518]: storehelpers.go:923: cannot refresh snap "lxd": snap has no updates available
Aug 20 11:36:07 ubuntu snapd[1518]: api_general.go:246: Cannot get snap-name for change 1
Aug 20 11:36:07 ubuntu snapd[1518]: api_general.go:246: Cannot get snap-name for change 2
Unit lxd.service could not be found.
Error: Process completed with exit code 4.

@kimmy214 , sorry for the last command, I meant :

sudo snap services lxd

Can I see the output of this one (just above) ?

Service          Startup  Current   Notes
lxd.activate     enabled  inactive  -
lxd.daemon       enabled  active    socket-activated
lxd.user-daemon  enabled  inactive  socket-activated

@kimmy214, everything seems Okay.

I recommend you to add this line in the process to see if the issue will persist:

sudo snap restart lxd

I would like to know if you do this, is that your username appears ?

getent group lxd

It doesn’t work for me.

sudo snap restart lxd

name: Test Linux Snapcraft (arm64)

on:
  workflow_dispatch:

# Declare default permissions as readonly.
permissions: read-all

jobs:
  snap:
    name: Create linux snap (aarch64)
    runs-on: buildjet-4vcpu-ubuntu-2204-arm
    env:
      LXD_GROUP: lxd
    steps:
      - uses: actions/checkout@v4

      - name: Install yq
        run: |
          if ! command -v yq >/dev/null 2>&1; then
            echo "yq not exists"
            sudo snap install -y yq
          fi
          yq --version

      - name: Setup LXD
        uses: canonical/setup-lxd@main
        with:
          group: ${{ env.LXD_GROUP }}
          channel: latest/stable

      - name: Show status
        run: |
          sudo systemctl status snapd
          sudo snap services lxd

      - name: List sockets 
        run: ls -l /var/snap/lxd/common/lxd/unix.socket

      - name: Add user to the LXD (lxd) group
        run: |
          sudo usermod -a -G $LXD_GROUP $USER
          sudo snap services --global lxd
          newgrp $LXD_GROUP
          getent group $LXD_GROUP

      - name: Restart lxd
        run: sudo snap restart lxd

      - name: Check LXD status
        run: lxc launch ubuntu:22.04 testlxd

      - name: Update snapcraft.yaml
        run: |
          rm -f snap/snapcraft.yaml
          mv snap/snapcraft-arm64.yaml snap/snapcraft.yaml

      - name: Install snapcraft
        run: sudo snap install snapcraft --classic

      - name: Build snap
        run: |
          # https://snapcraft.io/docs/flutter-applications
          version=$(yq '.version' pubspec.yaml)
          snapcraft --output "picguard_"$version"_linux_aarch64.snap"

      # Package the build.
      - name: Copy build for snap
        run: ls -la *.snap

      - uses: actions/upload-artifact@v4
        with:
          name: linux-snap-artifact
          path: |
            ./*.snap

      - name: Clean up
        if: ${{ always() }}
        run: |
          rm -f .env
          if which snapcraft >/dev/null 2>&1; then
            echo "snapcraft exists"
            snapcraft clean
          fi

Output: lxd:x:120:runner

@kimmy214, I do not proceed as you do to builde etc… . :slightly_smiling_face:

And if you change the line

run: lxc launch ubuntu:22.04 testlxd

to

run: sudo lxc launch ubuntu:22.04 testlxd

?

Any good suggestions?

It works for me. I also changed this line

snapcraft --output "picguard_"$version"_linux_aarch64.snap"

to

sudo snapcraft --output "picguard_"$version"_linux_aarch64.snap"

1 Like

@kimmy214, so everything is okay ? :face_with_monocle: