Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions access/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ func Run(ctx context.Context, o *Options) error {
if err != nil && !errors.Is(err, context.Canceled) {
return fmt.Errorf("rbac provider failed: %w", err)
}
<-serveErr
return nil
return <-serveErr
case err := <-serveErr:
return err
}
Expand Down
58 changes: 43 additions & 15 deletions tenancy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ root
│ │
│ ├── web ................... WorkspaceType: project
│ │ APIBinding tenancy-access ... from the WorkspaceType
│ │ ClusterRole tenancy.contrib.kcp.io:role:admin
│ │ ClusterRole tenancy.platform.kcp.io:role:admin
│ │ ClusterRoleBinding ...:membership:alice-admin
│ │ Namespace "default" ... created by the operator
│ │
Expand Down Expand Up @@ -203,6 +203,14 @@ run it twice and the second run is a no-op. Quote `"$KUBECONFIG"` — unset
and unquoted, the shell drops the argument and `--kubeconfig` swallows the
next flag, giving the baffling `load kubeconfig: stat --workspace-path`.

Platform administrators — whoever creates and deletes Tenants — are named
here too: `--platform-admin-user` and `--platform-admin-group` (both
repeatable) bind them to `tenancy.platform.kcp.io:platform-admin` in the
store, a role that may enter it and manage Tenants and nothing else. The
binding holds exactly the identities of the latest run, so dropping one
from the flags revokes it. In production, name a group your identity
provider asserts rather than individual users.

### 5. Run the operator

