fix: chown migrated legacy storage entries to dokku

`SaveEntry` and `touchMigrationFlag` wrote files via `os.WriteFile` and `os.Create` and never chowned them, so the install-time legacy-mount migration produced root-owned `legacy-*.json` files in `/var/lib/dokku/data/storage-registry/entries/`. The dokku user that runs `ps:rebuild` could not read them and every rebuild on a 0.37.x to 0.38.0 upgrade failed with permission denied. The companion `repairRegistryOwnership` pass in `TriggerInstall` rewrites ownership across the whole registry tree so installs that already ran the buggy code are fixed on the next package upgrade, since the per-app migration flag would otherwise cause `MigrateLegacyMounts` to skip the broken files forever.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-05-02 05:37:11 -04:00
1 parent cdfcd4d2c8
commit 179d09fdd5
7 files changed
+168 -24

No files matched your search

+30
View File
@@ -50,6 +50,10 @@ func TriggerInstall() error {
}
}
if err := repairRegistryOwnership(); err != nil {
return fmt.Errorf("Unable to repair storage registry ownership: %s", err.Error())
}
if err := MigrateLegacyMounts(); err != nil {
return fmt.Errorf("storage migration failed: %w", err)
}
@@ -73,6 +77,32 @@ func TriggerInstall() error {
return nil
}
// repairRegistryOwnership rewrites ownership on every regular file under
// the registry tree so the dokku user can read entry / migration-flag
// files. Earlier 0.38 builds wrote those files as root because SaveEntry
// and touchMigrationFlag bypassed the permission helpers; on an upgrade
// the per-app migration flag short-circuits MigrateLegacyMounts so a
// plain SaveEntry fix would leave the broken files in place. The walk is
// idempotent: calling SetPermissions on a file already owned by the
// target user produces a no-op chown.
func repairRegistryOwnership() error {
return filepath.Walk(RegistryDirectory(), func(path string, info os.FileInfo, err error) error {
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
if info.IsDir() {
return nil
}
return common.SetPermissions(common.SetPermissionInput{
Filename: path,
Mode: info.Mode().Perm(),
})
})
}
// TriggerPostDelete removes the attachment store for an app that's being
// destroyed. Entries are global and survive app deletion. The whole
// per-app property folder goes away rather than being rewritten as