From 4b54e50a0d01954371a04a8e4405710656f4c59b Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Fri, 3 Apr 2026 09:32:52 -0700 Subject: [PATCH] Make database chmod best-effort for rootless podman MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit os.Chmod(path, 0600) fails inside rootless podman containers because fchmod is denied in the user namespace. This was fatal — the database wouldn't open, crashing the service. Changed to best-effort: log nothing on failure, database functions correctly without the permission tightening. The file is already protected by the container's volume mount and the host filesystem permissions. Root cause of the 2026-04-03 incident recovery failure — MCR and Metacrypt couldn't start until their databases were deleted and recreated. Co-Authored-By: Claude Opus 4.6 (1M context) --- db/db.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/db/db.go b/db/db.go index 2ab1b32..81362c7 100644 --- a/db/db.go +++ b/db/db.go @@ -65,11 +65,11 @@ func Open(path string) (*sql.DB, error) { // connection to serialize all access and eliminate busy errors. database.SetMaxOpenConns(1) - // Ensure permissions are correct even if the file already existed. - if err := os.Chmod(path, 0600); err != nil { - _ = database.Close() - return nil, fmt.Errorf("db: chmod %s: %w", path, err) - } + // Best-effort permissions tightening. This may fail inside rootless + // podman containers where fchmod is denied in the user namespace. + // The database still functions correctly without it. + // See: log/2026-04-03-uid-incident.md + _ = os.Chmod(path, 0600) return database, nil } @@ -168,9 +168,7 @@ func Snapshot(database *sql.DB, destPath string) error { return fmt.Errorf("db: snapshot: %w", err) } - if err := os.Chmod(destPath, 0600); err != nil { - return fmt.Errorf("db: chmod snapshot %s: %w", destPath, err) - } + _ = os.Chmod(destPath, 0600) // best-effort; may fail in rootless containers return nil }