mirror of
https://github.com/dokku/dokku.git
synced 2026-05-18 13:15:19 +02:00
`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.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"os"
|
|
"os/user"
|
|
"strconv"
|
|
"syscall"
|
|
"testing"
|
|
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
// TestRepairRegistryOwnership covers the install-time repair that exists
|
|
// to fix #8557 on systems that already ran the buggy 0.38.0 install. The
|
|
// repair must rewrite ownership without rewriting the file mode, and
|
|
// must tolerate a missing registry tree (clean install).
|
|
func TestRepairRegistryOwnership(t *testing.T) {
|
|
RegisterTestingT(t)
|
|
withTempLibRoot(t)
|
|
|
|
Expect(EnsureEntriesDirectory()).To(Succeed())
|
|
path := entryPath("legacy-deadbeef")
|
|
Expect(os.WriteFile(path, []byte(`{"name":"legacy-deadbeef"}`), 0640)).To(Succeed())
|
|
|
|
Expect(repairRegistryOwnership()).To(Succeed())
|
|
|
|
info, err := os.Stat(path)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(info.Mode().Perm()).To(Equal(os.FileMode(0640)))
|
|
|
|
stat, ok := info.Sys().(*syscall.Stat_t)
|
|
Expect(ok).To(BeTrue())
|
|
|
|
current, err := user.Current()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(strconv.Itoa(int(stat.Uid))).To(Equal(current.Uid))
|
|
|
|
Expect(os.RemoveAll(RegistryDirectory())).To(Succeed())
|
|
Expect(repairRegistryOwnership()).To(Succeed())
|
|
}
|