Binary cache lives inside the install dir, so sfw can't run from a read-only install

Open Beginner friendly
#70 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript, node.js
Domain
cli

Research direction

Start with dist/sfw.mjs, where the issue says the wrapper sets INSTALL_ROOT and creates .sfw-cache; check how it chooses and prepares the binary cache. The report proposes an SFW_CACHE_DIR override and a user cache directory fallback when the install directory is unwritable. Done when sfw can run from a read-only install without an existing cached binary; the issue names no test file or command.

Written by the indexing model from the issue text.

Description

The sfw npm wrapper downloads the firewall binary into .sfw-cache right next to the installed package (INSTALL_ROOT in dist/sfw.mjs). If that directory isn't writable, every invocation dies before doing anything:

$ sfw npx --version
[sfw] Failed to prepare firewall binary: ENOENT: no such file or directory, mkdir '/nix/store/...-sfw-2.0.6/lib/node_modules/sfw/.sfw-cache'

I hit this on NixOS, where the package lives in the read-only Nix store, so sfw is broken on first run, not just when it tries to self-update. But it's the same class of problem as SocketDev/sfw-free#12 (global install as root, then running as a normal user). That issue is closed now and the SFW_SKIP_UPDATE_CHECK=1 workaround doesn't help here, since there is no cached binary to fall back to.

Would you take a patch (or add support) for an override like SFW_CACHE_DIR, defaulting to something under the user's cache dir when the install dir isn't writable? On my end I patched the bundled sfw.mjs to check process.env.SFW_CACHE_DIR first and default the wrapper to $HOME/.cache/sfw, which fixes it, but it would be better coming from upstream so distro packagers don't each carry their own hack.

Dominant language
No language data
Stars
271
Forks
8
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SocketDev/sfw-free

All issues in SocketDev/sfw-free

Similar issues

More CLI issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.