Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot read/write to storage file for Home Assistant nodes #1684

Open
Slyke opened this issue Nov 10, 2024 · 2 comments
Open

Error: Cannot read/write to storage file for Home Assistant nodes #1684

Slyke opened this issue Nov 10, 2024 · 2 comments

Comments

@Slyke
Copy link

Slyke commented Nov 10, 2024

Describe the bug

This looks to be similar to #678.

Being mounted from NFS share on a K8s cluster. I'm using v0.74.2. I upgraded from some ancient version from like 2022.

I have an initContainer that runs on startup:

      initContainers:
      - name: permissions-update
        image: busybox:1.35.0
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh", "-c", "chown -R 1000:1000 /data; chmod -R 770 /data"]
        volumeMounts:
          - mountPath: /data
            name: nodered-data

But also get this error. Here's file info:

Defaulted container "nodered" out of: nodered, permissions-update (init)
nodered-746df95b96-s6zmn:~$ cd /data/
nodered-746df95b96-s6zmn:/data$ ls -ahl
total 1M
drwxrwx---    1 node-red node-red     622 Nov 10 10:56 .
drwxr-xr-x    1 root     root        4.0K Nov 10 10:59 ..
-rwxrwx---    1 node-red node-red   37.8K Nov 10 10:56 .config.nodes.json
-rwxrwx---    1 node-red node-red   34.1K Nov 10 10:56 .config.nodes.json.backup
-rwxrwx---    1 node-red node-red     133 Nov  8 15:24 .config.runtime.json
-rwxrwx---    1 node-red node-red      95 Nov  8 15:24 .config.runtime.json.backup
-rwxrwx---    1 node-red node-red     691 Nov  8 15:25 .config.users.json
-rwxrwx---    1 node-red node-red     691 Nov  8 15:25 .config.users.json.backup
-rwxrwx---    1 node-red node-red  440.5K Nov 10 10:51 .flows.json.backup
-rwxrwx---    1 node-red node-red    5.7K Nov 10 08:00 .flows_cred.json.backup
drwxrwx---    1 node-red node-red     148 Sep 19  2022 .npm
drwxrwx---    1 node-red node-red     108 Jul  4  2023 context
-rwxrwx---    1 node-red node-red  440.3K Nov 10 10:51 flows.json
-rwxrwx---    1 node-red node-red    5.6K Nov 10 08:00 flows_cred.json
drwxrwx---    1 node-red node-red      10 Nov  8  2021 lib
-rwxrwx---    1 node-red node-red       2 Nov 17  2023 node-red-contrib-home-assistant-websocket.json
drwxrwx---    1 node-red node-red    5.7K Nov 10 10:55 node_modules
-rwxrwx---    1 node-red node-red  271.2K Nov 10 10:55 package-lock.json
-rwxrwx---    1 node-red node-red     759 Nov 10 10:55 package.json
-rwxrwx---    1 node-red node-red   20.2K Nov  7  2023 settings.js
nodered-746df95b96-s6zmn:/data$ whoami
node-red
nodered-746df95b96-wthm4:/data$ touch test
nodered-746df95b96-wthm4:/data$ echo "hi" > test2
nodered-746df95b96-wthm4:/data$ cat test2
hi

The node-red-contrib-home-assistant-websocket.json file has an empty JSON object in it: {}. Deleting this file, and restarting NodeRed does not recreate it.

Logs:

(node:7) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
10 Nov 11:12:11 - [info]

Welcome to Node-RED
===================

10 Nov 11:12:11 - [info] Node-RED version: v4.0.5
10 Nov 11:12:11 - [info] Node.js  version: v22.9.0
10 Nov 11:12:11 - [info] Linux 5.15.0-124-generic x64 LE
10 Nov 11:12:12 - [info] Loading palette nodes
10 Nov 11:12:24 - [info] Dashboard version 3.1.2 started at /ui
10 Nov 10:59:49 - [warn] [node-red-contrib-home-assistant-websocket/all] Error: Cannot read/write to storage file for Home Assistant nodes
10 Nov 10:59:49 - [warn] ------------------------------------------------------
10 Nov 10:59:49 - [info] Settings file  : /data/settings.js
10 Nov 10:59:49 - [info] Context store  : 'default' [module=localfilesystem]
10 Nov 10:59:49 - [info] Context store  : 'memoryOnly' [module=memory]
10 Nov 10:59:49 - [info] User directory : /data
10 Nov 10:59:49 - [warn] Projects disabled : editorTheme.projects.enabled=false
10 Nov 10:59:49 - [info] Flows file     : /data/flows.json
10 Nov 10:59:49 - [info] Server now running at http://127.0.0.1:1880/
10 Nov 10:59:49 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

10 Nov 10:59:49 - [info] Waiting for missing types to be registered:
10 Nov 10:59:49 - [info]  - server
10 Nov 10:59:49 - [info]  - api-call-service
10 Nov 10:59:49 - [info]  - api-current-state
10 Nov 10:59:49 - [info]  - trigger-state

Setting chmod 777 in the initContainer does not fix it.

To Reproduce

No response

Expected behavior

Should not error

Screenshots

No response

Example Flow

No response

Environment Information

Node-RED version: v4.0.5
Node.js version: v22.9.0
Linux 5.15.0-124-generic x64 LE

Additional context

No response

@Slyke
Copy link
Author

Slyke commented Nov 10, 2024

My workaround:

Edit file ./node_modules/node-red-contrib-home-assistant-websocket/dist/common/services/StorageService.js:

Change function defined on line 36 checkPermissions() to:

    checkPermissions(path) {
        if (!path)
            return true;
        try {
            fs_1.default.accessSync(path, fs_1.default.constants.R_OK | fs_1.default.constants.W_OK);
        }
        catch (err) {
            // throw new Error('Cannot read/write to storage file for Home Assistant nodes'); // Comment out this line
            // Add these 2 lines:
            console.error('Cannot read/write to storage file for Home Assistant nodes: ', err);
            return true; 
        }
        return true;
    }

The error it produces by the way is:

Cannot read/write to storage file for Home Assistant nodes Error: EACCES: permission denied, access '/data'
    at Object.accessSync (node:fs:243:11)
    at Storage.checkPermissions (/data/node_modules/node-red-contrib-home-assistant-websocket/dist/common/services/StorageService.js:40:26)
    at Storage.init (/data/node_modules/node-red-contrib-home-assistant-websocket/dist/common/services/StorageService.js:56:18)
    at exports.default (/data/node_modules/node-red-contrib-home-assistant-websocket/dist/index.js:84:36)
    at loadNodeSet (/usr/src/node-red/node_modules/@node-red/registry/lib/loader.js:359:27)
    at /usr/src/node-red/node_modules/@node-red/registry/lib/loader.js:453:31
    at Array.forEach (<anonymous>)
    at loadNodeSetList (/usr/src/node-red/node_modules/@node-red/registry/lib/loader.js:448:11)
    at /usr/src/node-red/node_modules/@node-red/registry/lib/loader.js:145:16 {
  errno: -13,
  code: 'EACCES',
  syscall: 'access',
  path: '/data'
}

@cyril-wx
Copy link

cyril-wx commented Dec 18, 2024

Thank you very much, author. Your method is useful. Before this, my “node-red-contrib-home-assistant-websocket” kept prompting packet conflicts and could not be successfully loaded into node red @Slyke
截屏2024-12-19 00 07 54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants