apppolicy: own the size names instead of importing internal/cgroup, which cut the cgroup test package's import cycle; README: egress allows are for wholly nested boxes (#328, #329)
internal/cgroup's tests reach apppolicy through hostbox and provision, and apppolicy imported cgroup for SizeByName, so go test ./internal/cgroup did not build (since d3757ae7). apppolicy now keeps the size names it accepts, and TestSizeNamesAreCgroupSizes holds them equal to cgroup.Sizes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+49
−3
README.md+1 −0internal/apppolicy/apppolicy.go+19 −3internal/apppolicy/sizenames_test.go+29 −0
diff --git a/README.md b/README.md| index fcdf6bafe..1995e7c72 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -517,6 +517,7 @@ Roll it in this order: |
| This release adds the app policy (#328, #329). A system operator can let an app's instances reach named private addresses with `carlos apps set --egress-allow`, and choose the size they run at with `carlos apps set --size` and `carlos instances set --size`. `carlos apps show` reads it back. Each app's policy is one signed object in the deployment bucket, under `control/app-policy/`. |
| - with nothing granted, this release changes nothing. there is no policy until an operator sets one, and every box runs its instances as it does today. |
| +- egress allows are meant for boxes where every tenant runs nested: on a box still running flat tenants the platform refuses them, and until host claims are on that check is a safeguard rather than a boundary. |
| - roll boxes first, then consoles, and dev first, as always. |
| - every console that writes the deployment bucket must run this release before anyone grants the first policy. an older console leaves the policy in place when it purges an app or creates one, so a new app with an old app's name could inherit its egress allow and size. |
| - one console per bucket writes policies. it holds a lease at `control/app-policy-lease/lock.json`, taken the first time it creates an app or changes a policy, and renewed every five minutes after that. a second console on the same bucket refuses both, and names the console that holds the lease and when it expires. |
diff --git a/internal/apppolicy/apppolicy.go b/internal/apppolicy/apppolicy.go| index 73013cd92..8b05743f9 100644 |
| --- a/internal/apppolicy/apppolicy.go |
| +++ b/internal/apppolicy/apppolicy.go |
| @@ -19,7 +19,6 @@ import ( |
| "strings" |
| "time" |
| - "github.com/carlosframework/platform/internal/cgroup" |
| "github.com/carlosframework/platform/internal/controlname" |
| "github.com/carlosframework/platform/internal/egressaddr" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -28,6 +27,23 @@ import ( |
| // Prefix is where every app's policy lives in the deployment bucket. |
| const Prefix = release.AppPolicyPrefix |
| +// sizeNames is cgroup.Sizes' names, in table order: the size names a policy |
| +// may carry. The list is this package's own so that apppolicy does not |
| +// import internal/cgroup, whose tests reach apppolicy through hostbox and |
| +// provision (an import cycle in test). TestSizeNamesAreCgroupSizes holds the |
| +// two equal. |
| +var sizeNames = []string{"small", "standard", "large", "xlarge"} |
| + |
| +// validSize is whether name is one of sizeNames, matched exactly. |
| +func validSize(name string) bool { |
| + for _, n := range sizeNames { |
| + if n == name { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // Key is one app's policy object. |
| func Key(sqid, app string) string { return release.AppPolicyKey(sqid, app) } |
| @@ -63,7 +79,7 @@ func (p Policy) Validate() error { |
| return fmt.Errorf("%w: version %d", ErrInvalid, p.V) |
| } |
| if p.DefaultSize != "" { |
| - if _, ok := cgroup.SizeByName(p.DefaultSize); !ok { |
| + if !validSize(p.DefaultSize) { |
| return fmt.Errorf("%w: default size %q", ErrInvalid, p.DefaultSize) |
| } |
| } |
| @@ -71,7 +87,7 @@ func (p Policy) Validate() error { |
| if !controlname.ValidHostShape(host) || strings.ToLower(host) != host { |
| return fmt.Errorf("%w: size host %q", ErrInvalid, host) |
| } |
| - if _, ok := cgroup.SizeByName(o.Size); !ok { |
| + if !validSize(o.Size) { |
| return fmt.Errorf("%w: size %q for %s", ErrInvalid, o.Size, host) |
| } |
| if o.CreatedAt.IsZero() { |
diff --git a/internal/apppolicy/sizenames_test.go b/internal/apppolicy/sizenames_test.go| new file mode 100644 |
| index 000000000..71dae2f23 |
| --- /dev/null |
| +++ b/internal/apppolicy/sizenames_test.go |
| @@ -0,0 +1,29 @@ |
| +package apppolicy |
| + |
| +import ( |
| + "slices" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/cgroup" |
| +) |
| + |
| +// TestSizeNamesAreCgroupSizes pins apppolicy's own size list to |
| +// cgroup.Sizes: a size added, removed, renamed or reordered there must be |
| +// made here too, or a policy would name a size no box knows (or refuse one |
| +// every box knows). |
| +func TestSizeNamesAreCgroupSizes(t *testing.T) { |
| + t.Parallel() |
| + if got, want := sizeNames, cgroup.SizeNames(); !slices.Equal(got, want) { |
| + t.Fatalf("apppolicy's size names %q, cgroup.Sizes' %q", got, want) |
| + } |
| + for _, n := range cgroup.SizeNames() { |
| + if !validSize(n) { |
| + t.Errorf("validSize(%q) = false", n) |
| + } |
| + } |
| + for _, n := range []string{"", "Small", "medium", "standard "} { |
| + if validSize(n) { |
| + t.Errorf("validSize(%q) = true", n) |
| + } |
| + } |
| +} |