Commit 8e8c03891a

8e8c03891a17798067a8da0a034725bf44ece8d0

parent: fe4290fab4

Verified · cmc

cmc <hello@cleberg.net> · 2026-07-15 16:13 UTC

fix: refuse to start when the cache directory is not writable

An unwritable cache directory degraded silently: media still served, because
the download succeeds before the cache write is attempted, so the only symptom
was one "permission denied" line per request and a cache that never filled.
Every request re-fetched from the CDN.

Probe the directory at startup and exit with the uid and the chown that fixes
it. The container image runs as uid 10000, which is the usual cause with a
bind-mounted cache, so say so in the message and in both compose examples.

Layout: unified · split

SETUP.md +4 −1
@@ -12,7 +12,10 @@ Time units:
1212* `uri` — Instance URI. Example: `"uri":"/art/"` -> https://skunky.ebloid.ru/art/
1313* `cache` — Caching system; default is off.
1414 * `enabled` — Caching system state, requires boolean value
15 * `path` — Path to cache directory, requires absolute filesystem path
15 * `path` — Path to cache directory. It must be writable by the user SkunkyArt
16 runs as, and SkunkyArt refuses to start if it is not. The container image
17 runs as uid 10000, so a bind-mounted cache needs
18 `sudo chown -R 10000:10000 <dir>` on the host.
1619 * `lifetime` — Cached file life time, requires numeric value, followed by multiplicative suffix (see Time Units for details)
1720 * `max-size` — Maximum file size in megabytes
1821 * `update-interval` — Automatic rotation interval
app/config.go +28 −1
@@ -58,9 +58,28 @@ var CFG = config{
5858
5959var lifetimeParsed int64
6060
61// checkCacheWritable creates the cache directory if it is missing and confirms
62// this process can actually write into it, returning the error that a real cache
63// write would hit.
64//
65// An unwritable cache directory is otherwise a silent cliff: every media request
66// still succeeds by re-downloading from the CDN, so the only symptom is one
67// "permission denied" line per request and a cache that never fills.
68func checkCacheWritable(path string) error {
69 if err := os.MkdirAll(path, 0700); err != nil {
70 return err
71 }
72 probe := path + "/.skunkyart-write-probe"
73 if err := os.WriteFile(probe, nil, 0600); err != nil {
74 return err
75 }
76 return os.Remove(probe)
77}
78
6179// ExecuteConfig loads the config file into CFG, validates it, and starts the
6280// cache rotation loop if caching is on. It exits the process on a config that
63// cannot be read or that asks for caching without proxying.
81// cannot be read, that asks for caching without proxying, or that points caching
82// at a directory this process cannot write.
6483func ExecuteConfig() {
6584 if CFG.cfg != "" {
6685 f, err := os.ReadFile(CFG.cfg)
@@ -71,6 +90,14 @@ func ExecuteConfig() {
7190 }
7291
7392 if CFG.Cache.Enabled {
93 if err := checkCacheWritable(CFG.Cache.Path); err != nil {
94 exit("Cache directory is not writable by this process (uid "+
95 strconv.Itoa(os.Getuid())+"): "+err.Error()+
96 "\nGrant that uid write access to the directory, or set cache.enabled to false."+
97 "\nThe official container image runs as uid 10000, so a bind-mounted cache needs:"+
98 "\n chown -R 10000:10000 <cache dir on the host>", 1)
99 }
100
74101 if CFG.Cache.Lifetime != "" {
75102 var duration int64
76103 day := 24 * time.Hour.Milliseconds()
compose.example.yaml +4 −1
@@ -14,4 +14,7 @@ services:
1414 - no-new-privileges:true
1515 volumes:
1616 - ./config.json:/config.json:ro
17 - ./cache:/cache # Ensure cache folder has a 10000:10000 ownership.
17 # The image runs as uid 10000, so the host cache dir must be writable by it:
18 # mkdir -p cache && sudo chown -R 10000:10000 cache
19 # Without this the container exits at startup telling you the same thing.
20 - ./cache:/cache
compose.vpn_example.yml +3 −1
@@ -59,7 +59,9 @@ services:
5959 - no-new-privileges:true
6060 volumes:
6161 - ./config.json:/config.json:ro
62 - ./cache:/cache # ensure this dir is owned 10000:10000
62 # The image runs as uid 10000, so the host cache dir must be writable by it:
63 # mkdir -p cache && sudo chown -R 10000:10000 cache
64 - ./cache:/cache
6365 environment:
6466 # Empty by default = direct. Set SKUNKY_PROXY in .env to route via the VPN.
6567 - HTTPS_PROXY=${SKUNKY_PROXY:-}