-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfailopen_no_access_migration_test.go
More file actions
75 lines (69 loc) · 2.65 KB
/
Copy pathfailopen_no_access_migration_test.go
File metadata and controls
75 lines (69 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"go/ast"
"go/parser"
"go/token"
"strings"
"testing"
)
// TestOnlyExplicitInputPersistsAccess pins the rule the removed container
// grandfather broke: main may persist an access decision in exactly ONE place,
// reconcileAccess, and only from an EXPLICITLY passed -access /
// PINGULARITY_ACCESS. Every other route - a store's age, a missing birth
// marker, container detection, the network layout - may advise, never write,
// because each of those is an inference and a wrong inference opens an
// unauthenticated dashboard to the LAN silently.
//
// A behavioral test cannot cover this: it can only check the paths it thought
// to build a fixture for, and the defect was precisely a path (stores born
// private under a build too old to record their birth) nobody had a fixture
// for. Reading the source catches the next such writer wherever it is added.
func TestOnlyExplicitInputPersistsAccess(t *testing.T) {
const setter = "SetAccessLocalOnly"
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "main.go", nil, 0)
if err != nil {
t.Fatalf("parse main.go: %v", err)
}
// enclosing maps a position back to the top-level func it sits in, so a
// violation names the function an operator's access can be written from.
type call struct {
fn string
pos string
}
var calls []call
for _, decl := range file.Decls {
fn, ok := decl.(*ast.FuncDecl)
if !ok || fn.Body == nil {
continue
}
name := fn.Name.Name
ast.Inspect(fn.Body, func(n ast.Node) bool {
sel, ok := n.(*ast.SelectorExpr)
if !ok || sel.Sel.Name != setter {
return true
}
calls = append(calls, call{fn: name, pos: fset.Position(sel.Pos()).String()})
return true
})
}
if len(calls) == 0 {
t.Fatalf("no %s call found in main.go; reconcileAccess is the recovery path for a container locked out of its own published port and must keep persisting explicit operator input", setter)
}
for _, c := range calls {
if c.fn != "reconcileAccess" {
t.Errorf("%s: %s is called from %s; only reconcileAccess (explicit -access/PINGULARITY_ACCESS) may persist an access decision - an inferred one silently exposes the dashboard",
c.pos, setter, c.fn)
}
}
// The removed migration by name, so a revert cannot come back quietly.
for _, decl := range file.Decls {
fn, ok := decl.(*ast.FuncDecl)
if !ok {
continue
}
if strings.Contains(strings.ToLower(fn.Name.Name), "grandfather") {
t.Errorf("%s exists again: the container access grandfather persisted network-reachable access on an inference that cannot distinguish a container born private under a build too old to record its birth from a 0.61-or-earlier one", fn.Name.Name)
}
}
}