diff --git a/docs/reference/limits-and-quotas.md b/docs/reference/limits-and-quotas.md index 9f9f68d..66a76e1 100644 --- a/docs/reference/limits-and-quotas.md +++ b/docs/reference/limits-and-quotas.md @@ -1,7 +1,7 @@ --- type: reference audience: developer or operator who needs to know what a caller or a tenant may do, and how the API says no -verified: 2026-11-11 +verified: 2026-11-14 --- # Limits and quotas @@ -31,9 +31,9 @@ Creating an instance, a network or a profile that would pass a limit is refused A profile bigger than what is left is refused with the limit it passes when an instance takes it: a `l`, or a third `s`. -### The plan is deprecated +### There is no plan -There used to be three plans (`small`, `medium`, `large`) that set these limits, and only the platform administrators changed them. There is no choice of plan any more: the `plan` of a tenant limits nothing and changing it changes no limit. It is still in the body of a tenant and in the answer of the quota, and a plan other than `small` is refused with `403` on creation and on change, as before; a tenant is created without one. It stays only until the console stops reading it, then it is removed from the API. An existing tenant has the same limits as a new one, whatever plan it was created with. +Every tenant has these limits, the ones of a tenant created today and of one created long ago. A tenant has no `plan`: it is not in its body, nor in the answer of the quota, and a body that gives one, to create or to change a tenant, is `400` like any field the API does not know. ## The rate diff --git a/docs/reference/tenants.md b/docs/reference/tenants.md index eaf9118..a4705c5 100644 --- a/docs/reference/tenants.md +++ b/docs/reference/tenants.md @@ -1,15 +1,15 @@ --- type: reference audience: developer or operator who works with tenants through the API -verified: 2026-11-11 +verified: 2026-11-14 --- # Tenants A tenant is a `Tenant` object of the `phorge.fr` group in `phorge-system` (`internal/kube/tenants.go`); Crossplane makes its namespace `t-`, its Incus project, and its network. -- **Create** is for any person signed in with Authentik, for themselves: the owner is the caller (`owner` is left out or is their own email, another one is `403`), every tenant has the same limits (2 instances, 2 vCPU, 4 GiB of memory, 128 GiB of disk, 2 networks and 2 profiles, see [Limits and quotas](limits-and-quotas.md)) so a body leaves `plan` out, and a person owns at most `MAX_TENANTS_PER_USER` tenants (`409`, `quota_exceeded`, counted by owner, whoever created them). A key never creates a tenant. `GET /v1/whoami` says `canCreateTenants`. It answers `202` with a `Location`: poll it until `phase` is `Ready`. `phase` is `Provisioning`, `Ready`, `Deleting`, or `Failed` when the tenant has not become ready for 3 minutes and either `problems` says what is wrong in words made for the user (a limit that is reached, or that the platform could not complete a step yet) or the platform could not apply what makes the tenant for 3 minutes (the same rule holds for every kind: an object whose composition fails is `Failed` with a sentence that the platform administrators can see why, instead of staying `Provisioning`). It never carries what Crossplane, a provider or Incus report: those stay in `status.problems` of the object, for the administrators. -- **Patch** changes `displayName`: the admins of the tenant, the owner among them, do. The `plan` is deprecated and changes no limit, since every tenant has the same ones: a body that gives it is `403`, as it always was. A key never patches a tenant unless it holds `tenants:write`. The owner cannot change (it is an OpenFGA tuple): a body that holds it is refused. To hand a tenant over, give the new person the `admin` role with a membership. +- **Create** is for any person signed in with Authentik, for themselves: the owner is the caller (`owner` is left out or is their own email, another one is `403`), every tenant has the same limits (2 instances, 2 vCPU, 4 GiB of memory, 128 GiB of disk, 2 networks and 2 profiles, see [Limits and quotas](limits-and-quotas.md)), and a person owns at most `MAX_TENANTS_PER_USER` tenants (`409`, `quota_exceeded`, counted by owner, whoever created them). A key never creates a tenant. `GET /v1/whoami` says `canCreateTenants`. It answers `202` with a `Location`: poll it until `phase` is `Ready`. `phase` is `Provisioning`, `Ready`, `Deleting`, or `Failed` when the tenant has not become ready for 3 minutes and either `problems` says what is wrong in words made for the user (a limit that is reached, or that the platform could not complete a step yet) or the platform could not apply what makes the tenant for 3 minutes (the same rule holds for every kind: an object whose composition fails is `Failed` with a sentence that the platform administrators can see why, instead of staying `Provisioning`). It never carries what Crossplane, a provider or Incus report: those stay in `status.problems` of the object, for the administrators. +- **Patch** changes `displayName`: the admins of the tenant, the owner among them, do. A key never patches a tenant unless it holds `tenants:write`. The owner cannot change (it is an OpenFGA tuple): a body that holds it is refused. To hand a tenant over, give the new person the `admin` role with a membership. - **Delete** is for the admins of the tenant, the owner among them. It removes what the tenant holds first (its instances, then its memberships, then its networks, then the profiles its users made, then its images), then the tenant, all in the foreground: `202`, then the tenant stays as `Deleting` until everything it is made of is gone (about two minutes, longer with a virtual machine to stop), and a `404` on a later get means the person no longer sees the tenant: it is gone or about to be, since the rights of the person (the owner tuple) go with the tenant a little before its last resources do (measured: the `404` came while the tenant was still `Deleting`). Stop polling on it, and do not take it for proof that Incus is empty. It destroys the virtual machines of the tenant. The order is not cosmetic: the platform deletes what a tenant holds in its namespace only while the namespace exists, so the tenant waits for them (see the Hangar issue 185). - Whoever cannot read a tenant is told it does not exist (`404`), whoever can but may not do this gets `403`. Bodies are JSON only, 64 KiB at most, with no field the API does not know. -- **The `plan` is deprecated.** There is no choice of plan: every tenant has the same limits, whatever its `plan`. The field stays in the body of a tenant (`small` for a new one, what the object holds for an existing one) and in the answer of `GET /v1/tenants/{t}/quota`, only so that what reads it keeps working until the console stops using it; it is then removed from the API. A creation without a plan works, and a plan other than `small` on creation or on change is `403`. +- **There is no plan.** Every tenant has the same limits. A body that gives a `plan`, to create or to change a tenant, is `400`, like any field the API does not know. diff --git a/internal/api/access_integration_test.go b/internal/api/access_integration_test.go index 7a71590..01cb538 100644 --- a/internal/api/access_integration_test.go +++ b/internal/api/access_integration_test.go @@ -104,7 +104,7 @@ func TestMembershipsOnTheRealCluster(t *testing.T) { {"POST", base + "/instances", `{"name":"web","image":"nope"}`, http.StatusForbidden}, {"POST", base + "/images", `{"name":"x","source":{"name":"alpine/3.22"}}`, http.StatusForbidden}, {"GET", base + "/memberships", "", http.StatusForbidden}, - {"PATCH", base, `{"plan":"large"}`, http.StatusForbidden}, + {"PATCH", base, `{"displayName":"x"}`, http.StatusForbidden}, {"DELETE", base, "", http.StatusForbidden}, } { if code := call(t, e, c.method, c.path, "bob", c.body); code != c.want { diff --git a/internal/api/compute_integration_test.go b/internal/api/compute_integration_test.go index 76ae282..8a2bbe4 100644 --- a/internal/api/compute_integration_test.go +++ b/internal/api/compute_integration_test.go @@ -148,7 +148,7 @@ func TestImageAndInstanceOnTheRealCluster(t *testing.T) { }) } - // The plan small allows one VM: Incus refuses the second, and says so in problems. + // Incus refuses the instance that passes a limit of the tenant, and says so in problems. if code := call(t, e, "POST", base+"/instances", "owner", `{"name":"second","image":"debian"}`); code != http.StatusAccepted { t.Fatalf("create the second instance: %d", code) } diff --git a/internal/api/instances.go b/internal/api/instances.go index 9358ee5..22c6353 100644 --- a/internal/api/instances.go +++ b/internal/api/instances.go @@ -198,7 +198,7 @@ func (i *instanceRoutes) create(w http.ResponseWriter, r *http.Request) { req.Networks, req.Network = nws, "" // The limits of the tenant hold the count and the total of CPU, memory and disk: say which before asking Incus, who would leave an instance // that never becomes ready. The profiles the users made are read for it, an instance counts what its profile comes to. - _, used, made, ok := holdings(w, r, &i.base, i.store, i.networks, i.profiles, tenant) + used, made, ok := holdings(w, r, &i.base, i.store, i.networks, i.profiles, tenant) if !ok { return } diff --git a/internal/api/keyscopes_test.go b/internal/api/keyscopes_test.go index a76a290..7460425 100644 --- a/internal/api/keyscopes_test.go +++ b/internal/api/keyscopes_test.go @@ -37,9 +37,9 @@ func TestAKeyWithTheScopesOfTheNetworksTheProfilesAndTheTenantPassesTheirRoutes( {"GET", "/v1/apikeys", "", http.StatusForbidden}, {"GET", "/v1/tenants/other/networks", "", http.StatusNotFound}, {"POST", "/v1/tenants/other/networks", `{"name":"x"}`, http.StatusNotFound}, - // the tenant: rename it, and do not choose its plan + // the tenant: rename it; there is no plan to give {"PATCH", "/v1/tenants/demo", `{"displayName":"renamed"}`, http.StatusOK}, - {"PATCH", "/v1/tenants/demo", `{"plan":"large"}`, http.StatusForbidden}, + {"PATCH", "/v1/tenants/demo", `{"plan":"large"}`, http.StatusBadRequest}, {"POST", "/v1/tenants", `{"name":"fresh","owner":"x@example.org"}`, http.StatusForbidden}, {"DELETE", "/v1/tenants/demo", "", http.StatusAccepted}, } { diff --git a/internal/api/networks.go b/internal/api/networks.go index d40f745..a2bebbf 100644 --- a/internal/api/networks.go +++ b/internal/api/networks.go @@ -148,7 +148,7 @@ func (n *networkRoutes) create(w http.ResponseWriter, r *http.Request) { } tenant := r.PathValue("t") // The tenant is limited in how many: say it before asking, with a code, instead of leaving a network that never becomes ready. - _, used, _, ok := holdings(w, r, &n.base, n.instances, n.store, n.profiles, tenant) + used, _, ok := holdings(w, r, &n.base, n.instances, n.store, n.profiles, tenant) if !ok { return } diff --git a/internal/api/networks_test.go b/internal/api/networks_test.go index 8fc99ab..f30ad73 100644 --- a/internal/api/networks_test.go +++ b/internal/api/networks_test.go @@ -169,7 +169,7 @@ func TestANetworkShowsAPhaseAndNoCrossplaneCondition(t *testing.T) { } } if !strings.Contains(body.Problems, "number of networks") { - t.Errorf("the limit of the plan is told in words: %q", body.Problems) + t.Errorf("the limit of the tenant is told in words: %q", body.Problems) } } diff --git a/internal/api/quota.go b/internal/api/quota.go index a522999..cc70a6d 100644 --- a/internal/api/quota.go +++ b/internal/api/quota.go @@ -11,7 +11,6 @@ import ( "github.com/phorge-fr/phorge-api/internal/quota" "github.com/phorge-fr/phorge-api/internal/ratelimit" "github.com/phorge-fr/phorge-api/internal/server" - "github.com/phorge-fr/phorge-api/internal/tenants" ) // quotaRoutes tell a tenant what it is allowed to hold, the same for every tenant, and what it holds, so that a client draws what is @@ -28,45 +27,42 @@ func (q *quotaRoutes) register(s *server.Server, authn func(http.Handler) http.H } type quotaBody struct { - // Plan is deprecated: it changes no limit, and goes when the console stops reading it. - Plan tenants.Plan `json:"plan"` Limits quota.Limits `json:"limits"` Used quota.Used `json:"used"` } func (q *quotaRoutes) get(w http.ResponseWriter, r *http.Request) { tenant := r.PathValue("t") - plan, used, _, ok := holdings(w, r, &q.base, q.instances, q.networks, q.profiles, tenant) + used, _, ok := holdings(w, r, &q.base, q.instances, q.networks, q.profiles, tenant) if !ok { return } - writeJSON(w, http.StatusOK, quotaBody{Plan: plan, Limits: quota.PerTenant, Used: used}) + writeJSON(w, http.StatusOK, quotaBody{Limits: quota.PerTenant, Used: used}) } -// holdings reads the plan of a tenant (deprecated, it limits nothing), what it holds, and the profiles its users made (an instance counts what its profile comes to), +// holdings reads what a tenant holds, and the profiles its users made (an instance counts what its profile comes to), // or answers. -func holdings(w http.ResponseWriter, r *http.Request, b *base, instances compute.InstanceStore, networks compute.NetworkStore, profiles compute.ProfileStore, tenant string) (tenants.Plan, quota.Used, []compute.Profile, bool) { - tn, err := b.tenants.Get(r.Context(), tenant) - if err != nil { +func holdings(w http.ResponseWriter, r *http.Request, b *base, instances compute.InstanceStore, networks compute.NetworkStore, profiles compute.ProfileStore, tenant string) (quota.Used, []compute.Profile, bool) { + if _, err := b.tenants.Get(r.Context(), tenant); err != nil { b.storeError(w, err, "tenant") - return "", quota.Used{}, nil, false + return quota.Used{}, nil, false } in, err := instances.List(r.Context(), tenant) if err != nil { b.storeError(w, err, "instance") - return "", quota.Used{}, nil, false + return quota.Used{}, nil, false } nw, err := networks.List(r.Context(), tenant) if err != nil { b.storeError(w, err, "network") - return "", quota.Used{}, nil, false + return quota.Used{}, nil, false } made, err := profiles.List(r.Context(), tenant) if err != nil { b.storeError(w, err, "profile") - return "", quota.Used{}, nil, false + return quota.Used{}, nil, false } - return tn.Plan, quota.UsedBy(in, nw, made), made, true + return quota.UsedBy(in, nw, made), made, true } // quotaExceeded answers a request that would pass a limit: 409, with a code a program can act on and a sentence that says which. diff --git a/internal/api/quota_test.go b/internal/api/quota_test.go index ec750ad..72dcc20 100644 --- a/internal/api/quota_test.go +++ b/internal/api/quota_test.go @@ -12,7 +12,7 @@ import ( // tiny is a tenant like any other (2 instances, 2 vCPU, 4 GiB, 128 GiB, 2 networks, 2 profiles) that alice may use as she uses demo. func withTiny(e *env) { - e.store.tenants["tiny"] = tenants.Tenant{Name: "tiny", Owner: "alice@example.org", Plan: tenants.Small, CreatedAt: now, Ready: true, NotReadySince: now} + e.store.tenants["tiny"] = tenants.Tenant{Name: "tiny", Owner: "alice@example.org", CreatedAt: now, Ready: true, NotReadySince: now} for _, rel := range []string{"can_read_tenant", "can_read_instances", "can_write_instances", "can_read_images", "can_write_images", "can_read_networks", "can_write_networks", "can_read_profiles", "can_write_profiles"} { e.fga.grants["user:operator@example.org "+rel+" tenant:tiny"] = true } @@ -26,24 +26,28 @@ func TestQuotaSaysWhatEveryTenantMayHoldAndWhatItHolds(t *testing.T) { e.instances.put("demo", compute.Instance{Name: "b", Image: "debian", Profile: "m", Running: false}) // stopped: it counts var got quotaBody mustDecode(t, e.do(t, "GET", "/v1/tenants/demo/quota", "viewer", ""), &got) - // the plan of demo is large and the limits are the same as for every tenant: the plan is shown, deprecated, and limits nothing - if got.Plan != tenants.Large || got.Limits != (quota.Limits{Instances: 2, VCPU: 2, MemoryMiB: 4096, DiskGiB: 128, Networks: 2, Profiles: 2}) { - t.Errorf("plan and limits: %+v", got) + if got.Limits != (quota.Limits{Instances: 2, VCPU: 2, MemoryMiB: 4096, DiskGiB: 128, Networks: 2, Profiles: 2}) { + t.Errorf("limits: %+v", got.Limits) } if want := (quota.Used{Instances: 2, VCPU: 4, MemoryMiB: 2048 + 4096, DiskGiB: 148, Networks: 1, Profiles: 0}); got.Used != want { t.Errorf("used = %+v, want %+v (the network of the test environment, the stopped VM, the profile)", got.Used, want) } } -// The plan of a tenant is kept in the answer and limits nothing: a small one and a large one have the same limits. -func TestThePlanOfATenantChangesNoLimit(t *testing.T) { +// Every tenant has the same limits, and the answer names no plan: there is none. +func TestEveryTenantHasTheSameLimitsAndNoPlan(t *testing.T) { e := newEnv(t) - withTiny(e) // small, demo is large - var small, large quotaBody - mustDecode(t, e.do(t, "GET", "/v1/tenants/tiny/quota", "operator", ""), &small) - mustDecode(t, e.do(t, "GET", "/v1/tenants/demo/quota", "viewer", ""), &large) - if small.Plan != tenants.Small || large.Plan != tenants.Large || small.Limits != large.Limits || small.Limits != quota.PerTenant { - t.Errorf("small %+v, large %+v: the limits are the same, whatever the plan", small, large) + withTiny(e) + var tiny, demo quotaBody + mustDecode(t, e.do(t, "GET", "/v1/tenants/tiny/quota", "operator", ""), &tiny) + mustDecode(t, e.do(t, "GET", "/v1/tenants/demo/quota", "viewer", ""), &demo) + if tiny.Limits != demo.Limits || tiny.Limits != quota.PerTenant { + t.Errorf("tiny %+v, demo %+v: the limits are the same for every tenant", tiny.Limits, demo.Limits) + } + var raw map[string]any + mustDecode(t, e.do(t, "GET", "/v1/tenants/demo/quota", "viewer", ""), &raw) + if _, ok := raw["plan"]; ok { + t.Errorf("the answer carries a plan: %v", raw) } } diff --git a/internal/api/selfservice_test.go b/internal/api/selfservice_test.go index 634d7d4..6ded8ca 100644 --- a/internal/api/selfservice_test.go +++ b/internal/api/selfservice_test.go @@ -24,10 +24,10 @@ func TestAPersonCreatesATenantForThemselves(t *testing.T) { } var body tenantBody mustDecode(t, rec, &body) - if body.Owner != "mallory@example.org" || body.Plan != tenants.Small || body.CreatedBy != "user:mallory@example.org" { - t.Errorf("the owner is the caller and the plan the smallest: %+v", body) + if body.Owner != "mallory@example.org" || body.CreatedBy != "user:mallory@example.org" { + t.Errorf("the owner is the caller: %+v", body) } - if got := e.store.tenants["mine"]; got.Owner != "mallory@example.org" || got.Plan != tenants.Small { + if got := e.store.tenants["mine"]; got.Owner != "mallory@example.org" { t.Errorf("the store received %+v", got) } if loc := rec.Header().Get("Location"); loc != "/v1/tenants/mine" { @@ -35,25 +35,17 @@ func TestAPersonCreatesATenantForThemselves(t *testing.T) { } } -func TestAPersonCannotCreateATenantForSomeoneElseOrWithABiggerPlan(t *testing.T) { +func TestAPersonCannotCreateATenantForSomeoneElse(t *testing.T) { e := newEnvWith(t, usersMay()) - for name, tt := range map[string]struct{ body, want string }{ - "for someone else": {`{"name":"x1","owner":"bob@example.org"}`, "only create a tenant for yourself"}, - "a bigger plan": {`{"name":"x2","plan":"large"}`, "no choice of plan"}, - "a medium plan": {`{"name":"x3","plan":"medium"}`, "no choice of plan"}, - } { - rec := e.do(t, "POST", "/v1/tenants", "mallory", tt.body) - if rec.Code != http.StatusForbidden || !strings.Contains(rec.Body.String(), tt.want) { - t.Errorf("%s: status %d: %s", name, rec.Code, rec.Body) - } + rec := e.do(t, "POST", "/v1/tenants", "mallory", `{"name":"x1","owner":"bob@example.org"}`) + if rec.Code != http.StatusForbidden || !strings.Contains(rec.Body.String(), "only create a tenant for yourself") { + t.Errorf("for someone else: status %d: %s", rec.Code, rec.Body) } - for _, name := range []string{"x1", "x2", "x3"} { - if _, ok := e.store.tenants[name]; ok { - t.Errorf("%s was created", name) - } + if _, ok := e.store.tenants["x1"]; ok { + t.Error("x1 was created") } - // their own address, in another case, is theirs; the small plan is what they get anyway - if code := call(t, e, "POST", "/v1/tenants", "mallory", `{"name":"x4","owner":"Mallory@Example.org","plan":"small"}`); code != http.StatusAccepted { + // their own address, in another case, is theirs + if code := call(t, e, "POST", "/v1/tenants", "mallory", `{"name":"x4","owner":"Mallory@Example.org"}`); code != http.StatusAccepted { t.Errorf("their own address: status %d", code) } } @@ -76,7 +68,7 @@ func TestAPersonOwnsAtMostSomeTenants(t *testing.T) { if code := call(t, e, "POST", "/v1/tenants", "viewer", `{"name":"v1"}`); code != http.StatusAccepted { t.Errorf("another person: status %d", code) } - e.store.tenants["gift"] = tenants.Tenant{Name: "gift", Owner: "MALLORY@example.org", Plan: tenants.Small} + e.store.tenants["gift"] = tenants.Tenant{Name: "gift", Owner: "MALLORY@example.org"} e.store.tenants["a3"] = tenants.Tenant{Name: "a3-gone"} delete(e.store.tenants, "a3") if code := call(t, e, "POST", "/v1/tenants", "mallory", `{"name":"a5"}`); code != http.StatusConflict { @@ -96,19 +88,23 @@ func TestAPersonOwnsAtMostSomeTenants(t *testing.T) { func TestACreationAsksForNothingBeyondTheCaller(t *testing.T) { e := newEnvWith(t, usersMay()) for name, body := range map[string]string{ - "for somebody else": `{"name":"fresh","owner":"bob@example.org"}`, - "another plan": `{"name":"fresh","plan":"large"}`, - "another plan, medium": `{"name":"fresh","plan":"medium"}`, + "for somebody else": `{"name":"fresh","owner":"bob@example.org"}`, } { if code := call(t, e, "POST", "/v1/tenants", "mallory", body); code != http.StatusForbidden { t.Errorf("%s: status %d, want 403", name, code) } } + // there is no plan to give, small or not: the field is unknown + for _, plan := range []string{"small", "large"} { + if code := call(t, e, "POST", "/v1/tenants", "mallory", `{"name":"fresh","plan":"`+plan+`"}`); code != http.StatusBadRequest { + t.Errorf("plan %s: status %d, want 400", plan, code) + } + } if len(e.store.created) != 0 { t.Errorf("something was created: %+v", e.store.created) } - if code := call(t, e, "POST", "/v1/tenants", "mallory", `{"name":"fresh","owner":"MALLORY@example.org","plan":"small"}`); code != http.StatusAccepted { - t.Errorf("itself, the smallest plan: status %d, want 202", code) + if code := call(t, e, "POST", "/v1/tenants", "mallory", `{"name":"fresh","owner":"MALLORY@example.org"}`); code != http.StatusAccepted { + t.Errorf("itself: status %d, want 202", code) } } @@ -140,14 +136,14 @@ func TestWhoamiSaysWhetherTheCallerMayCreateATenant(t *testing.T) { func TestTheAdminsOfATenantChangeAndDeleteIt(t *testing.T) { e := newEnvWith(t, usersMay()) - e.store.tenants["demo"] = tenants.Tenant{Name: "demo", Owner: "alice@example.org", Plan: tenants.Small, Ready: true, NotReadySince: now} + e.store.tenants["demo"] = tenants.Tenant{Name: "demo", Owner: "alice@example.org", Ready: true, NotReadySince: now} for who, want := range map[string]int{"alice": 200, "tadmin": 200, "operator": 403, "user": 403, "viewer": 403, "mallory": 404, "svc": 403, "": 401} { if code := call(t, e, "PATCH", "/v1/tenants/demo", who, `{"displayName":"renamed"}`); code != want { t.Errorf("rename by %q: status %d, want %d", who, code, want) } } - // the plan is changed where the platform is run, on request: not through the API, by nobody - for who, want := range map[string]int{"alice": 403, "tadmin": 403, "admin": 403} { + // there is no plan to change: the field is unknown, whoever asks + for who, want := range map[string]int{"alice": 400, "tadmin": 400, "admin": 400, "viewer": 403} { if code := call(t, e, "PATCH", "/v1/tenants/demo", who, `{"plan":"large"}`); code != want { t.Errorf("plan by %q: status %d, want %d", who, code, want) } diff --git a/internal/api/tenants.go b/internal/api/tenants.go index 4dfe347..2ea8df7 100644 --- a/internal/api/tenants.go +++ b/internal/api/tenants.go @@ -18,8 +18,8 @@ import ( // // Seeing a tenant takes a right on it (a role; for a key, the scope tenants:read too). Any person creates a tenant for themselves: // they own it, and the number of tenants a person owns is limited (MAX_TENANTS_PER_USER). Changing the -// name of a tenant and deleting it is for its admins, the owner among them. Every tenant has the same limits (internal/quota), -// whatever its plan, which is deprecated and kept as it is read until the console stops using it. A key never creates, changes or deletes a tenant. +// name of a tenant and deleting it is for its admins, the owner among them. Every tenant has the same limits (internal/quota). +// A key never creates, changes or deletes a tenant. type tenantRoutes struct { base store tenants.Store @@ -69,7 +69,6 @@ type tenantBody struct { Name string `json:"name"` DisplayName string `json:"displayName,omitempty"` Owner string `json:"owner"` - Plan tenants.Plan `json:"plan"` Phase tenants.Phase `json:"phase"` Problems string `json:"problems,omitempty"` Namespace string `json:"namespace,omitempty"` @@ -80,7 +79,7 @@ type tenantBody struct { func (t *tenantRoutes) body(tn tenants.Tenant) tenantBody { return tenantBody{ - Name: tn.Name, DisplayName: tn.DisplayName, Owner: tn.Owner, Plan: tn.Plan, Phase: tn.PhaseAt(t.now()), + Name: tn.Name, DisplayName: tn.DisplayName, Owner: tn.Owner, Phase: tn.PhaseAt(t.now()), Problems: tn.MessageAt(t.now()), Namespace: tn.Namespace, IncusProject: tn.IncusProject, CreatedAt: tn.CreatedAt, CreatedBy: tn.CreatedBy, } } @@ -125,17 +124,12 @@ func (t *tenantRoutes) create(w http.ResponseWriter, r *http.Request) { } id, _ := auth.FromContext(r.Context()) req.CreatedBy = id.Subject - // A person creates a tenant for themselves: the owner is the caller, and the plan the default one, which limits nothing. A request that says otherwise - // is refused, not changed in silence. + // A person creates a tenant for themselves: the owner is the caller. A request that says otherwise is refused, not changed in silence. if req.Owner != "" && !strings.EqualFold(req.Owner, id.Email) { httperr.Write(w, http.StatusForbidden, "forbidden", "you can only create a tenant for yourself") return } - if req.Plan != "" && req.Plan != tenants.Small { - httperr.Write(w, http.StatusForbidden, "forbidden", "there is no choice of plan any more: every tenant has the same limits, leave plan out") - return - } - req.Owner, req.Plan = id.Email, tenants.Small + req.Owner = id.Email if err := req.Validate(); err != nil { t.storeError(w, err, "tenant") return @@ -185,12 +179,6 @@ func (t *tenantRoutes) patch(w http.ResponseWriter, r *http.Request) { t.storeError(w, err, "tenant") return } - // Every tenant has the same limits: the plan is deprecated, kept until the console stops reading it, and it changes nothing. Its - // admins rename a tenant, and a request that gives a plan is still refused, as it always was. - if req.Plan != nil { - httperr.Write(w, http.StatusForbidden, "forbidden", "there is no choice of plan any more: every tenant has the same limits") - return - } tn, err := t.store.Patch(r.Context(), r.PathValue("t"), req) if err != nil { t.storeError(w, err, "tenant") diff --git a/internal/api/tenants_integration_test.go b/internal/api/tenants_integration_test.go index b6dd5a0..0f33e61 100644 --- a/internal/api/tenants_integration_test.go +++ b/internal/api/tenants_integration_test.go @@ -90,7 +90,7 @@ func TestTenantLifecycleOnTheRealCluster(t *testing.T) { return got.Phase == tenants.Ready }) t.Logf("ready after %s: namespace %s, project %s", time.Since(started).Round(time.Second), got.Namespace, got.IncusProject) - if got.Namespace != "t-"+name || got.IncusProject != "t-"+name || got.Plan != tenants.Small || got.Owner != ownerEmail { + if got.Namespace != "t-"+name || got.IncusProject != "t-"+name || got.Owner != ownerEmail { t.Errorf("unexpected tenant: %+v", got) } @@ -101,8 +101,8 @@ func TestTenantLifecycleOnTheRealCluster(t *testing.T) { if code := e.do(t, http.MethodGet, "/v1/tenants/"+name, "stranger", "").Code; code != http.StatusNotFound { t.Errorf("a stranger gets %d, want 404", code) } - if code := e.do(t, http.MethodPatch, "/v1/tenants/"+name, "owner", `{"plan":"large"}`).Code; code != http.StatusForbidden { - t.Errorf("the owner changing the plan gets %d, want 403: it is changed where the platform is run", code) + if code := e.do(t, http.MethodPatch, "/v1/tenants/"+name, "owner", `{"plan":"large"}`).Code; code != http.StatusBadRequest { + t.Errorf("the owner giving a plan gets %d, want 400: there is no plan", code) } if listed := names(t, e.do(t, http.MethodGet, "/v1/tenants", "owner", "")); !slices.Equal(listed, []string{name}) { t.Errorf("the owner sees %v, want only %s", listed, name) @@ -115,7 +115,7 @@ func TestTenantLifecycleOnTheRealCluster(t *testing.T) { } waitFor(t, 3*time.Minute, "the renamed tenant to be Ready again", func() bool { mustDecode(t, e.do(t, http.MethodGet, "/v1/tenants/"+name, "owner", ""), &got) - return got.Plan == tenants.Small && got.DisplayName == "resized" && got.Phase == tenants.Ready + return got.DisplayName == "resized" && got.Phase == tenants.Ready }) // Delete, in the foreground: it is Deleting until everything is gone, and then it is not found. diff --git a/internal/api/tenants_test.go b/internal/api/tenants_test.go index af10e29..5ecc6e4 100644 --- a/internal/api/tenants_test.go +++ b/internal/api/tenants_test.go @@ -63,11 +63,7 @@ func (s *store) Create(_ context.Context, r tenants.CreateRequest) (tenants.Tena return tenants.Tenant{}, tenants.ErrExists } s.created = append(s.created, r) - plan := r.Plan - if plan == "" { - plan = tenants.Small - } - t := tenants.Tenant{Name: r.Name, Owner: r.Owner, Plan: plan, DisplayName: r.DisplayName, CreatedBy: r.CreatedBy, CreatedAt: now, NotReadySince: now} + t := tenants.Tenant{Name: r.Name, Owner: r.Owner, DisplayName: r.DisplayName, CreatedBy: r.CreatedBy, CreatedAt: now, NotReadySince: now} s.tenants[r.Name] = t return t, nil } @@ -77,9 +73,6 @@ func (s *store) Patch(_ context.Context, name string, r tenants.PatchRequest) (t if err != nil { return t, err } - if r.Plan != nil { - t.Plan = *r.Plan - } if r.DisplayName != nil { t.DisplayName = *r.DisplayName } @@ -166,8 +159,8 @@ func newEnvWith(t *testing.T, settings Settings) *env { exchange := &fakeExchange{} incus := newFakeIncus(t) st := &store{tenants: map[string]tenants.Tenant{ - "demo": {Name: "demo", Owner: "alice@example.org", Plan: tenants.Large, CreatedAt: now, Ready: true, NotReadySince: now, Namespace: "t-demo", IncusProject: "t-demo"}, - "other": {Name: "other", Owner: "bob@example.org", Plan: tenants.Large, CreatedAt: now, NotReadySince: now.Add(-time.Hour), Problems: "project Synced: Reached maximum"}, + "demo": {Name: "demo", Owner: "alice@example.org", CreatedAt: now, Ready: true, NotReadySince: now, Namespace: "t-demo", IncusProject: "t-demo"}, + "other": {Name: "other", Owner: "bob@example.org", CreatedAt: now, NotReadySince: now.Add(-time.Hour), Problems: "project Synced: Reached maximum"}, }} fga := &checker{ grants: map[string]bool{ @@ -360,7 +353,7 @@ func TestListShowsWhatTheCallerMaySee(t *testing.T) { func TestListIsSortedAndAnEmptyListIsAnArray(t *testing.T) { e := newEnv(t) - e.store.tenants["alpha"] = tenants.Tenant{Name: "alpha", Owner: "a@b", Plan: tenants.Small} + e.store.tenants["alpha"] = tenants.Tenant{Name: "alpha", Owner: "a@b"} e.fga.objects["user:admin@example.org"] = append(e.fga.objects["user:admin@example.org"], "tenant:alpha") if got := names(t, e.do(t, http.MethodGet, "/v1/tenants", "admin", "")); !slices.Equal(got, []string{"alpha", "demo", "other"}) { t.Errorf("order = %v", got) @@ -403,7 +396,7 @@ func TestGetShowsThePhase(t *testing.T) { var ready, failed tenantBody mustDecode(t, e.do(t, http.MethodGet, "/v1/tenants/demo", "admin", ""), &ready) mustDecode(t, e.do(t, http.MethodGet, "/v1/tenants/other", "admin", ""), &failed) - if ready.Phase != tenants.Ready || ready.Namespace != "t-demo" || ready.Owner != "alice@example.org" || ready.Plan != tenants.Large { + if ready.Phase != tenants.Ready || ready.Namespace != "t-demo" || ready.Owner != "alice@example.org" { t.Errorf("ready: %+v", ready) } if failed.Phase != tenants.Failed || failed.Problems != "This tenant has reached one of its limits." { @@ -416,7 +409,7 @@ func TestGetShowsThePhase(t *testing.T) { func TestACrossplaneConditionNeverReachesTheClient(t *testing.T) { e := newEnv(t) e.fga.grants["user:admin@example.org can_read_tenant tenant:broken"] = true - e.store.tenants["broken"] = tenants.Tenant{Name: "broken", Owner: "alice@example.org", Plan: tenants.Small, CreatedAt: now, NotReadySince: now.Add(-time.Hour), + e.store.tenants["broken"] = tenants.Tenant{Name: "broken", Owner: "alice@example.org", CreatedAt: now, NotReadySince: now.Add(-time.Hour), Problems: "network Ready: not ready | network Synced: create failed: apply failed: Failed to create network \"default\": Failed to load project \"t-broken\": Project not found | " + "owner Ready: not ready | profile LastAsyncOperation: apply failed: Failed to create profile \"phorge\": Project not found | project Ready: not ready"} var got tenantBody @@ -445,7 +438,7 @@ func TestCreate(t *testing.T) { } var got tenantBody mustDecode(t, rec, &got) - if got.Name != "newone" || got.Owner != "alice@example.org" || got.Plan != tenants.Small || got.Phase != tenants.Provisioning { + if got.Name != "newone" || got.Owner != "alice@example.org" || got.Phase != tenants.Provisioning { t.Errorf("body: %+v", got) } if len(e.store.created) != 1 || e.store.created[0].CreatedBy != "user:alice@example.org" { @@ -490,7 +483,7 @@ func TestCreateRefusesABadRequest(t *testing.T) { {"a name that is not a slug", "application/json", `{"name":"Demo!"}`, http.StatusUnprocessableEntity}, {"no name", "application/json", `{}`, http.StatusUnprocessableEntity}, {"an owner that is somebody else", "application/json", `{"name":"newone","owner":"*"}`, http.StatusForbidden}, - {"a plan that is not small", "application/json", `{"name":"newone","plan":"huge"}`, http.StatusForbidden}, + {"a plan, there is none", "application/json", `{"name":"newone","plan":"small"}`, http.StatusBadRequest}, {"a name that exists", "application/json", `{"name":"demo"}`, http.StatusConflict}, {"not JSON", "application/json", `name=newone`, http.StatusBadRequest}, {"a field that does not exist", "application/json", `{"name":"newone","admin":true}`, http.StatusBadRequest}, @@ -521,7 +514,7 @@ func TestPatch(t *testing.T) { } var got tenantBody mustDecode(t, rec, &got) - if got.Plan != tenants.Large || got.DisplayName != "Production" || got.Owner != "alice@example.org" { + if got.DisplayName != "Production" || got.Owner != "alice@example.org" { t.Errorf("body: %+v", got) } @@ -529,15 +522,15 @@ func TestPatch(t *testing.T) { token, path, body string want int }{ - "the owner cannot be changed": {"admin", "/v1/tenants/demo", `{"owner":"mallory@example.org"}`, http.StatusBadRequest}, - "nor the name": {"admin", "/v1/tenants/demo", `{"name":"x"}`, http.StatusBadRequest}, - "an empty patch": {"admin", "/v1/tenants/demo", `{}`, http.StatusUnprocessableEntity}, - "the plan is not changed through the API": {"admin", "/v1/tenants/demo", `{"plan":"large"}`, http.StatusForbidden}, - "a tenant that does not exist": {"admin", "/v1/tenants/ghost", `{"displayName":"x"}`, http.StatusNotFound}, - "a member who sees the tenant": {"viewer", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusForbidden}, - "a stranger does not see it": {"mallory", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusNotFound}, - "a key without the scope": {"svc", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusForbidden}, - "nobody": {"", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusUnauthorized}, + "the owner cannot be changed": {"admin", "/v1/tenants/demo", `{"owner":"mallory@example.org"}`, http.StatusBadRequest}, + "nor the name": {"admin", "/v1/tenants/demo", `{"name":"x"}`, http.StatusBadRequest}, + "an empty patch": {"admin", "/v1/tenants/demo", `{}`, http.StatusUnprocessableEntity}, + "a plan, there is none": {"admin", "/v1/tenants/demo", `{"plan":"large"}`, http.StatusBadRequest}, + "a tenant that does not exist": {"admin", "/v1/tenants/ghost", `{"displayName":"x"}`, http.StatusNotFound}, + "a member who sees the tenant": {"viewer", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusForbidden}, + "a stranger does not see it": {"mallory", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusNotFound}, + "a key without the scope": {"svc", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusForbidden}, + "nobody": {"", "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusUnauthorized}, } { before := len(e.store.patched) if rec := e.do(t, http.MethodPatch, tt.path, tt.token, tt.body); rec.Code != tt.want { @@ -627,7 +620,7 @@ func TestAServiceKeyDoesWhatOpenFGAHoldsForIt(t *testing.T) { {"does not see another tenant", http.MethodGet, "/v1/tenants/other", "", http.StatusNotFound}, {"is refused what it has no tuple for", http.MethodGet, "/v1/tenants/demo/images", "", http.StatusForbidden}, {"lists the tenants it can read", http.MethodGet, "/v1/tenants", "", http.StatusOK}, - {"cannot create a tenant", http.MethodPost, "/v1/tenants", `{"name":"newone","plan":"small"}`, http.StatusForbidden}, + {"cannot create a tenant", http.MethodPost, "/v1/tenants", `{"name":"newone"}`, http.StatusForbidden}, {"cannot change a tenant", http.MethodPatch, "/v1/tenants/demo", `{"displayName":"x"}`, http.StatusForbidden}, {"cannot create a key", http.MethodPost, "/v1/apikeys", `{"displayName":"x","expiresAt":"2026-12-31T00:00:00Z","grants":[{"tenant":"demo","scopes":["tenants:read"]}]}`, http.StatusForbidden}, } { diff --git a/internal/compute/compute.go b/internal/compute/compute.go index 7577455..6e77c86 100644 --- a/internal/compute/compute.go +++ b/internal/compute/compute.go @@ -133,13 +133,13 @@ type ImageStore interface { // ---- Instance ---- -// The bounds of an instance, which are the ones of the XRD. The plan of the tenant limits the total on top of them. +// The bounds of an instance, which are the ones of the XRD. The limits of the tenant cap the total on top of them. const ( MinCPU, MaxCPU = 1, 16 MinMemory, MaxMemory = 256, 65536 MinDisk, MaxDisk = 1, 500 MaxSSHKeys = 20 - // MaxInstanceNetworks is the number of networks one instance joins, the bound of the XRD. The plan limits how many networks a + // MaxInstanceNetworks is the number of networks one instance joins, the bound of the XRD. The limits of the tenant say how many networks a // tenant has, not how many an instance is attached to. MaxInstanceNetworks = 8 ) diff --git a/internal/kube/tenants.go b/internal/kube/tenants.go index d858f13..4bb9383 100644 --- a/internal/kube/tenants.go +++ b/internal/kube/tenants.go @@ -86,9 +86,6 @@ func (s *Tenants) Create(ctx context.Context, req tenants.CreateRequest) (tenant return tenants.Tenant{}, err } spec := map[string]any{"owner": req.Owner} - if req.Plan != "" { - spec["plan"] = string(req.Plan) - } if req.DisplayName != "" { spec["displayName"] = req.DisplayName } @@ -108,16 +105,13 @@ func (s *Tenants) Create(ctx context.Context, req tenants.CreateRequest) (tenant return tenantOf(obj), nil } -// Patch changes the plan or the display name, with a JSON merge patch on the fields that were given. +// Patch changes the display name, with a JSON merge patch on the fields that were given. func (s *Tenants) Patch(ctx context.Context, name string, req tenants.PatchRequest) (tenants.Tenant, error) { r, err := s.resource() if err != nil { return tenants.Tenant{}, err } spec := map[string]any{} - if req.Plan != nil { - spec["plan"] = string(*req.Plan) - } if req.DisplayName != nil { spec["displayName"] = *req.DisplayName } @@ -200,7 +194,6 @@ func mapError(err error) error { func tenantOf(obj *unstructured.Unstructured) tenants.Tenant { // A field of the wrong type reads as empty. owner, _, _ := unstructured.NestedString(obj.Object, "spec", "owner") - plan, _, _ := unstructured.NestedString(obj.Object, "spec", "plan") displayName, _, _ := unstructured.NestedString(obj.Object, "spec", "displayName") problems, _, _ := unstructured.NestedString(obj.Object, "status", "problems") namespace, _, _ := unstructured.NestedString(obj.Object, "status", "namespace") @@ -210,7 +203,6 @@ func tenantOf(obj *unstructured.Unstructured) tenants.Tenant { Name: obj.GetName(), DisplayName: displayName, Owner: owner, - Plan: tenants.Plan(plan), CreatedAt: obj.GetCreationTimestamp().Time, CreatedBy: obj.GetAnnotations()[CreatedByAnnotation], Namespace: namespace, diff --git a/internal/kube/tenants_test.go b/internal/kube/tenants_test.go index e630736..bc704d8 100644 --- a/internal/kube/tenants_test.go +++ b/internal/kube/tenants_test.go @@ -28,12 +28,12 @@ func TestCreateWritesTheObject(t *testing.T) { s, client := newTenantStore() got, err := s.Create(t.Context(), tenants.CreateRequest{ - Name: "demo", Owner: "Alice@Example.org", Plan: tenants.Medium, DisplayName: "Demo", CreatedBy: "user:admin@example.org", + Name: "demo", Owner: "Alice@Example.org", DisplayName: "Demo", CreatedBy: "user:admin@example.org", }) if err != nil { t.Fatal(err) } - if got.Name != "demo" || got.Owner != "Alice@Example.org" || got.Plan != tenants.Medium || got.CreatedBy != "user:admin@example.org" { + if got.Name != "demo" || got.Owner != "Alice@Example.org" || got.DisplayName != "Demo" || got.CreatedBy != "user:admin@example.org" { t.Errorf("unexpected tenant: %+v", got) } @@ -45,21 +45,20 @@ func TestCreateWritesTheObject(t *testing.T) { t.Errorf("wrong object: %s %s in %s", obj.GetAPIVersion(), obj.GetKind(), obj.GetNamespace()) } owner, _, _ := unstructured.NestedString(obj.Object, "spec", "owner") - plan, _, _ := unstructured.NestedString(obj.Object, "spec", "plan") - if owner != "Alice@Example.org" || plan != "medium" { - t.Errorf("spec: owner %q plan %q", owner, plan) + if owner != "Alice@Example.org" { + t.Errorf("spec: owner %q", owner) + } + if _, found, _ := unstructured.NestedString(obj.Object, "spec", "plan"); found { + t.Error("a plan was written: the API knows none") } } -func TestCreateLeavesThePlanToTheDefaultOfTheXRD(t *testing.T) { +func TestCreateLeavesOutWhatWasNotAsked(t *testing.T) { s, client := newTenantStore() if _, err := s.Create(t.Context(), tenants.CreateRequest{Name: "demo", Owner: "a@b"}); err != nil { t.Fatal(err) } obj, _ := client.Resource(tenantsGVR).Namespace(TenantNamespace).Get(t.Context(), "demo", metav1.GetOptions{}) - if _, found, _ := unstructured.NestedString(obj.Object, "spec", "plan"); found { - t.Error("a plan was sent although none was asked for: the XRD has a default") - } if _, found, _ := unstructured.NestedString(obj.Object, "spec", "displayName"); found { t.Error("an empty display name was sent") } @@ -105,16 +104,16 @@ func ptr[T any](v T) *T { return &v } func TestPatchChangesOnlyWhatWasGiven(t *testing.T) { s, client := newTenantStore() - if _, err := s.Create(t.Context(), tenants.CreateRequest{Name: "demo", Owner: "a@b", Plan: tenants.Small, DisplayName: "Old"}); err != nil { + if _, err := s.Create(t.Context(), tenants.CreateRequest{Name: "demo", Owner: "a@b", DisplayName: "Old"}); err != nil { t.Fatal(err) } - got, err := s.Patch(t.Context(), "demo", tenants.PatchRequest{Plan: ptr(tenants.Large)}) + got, err := s.Patch(t.Context(), "demo", tenants.PatchRequest{DisplayName: ptr("New")}) if err != nil { t.Fatal(err) } - if got.Plan != tenants.Large || got.DisplayName != "Old" || got.Owner != "a@b" { - t.Errorf("after the plan: %+v", got) + if got.DisplayName != "New" || got.Owner != "a@b" { + t.Errorf("after the rename: %+v", got) } if _, err := s.Patch(t.Context(), "demo", tenants.PatchRequest{DisplayName: ptr("")}); err != nil { @@ -124,8 +123,8 @@ func TestPatchChangesOnlyWhatWasGiven(t *testing.T) { if name, _, _ := unstructured.NestedString(obj.Object, "spec", "displayName"); name != "" { t.Errorf("display name = %q, want it cleared", name) } - if plan, _, _ := unstructured.NestedString(obj.Object, "spec", "plan"); plan != "large" { - t.Errorf("plan = %q, a patch of the display name changed it", plan) + if owner, _, _ := unstructured.NestedString(obj.Object, "spec", "owner"); owner != "a@b" { + t.Errorf("owner = %q, a patch of the display name changed it", owner) } } @@ -246,7 +245,7 @@ func TestTenantOfReadsTheStatus(t *testing.T) { "name": "demo", "namespace": "phorge-system", "creationTimestamp": created.Format(time.RFC3339), "annotations": map[string]any{CreatedByAnnotation: "user:admin@example.org"}, }, - "spec": map[string]any{"owner": "a@b", "plan": "small", "displayName": "Demo"}, + "spec": map[string]any{"owner": "a@b", "displayName": "Demo"}, "status": map[string]any{ "namespace": "t-demo", "incusProject": "t-demo", "problems": "Alias 'x' doesn't exist", "conditions": []any{ diff --git a/internal/openapi/openapi.yaml b/internal/openapi/openapi.yaml index 0ee9161..c027322 100644 --- a/internal/openapi/openapi.yaml +++ b/internal/openapi/openapi.yaml @@ -109,9 +109,8 @@ paths: description: | Any person creates a tenant for themselves (`canCreateTenants` of `GET /v1/whoami`): they own it, `owner` is left out or is their own email. Every tenant has the same limits (2 VMs, 2 vCPU, 4 GiB of memory, 128 GiB of disk, 2 networks - and 2 profiles), so there is no plan to choose: leave `plan` out. It is deprecated and kept until the console stops - reading it: a `plan` other than `small` is `403`, and none changes a limit. A person owns a limited number of tenants: - past it the answer is `409` with the code `quota_exceeded`. A key never creates a tenant. + and 2 profiles), so there is nothing to choose and no `plan`: a body that gives one is `400`. A person owns a limited + number of tenants: past it the answer is `409` with the code `quota_exceeded`. A key never creates a tenant. The answer is `202`: the tenant exists but Crossplane takes about a minute to make its namespace, its Incus project and the three profiles `s`, `m` and `l`. It comes without a network: deploy one in it. Poll the @@ -179,9 +178,8 @@ paths: operationId: updateTenant summary: Change the display name description: | - The admins of the tenant, the owner among them, change its display name. The `plan` is deprecated and changes - no limit, since every tenant has the same ones: a body that gives it is `403`. The name and the owner cannot change: to hand a tenant over, give the new person the - `admin` role with a membership. + The admins of the tenant, the owner among them, change its display name. The name and the owner cannot change: to + hand a tenant over, give the new person the `admin` role with a membership. security: - bearerAuth: [] requestBody: @@ -546,8 +544,7 @@ paths: description: | The limits of the tenant (instances, vCPU, memory, disk, networks, profiles), the same for every tenant, and what the tenant holds. A stopped instance counts, as it does for Incus. The profiles are the ones its users made: `s`, `m` and - `l` are not counted. The `plan` is deprecated, it limits nothing and goes when the console stops reading it. A request that - would pass a limit is refused with `409` and the code `quota_exceeded`, and a message that says which. + `l` are not counted. A request that would pass a limit is refused with `409` and the code `quota_exceeded`, and a message that says which. security: - bearerAuth: [] responses: @@ -1509,12 +1506,9 @@ components: Quota: type: object required: - - plan - limits - used properties: - plan: - $ref: "#/components/schemas/Plan" limits: $ref: "#/components/schemas/QuotaFigures" used: @@ -2237,23 +2231,11 @@ components: type: string minLength: 1 maxLength: 100 - Plan: - type: string - deprecated: true - description: | - Deprecated: every tenant has the same limits (2 VMs, 2 vCPU, 4 GiB, 128 GiB of disk, 2 networks, 2 profiles), whatever - its plan, which is kept as it is read until the console stops using it and then removed. A new tenant is `small`; - another plan is `403` on creation and on change. - enum: - - small - - medium - - large Tenant: type: object required: - name - owner - - plan - phase - createdAt properties: @@ -2267,8 +2249,6 @@ components: type: string description: Email of the owner, who is `admin` of the tenant. It cannot change. example: alice@example.org - plan: - $ref: "#/components/schemas/Plan" phase: $ref: "#/components/schemas/Phase" problems: @@ -2313,8 +2293,6 @@ components: Email of the owner, exactly as it is in Authentik (case included). Leave it out: it is the caller's own email, and another one is `403`. example: alice@example.org - plan: - $ref: "#/components/schemas/Plan" displayName: type: string maxLength: 100 @@ -2323,8 +2301,6 @@ components: additionalProperties: false minProperties: 1 properties: - plan: - $ref: "#/components/schemas/Plan" displayName: type: string maxLength: 100 diff --git a/internal/tenants/tenants.go b/internal/tenants/tenants.go index c5d7697..a97c999 100644 --- a/internal/tenants/tenants.go +++ b/internal/tenants/tenants.go @@ -13,20 +13,6 @@ import ( "github.com/phorge-fr/phorge-api/internal/status" ) -// Plan is the quota plan of a tenant. It is deprecated: every tenant has the same limits, whatever its plan, and it is kept only -// until the console stops reading it. -type Plan string - -// The plans of the Tenant XRD. -const ( - Small Plan = "small" - Medium Plan = "medium" - Large Plan = "large" -) - -// Valid reports whether p is a plan. -func (p Plan) Valid() bool { return p == Small || p == Medium || p == Large } - // MaxDisplayName is the limit of the XRD (characters, not bytes). const MaxDisplayName = 100 @@ -49,7 +35,6 @@ type Tenant struct { Name string DisplayName string Owner string - Plan Plan CreatedAt time.Time CreatedBy string @@ -82,7 +67,6 @@ type CreateRequest struct { Name string `json:"name"` Owner string `json:"owner"` DisplayName string `json:"displayName"` - Plan Plan `json:"plan"` // CreatedBy is the subject of the caller, recorded on the object. Not part of the request body. CreatedBy string `json:"-"` @@ -91,7 +75,6 @@ type CreateRequest struct { // PatchRequest is what changes on a tenant. The name and the owner cannot: the owner is an OpenFGA tuple, which cannot be // edited, and to hand a tenant over a Membership with the admin role is created. type PatchRequest struct { - Plan *Plan `json:"plan"` DisplayName *string `json:"displayName"` } @@ -107,9 +90,6 @@ func (r CreateRequest) Validate() error { if !auth.SafeEmail(r.Owner) { problems = append(problems, "owner must be an email address") } - if r.Plan != "" && !r.Plan.Valid() { - problems = append(problems, "plan must be small, medium or large") - } if utf8.RuneCountInString(r.DisplayName) > MaxDisplayName { problems = append(problems, fmt.Sprintf("displayName must be at most %d characters", MaxDisplayName)) } @@ -122,11 +102,8 @@ func (r CreateRequest) Validate() error { // Validate checks the patch. func (r PatchRequest) Validate() error { var problems []string - if r.Plan == nil && r.DisplayName == nil { - problems = append(problems, "nothing to change: give plan or displayName") - } - if r.Plan != nil && !r.Plan.Valid() { - problems = append(problems, "plan must be small, medium or large") + if r.DisplayName == nil { + problems = append(problems, "nothing to change: give displayName") } if r.DisplayName != nil && utf8.RuneCountInString(*r.DisplayName) > MaxDisplayName { problems = append(problems, fmt.Sprintf("displayName must be at most %d characters", MaxDisplayName)) diff --git a/internal/tenants/tenants_test.go b/internal/tenants/tenants_test.go index 9fed850..e693ce6 100644 --- a/internal/tenants/tenants_test.go +++ b/internal/tenants/tenants_test.go @@ -35,12 +35,12 @@ func TestPhaseAt(t *testing.T) { } func TestCreateRequestValidate(t *testing.T) { - good := CreateRequest{Name: "demo", Owner: "alice@example.org", Plan: Medium, DisplayName: "Demo"} + good := CreateRequest{Name: "demo", Owner: "alice@example.org", DisplayName: "Demo"} if err := good.Validate(); err != nil { t.Fatal(err) } if err := (CreateRequest{Name: "demo", Owner: "alice@example.org"}).Validate(); err != nil { - t.Errorf("plan and display name are optional: %v", err) + t.Errorf("the display name is optional: %v", err) } if err := (CreateRequest{Name: "ab", Owner: "Alice@Example.org"}).Validate(); err != nil { t.Errorf("the owner keeps its case, a two letters name is fine: %v", err) @@ -58,7 +58,6 @@ func TestCreateRequestValidate(t *testing.T) { "an owner that is a wildcard": {Name: "demo", Owner: "*"}, "an owner with a relation": {Name: "demo", Owner: "a@b#admin"}, "an owner with a space": {Name: "demo", Owner: "a @b"}, - "an unknown plan": {Name: "demo", Owner: "a@b", Plan: "huge"}, "a display name too long": {Name: "demo", Owner: "a@b", DisplayName: strings.Repeat("é", MaxDisplayName+1)}, } { t.Run(name, func(t *testing.T) { @@ -74,7 +73,7 @@ func TestCreateRequestValidate(t *testing.T) { t.Errorf("100 characters were refused: %v", err) } - err := CreateRequest{Name: "D", Owner: "x", Plan: "huge"}.Validate() + err := CreateRequest{Name: "D", Owner: "x", DisplayName: strings.Repeat("a", MaxDisplayName+1)}.Validate() var invalid *InvalidError if !errors.As(err, &invalid) || len(invalid.Problems) != 3 { t.Errorf("every problem is reported at once: %v", err) @@ -82,15 +81,13 @@ func TestCreateRequestValidate(t *testing.T) { } func TestPatchRequestValidate(t *testing.T) { - large, bad, name := Large, Plan("huge"), "Production" + name := "Production" long := strings.Repeat("a", MaxDisplayName+1) empty := "" for name, ok := range map[string]PatchRequest{ - "a plan": {Plan: &large}, "a display name": {DisplayName: &name}, "an empty name clears": {DisplayName: &empty}, - "both": {Plan: &large, DisplayName: &name}, } { if err := ok.Validate(); err != nil { t.Errorf("%s: %v", name, err) @@ -98,7 +95,6 @@ func TestPatchRequestValidate(t *testing.T) { } for name, req := range map[string]PatchRequest{ "nothing": {}, - "an unknown plan": {Plan: &bad}, "a display name too long": {DisplayName: &long}, } { if err := req.Validate(); err == nil {