Error accessing GPIO chips: Permission denied

Hello,

I'm trying to interact with the GPIOs of a Radxa Rock3A through Node-red.
Node-Red is in a Docker container.
According to what I found on the internet, node-red-contrib-libgpiod are the solution.
The requirements for these nodes are not in the prebuild NodeRED images so I compiled my own image.

Editing Dockerfile.debian, add :

apt install gpiod libgpiod-dev libgpiod-doc libnode-dev
npm i node-libgpiod

Then build the image without problem.
Setting up the container also goes smoothly
my docker compose file :

services:
  node-red:
    container_name: nodered_1
    image: node-red-build:node-red-libgpiod
    privileged: true
    restart: always
    environment:
      - TZ=Europe/Paris
    ports:
      - "1880:1880"
    volumes:
      - node_red_data:/data
    devices:
       - "/dev/gpiochip0:/dev/gpiochip0:rwm"
       - "/dev/gpiochip1:/dev/gpiochip1:rwm"
       - "/dev/gpiochip2:/dev/gpiochip2:rwm"
       - "/dev/gpiochip3:/dev/gpiochip3:rwm"
volumes:
  node_red_data:

The first problem occurs when I want to install the palett "node-red-contrib-libgpiod"

2025-05-09T09:40:52.950Z Installer : node-red-contrib-libgpiod 0.0.1

2025-05-09T09:40:51.244Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --omit=dev --engine-strict node-red-contrib-libgpiod@0.0.1
2025-05-09T09:40:54.395Z [err] npm error code EACCES
2025-05-09T09:40:54.396Z [err] npm error syscall open
2025-05-09T09:40:54.396Z [err] npm error path /data/.npm/_cacache/tmp/e68164e8
2025-05-09T09:40:54.397Z [err] npm error errno EACCES
2025-05-09T09:40:54.398Z [err] npm error
2025-05-09T09:40:54.398Z [err] npm error Your cache folder contains root-owned files, due to a bug in
2025-05-09T09:40:54.398Z [err] npm error previous versions of npm which has since been addressed.
2025-05-09T09:40:54.398Z [err] npm error
2025-05-09T09:40:54.398Z [err] npm error To permanently fix this problem, please run:
2025-05-09T09:40:54.398Z [err] npm error   sudo chown -R 1000:1000 "/data/.npm"
2025-05-09T09:40:54.403Z [err] npm error Log files were not written due to an error writing to the directory: /data/.npm/_logs
2025-05-09T09:40:54.403Z [err] npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
2025-05-09T09:40:54.424Z rc=1

I therefore apply the proposed solution (loged as root inside the container)

chown -R 1000:1000 "/data/.npm"

And the pallet installs correctly (Is the proposed solution correct?)

Then I place a node from this palett on the flow (ie. "GPIO in") with a correct setting like

  • device : gpiochip1
  • pin : 0
  • name : pin-03

then I deploy the flow. This is where I have a second problem. The node indicates "Unable to open device"

If in the container console i run "gpioinfo" as root, the command return the list of the gpio in the /dev/gpiochip but the same command as user node-red return :

gpioinfo: error accessing GPIO chips: Permission denied

So the user running NodeRED (node-red) does not have rights access to peripherals.
After a long search on the internet I found a workaround, running as root :

chmod a+rw /dev/gpiochip*

Then redeploy the flow and it work ! :star_struck:

But there is a third problem that I have not been able to solve.
This workaround is temporary and does not survive a reboot !
How can we make this solution (or an other?) sustainable?

Thank you.