```sh
Expand Down Expand Up @@ -304,7 +312,7 @@ Workspace names are DNS labels; display names are arbitrary UTF-8. The
- `slug` (default): lowercase the display name, collapse everything else to
dashes ("Acme Corp" → `acme-corp`). On collision with a workspace owned by
a different object, fall back to the slug plus a hash of the object's UID.
Ownership is tracked with a `tenancy.contrib.kcp.io/owner-uid` label, so
Ownership is tracked with a `tenancy.kcp.hub/owner-uid` label, so
reconciles converge without storing decisions anywhere.
- `uid`: always name by UID hash. Opaque, but immune to display-name games.

Expand All @@ -317,7 +325,7 @@ always proposes the same candidates.
front-proxy:

```
POST /services/tenancy/apis/tenancy.contrib.kcp.io/v1alpha1/selftenancyreviews
POST /services/tenancy/apis/tenancy.platform.kcp.io/v1alpha1/selftenancyreviews
```

The caller POSTs an empty object; the answer lists their tenants with
Expand Down Expand Up @@ -410,8 +418,12 @@ is for a self-signed local serving certificate; in a deployment pass
`--certificate-authority` instead.

`kubeconfig` is the other half of a login: it asks the virtual workspace
what the caller can reach and writes one context per tenant and per
project, each pointing at that workspace's own URL. There is still no user
what the caller can reach and writes one context per **project**, each
pointing at that workspace's own URL. Projects only, because a tenant
workspace is where this system keeps its own records — a Membership
materializes RBAC in that tenant's projects, never in the tenant itself,
so no member can enter it and a context for it would only ever answer
`Forbidden`. There is still no user
registry to enrol into — `login` obtains a credential, it does not create
an identity. Issuing identities belongs to your provider, and a
`Membership` only records what one may do.
Expand Down Expand Up @@ -471,8 +483,8 @@ PKI=$PWD/pki # or tenancy/.e2e/pki
# ask who you are:
curl -ks --cert "$PKI/alice.crt" --key "$PKI/alice.key" \
-X POST -H 'Content-Type: application/json' \
-d '{"apiVersion":"tenancy.contrib.kcp.io/v1alpha1","kind":"SelfTenancyReview"}' \
https://localhost:9445/services/tenancy/apis/tenancy.contrib.kcp.io/v1alpha1/selftenancyreviews
-d '{"apiVersion":"tenancy.platform.kcp.io/v1alpha1","kind":"SelfTenancyReview"}' \
https://localhost:9445/services/tenancy/apis/tenancy.platform.kcp.io/v1alpha1/selftenancyreviews

# ...and whether the directory is being fed at all:
curl -ks --cert "$PKI/alice.crt" --key "$PKI/alice.key" \
Expand All @@ -490,6 +502,15 @@ Reading the answers:
- `403 ... authentication required` means no certificate was presented at
all; the review is only served to an authenticated caller.

## Regenerating the schemas

The `apiresourceschema-*.yaml` assets are generated from the Go types by
`make generate` (controller-gen + kcp's `apigen`; see
[../hack/update-apiresourceschemas.sh](../hack/update-apiresourceschemas.sh)).
After changing anything under `sdk/apis/`, run it and commit the result —
and if a schema's name changed, update `ExportsOrder` in
[config/apiexport/bootstrap.go](config/apiexport/bootstrap.go).

## Testing

From the repository root:
Expand Down Expand Up @@ -541,14 +562,21 @@ SelfTenancyReview scenarios authenticate with.
identity exists because your IdP issued it a credential, and a
`Membership` names it verbatim. A typo in a subject name is not an
error, it is a grant nobody holds.
6. **There is no tenant self-service.** The virtual workspace serves
`SelfTenancyReview` and nothing else, so Projects and Memberships are
written straight to kcp by someone holding an admin kubeconfig —
`tenancyctl` included. A tenant cannot manage their own projects,
because the tier those objects live in names no tenant identity. The
intended shape is for those writes to arrive through the virtual
workspace, which would hold the only credential into that tier and
could enforce guards a direct write bypasses.
6. **Self-service is narrow, and mediated.** Besides `SelfTenancyReview`,
the virtual workspace accepts exactly three writes, each performed with
its own credential into the tenant tier rather than a grant to the
caller:
- `SelfTenantRequest` gives a caller their first tenant, with the
caller as its admin. It is off unless the deployment passes
`--self-service-tenants`, and `--self-service-tenant-groups` limits it
to groups the identity provider asserts.
- `SelfProjectRequest` creates a project in a tenant the caller
administers. The caller names the project and nothing else.
- `memberships` lists, grants and revokes access in tenants the caller
administers.

Anything else — deleting a tenant or project, renaming one — is still
written straight to kcp by someone holding an admin kubeconfig.
7. **The operator is not an administrator, and that is load-bearing.** It
holds no admin client; every write goes through one of the four exports,
so its reach is exactly their claims. The flip side is that a workspace
Expand Down
18 changes: 16 additions & 2 deletions tenancy/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func newInitCommand() *cobra.Command {
workspaceType string
serverUsers []string
serverGroups []string
adminUsers []string
adminGroups []string
timeout time.Duration
)

Expand Down Expand Up @@ -109,10 +111,17 @@ root down. Idempotent: safe to run on every pod start and every upgrade.`,
if err != nil {
return fmt.Errorf("resolve workspace path %s: %w", storePath, err)
}
if err := bootstrap.BindStore(ctx, storeCfg, result); err != nil {
if err := bootstrap.BindStore(ctx, storeCfg, result, bootstrap.Options{
ServerUsers: serverUsers,
ServerGroups: serverGroups,
}); err != nil {
return fmt.Errorf("bind the Tenant API into %s: %w", storePath, err)
}
logger.Info("tenant store ready", "workspace", storePath)
if err := bootstrap.GrantPlatformAdmins(ctx, storeCfg, adminUsers, adminGroups); err != nil {
return fmt.Errorf("grant platform admins in %s: %w", storePath, err)
}
logger.Info("tenant store ready", "workspace", storePath,
"platformAdminUsers", adminUsers, "platformAdminGroups", adminGroups)
}
if tenantsWorkspace != "" {
tenantsPath, err = accessbootstrap.JoinWorkspacePath(workspacePrefix, tenantsWorkspace)
Expand Down Expand Up @@ -187,6 +196,11 @@ root down. Idempotent: safe to run on every pod start and every upgrade.`,
"or the virtual workspace does not run as this bootstrap's own credential.")
cmd.Flags().StringSliceVar(&serverGroups, "server-group", nil,
"Additional Group to grant the server role to, repeatable.")
cmd.Flags().StringSliceVar(&adminUsers, "platform-admin-user", nil,
"User who may manage Tenants in the store workspace, repeatable. Bound to a role "+
"that allows exactly that; anyone left off the list on a later run loses it.")
cmd.Flags().StringSliceVar(&adminGroups, "platform-admin-group", nil,
"Group, as the identity provider asserts it, whose members may manage Tenants, repeatable.")
cmd.Flags().DurationVar(&timeout, "timeout", 3*time.Minute,
"Overall time budget for installing and verifying.")

Expand Down
5 changes: 5 additions & 0 deletions tenancy/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"k8s.io/klog/v2"

"github.com/kcp-dev/contrib-virtual-workspaces/tenancy/pkg/cli"
)

// Execute runs the tenancy binary.
Expand All @@ -45,6 +47,9 @@ func Execute() error {
root.AddCommand(newInitCommand())
root.AddCommand(newOperatorCommand())
root.AddCommand(newVirtualWorkspaceCommand())
// seed is shared with the CLI: one idempotent command any environment
// (Tilt, demos, CI) uses to converge on baseline tenancy data.
root.AddCommand(cli.NewSeedCommand())

return root.Execute()
}
Expand Down
4 changes: 2 additions & 2 deletions tenancy/config/apiexport/apiexport-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
spec:
resources:
- name: tenants
group: tenancy.contrib.kcp.io
schema: v1alpha1.tenants.tenancy.contrib.kcp.io
group: tenancy.platform.kcp.io
schema: v260926-3d181e5.tenants.tenancy.platform.kcp.io
storage:
crd: {}
8 changes: 4 additions & 4 deletions tenancy/config/apiexport/apiexport-tenancy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ metadata:
spec:
resources:
- name: projects
group: tenancy.contrib.kcp.io
schema: v1alpha1.projects.tenancy.contrib.kcp.io
group: tenancy.platform.kcp.io
schema: v260924-7813b03.projects.tenancy.platform.kcp.io
storage:
crd: {}
- name: memberships
group: tenancy.contrib.kcp.io
schema: v1alpha1.memberships.tenancy.contrib.kcp.io
group: tenancy.platform.kcp.io
schema: v260924-7813b03.memberships.tenancy.platform.kcp.io
storage:
crd: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
apiVersion: apis.kcp.io/v1alpha1
kind: APIResourceSchema
metadata:
name: v260924-7813b03.memberships.tenancy.platform.kcp.io
spec:
group: tenancy.platform.kcp.io
names:
kind: Membership
listKind: MembershipList
plural: memberships
singular: membership
scope: Cluster
versions:
- name: v1alpha1
schema:
description: |-
Membership grants one subject one role in one tenant, or in one project
of that tenant. The operator materializes it as RBAC in the target
workspace; deleting the Membership removes that RBAC again.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: MembershipSpec is the desired state of a Membership.
properties:
project:
description: |-
Project optionally narrows the grant to one project of the tenant.
Empty means the grant applies to the tenant's workspace, which every
project workspace nests under.
type: string
role:
description: 'Role is the access level granted: view, edit or admin.'
enum:
- view
- edit
- admin
type: string
subject:
description: Subject is who the grant is for.
properties:
kind:
description: Kind is User or Group.
enum:
- User
- Group
type: string
name:
description: |-
Name is the username or group name, compared verbatim against the
identity kcp authenticates. No issuer prefixes are added or stripped
here; the deployment's authentication configuration must agree with
kcp's.
type: string
required:
- kind
- name
type: object
tenant:
description: Tenant names the Tenant (in the same workspace) the grant
applies to.
type: string
required:
- role
- subject
- tenant
type: object
status:
description: MembershipStatus is the observed state of a Membership.
properties:
message:
type: string
phase:
description: |-
Phase describes where a tenancy object is in its lifecycle. It is a
coarse, human-first signal; Message carries the detail when a phase is
not Ready.
type: string
type: object
required:
- spec
type: object
served: true
storage: true
subresources:
status: {}
Loading
Loading