v0.328.0 (unreleased): live finding on 9201 (rc.4) — roots resolved through their nearest existing ancestor; no symlink resolve for the placeholder check
gates / gates (push) Successful in 45s
gates / gates (push) Successful in 45s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
@@ -548,8 +548,9 @@ func (c *checker) underRoot(p string) bool {
|
||||
return false
|
||||
}
|
||||
for _, r := range c.roots {
|
||||
rr, rerr := c.p.Resolve(r)
|
||||
if rerr == nil && within(rp, rr) {
|
||||
// A root is resolved the same way (nearest existing ancestor): a drive folder not created yet must not make
|
||||
// every bind under it "outside" (found live on 9201 with rc.4: every not-installed app refused).
|
||||
if rr, ok := c.resolveExisting(r); ok && within(rp, rr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,3 +417,24 @@ func TestAdmit_HDDPathRootIsAppdataOnly(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Found live on 9201 (rc.4): with Resolve set, roots that do not exist yet (a drive folder not created, or the
|
||||
// placeholder env) made every bind "outside". A root is resolved through its nearest existing ancestor too.
|
||||
func TestAdmit_RootsThatDoNotExistYet(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, "mnt", "felhom-drives"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resolve := func(s string) (string, error) {
|
||||
r, err := filepath.EvalSymlinks(filepath.Join(root, s))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
rel, _ := filepath.Rel(root, r)
|
||||
return "/" + rel, nil
|
||||
}
|
||||
c := "services:\n app:\n image: x/y:1\n volumes:\n - ${USERDATA_PATH}/media:/m\n - ${HDD_PATH}/appdata/app:/c\n"
|
||||
if err := Admit("app", []byte(c), PlaceholderEnv(), Policy{Resolve: resolve}); err != nil {
|
||||
t.Fatalf("binds under roots that do not exist yet were refused: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,14 @@ func (m *Manager) policyEnv(env map[string]string) map[string]string {
|
||||
// app's refusal line.
|
||||
func (m *Manager) admitCompose(name string, data []byte, env map[string]string) error {
|
||||
e := privpolicy.PlaceholderEnv()
|
||||
pol := privpolicy.Policy{SystemDataPath: m.sysDataPath}
|
||||
if env != nil {
|
||||
e = m.policyEnv(env)
|
||||
// Resolve (real paths only — the placeholder env names no real folder): a bind source that is a symlink out
|
||||
// of its data root is outside; it is judged where it points.
|
||||
pol.Resolve = filepath.EvalSymlinks
|
||||
}
|
||||
// Resolve: a bind source that is a symlink out of its data root is outside (it is judged where it points).
|
||||
err := privpolicy.Admit(name, data, e, privpolicy.Policy{SystemDataPath: m.sysDataPath, Resolve: filepath.EvalSymlinks})
|
||||
err := privpolicy.Admit(name, data, e, pol)
|
||||
m.noteAdmission(name, data, err)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user