A tenant requests access to Gateway API resources. After approval, a Capsule GlobalTenantResource distributes RoleBindings to that tenant’s namespaces. The subjects follow its owners, including owners and namespaces added later.

See Capsule’s GlobalTenantResources documentation for how the distributor selects tenant namespaces and reconciles generated resources. The permit controls the initial provisioning and its own cleanup policy.

Prerequisites

Install Capsule, Resource Permits, and the Gateway API CRDs and controller. Use an existing solar-system namespace owned by tenant solar, with the tenant label and default ServiceAccount. The requester needs permission to create ResourcePermits; the reviewer needs status-update permission and must match the template’s approvers. Replace the example reviewer names with your actual identities.

Install the shared executor permissions shown in the Grafana example:

kubectl apply -f playground/manifests/platform/globalresourcepermittemplates/rbac.yaml

The playground-gateway-api-editor ClusterRole grants access to namespaced Gateway API resources through RoleBindings. It does not grant access to GatewayClasses or CRD definitions. The template’s resolved execution identity also needs permission to read namespaces and ServiceAccounts and to manage GlobalTenantResources; see execution identities.

Define the template

The template derives the tenant from the requesting namespace. It has no parameters and requires manual approval.

# A provisioning permit permanently enables Gateway API access for all
# owners of the requesting Tenant, including owners and namespaces added later.
apiVersion: addons.projectcapsule.dev/v1beta2
kind: GlobalResourcePermitTemplate
metadata:
  name: gateway-api
  labels:
    company.com/consumer: "tenants"
  annotations:
    info.projectcapsule.dev/description: "Permanently grant tenant owners access to namespaced Gateway API resources."
    info.projectcapsule.dev/tags: "rbac,gateway-api"
    info.projectcapsule.dev/icon: "https://www.svgrepo.com/show/375342/cloud-api-gateway.svg"
spec:
  impersonation:
    name: capsule
    namespace: capsule-system
  namespaceSelectors:
    - matchExpressions:
        - key: capsule.clastix.io/tenant
          operator: Exists
  approvals:
    auto: false
    approvers:
      - kind: User
        name: kubernetes-admin
      - kind: User
        name: admin
  paramSchema:
    type: object
    additionalProperties: false
  context:
    resources:
      # An omitted namespace resolves to the ResourcePermit's namespace. Read
      # its default ServiceAccount to obtain the namespace without user input.
      - apiVersion: v1
        kind: ServiceAccount
        name: default
        index: localServiceAccount
        optional: false
      - apiVersion: v1
        kind: Namespace
        index: tenantNamespaces
        selector:
          matchExpressions:
            - key: capsule.clastix.io/tenant
              operator: Exists
  resources:
    - policy:
        creation: Owner
        protect: true
        force: false
        # Keep the distributor, and therefore its RoleBindings, after expiry.
        deletion: Orphan
      template: |-
        {{- $source := (index $.context.resources.localServiceAccount 0).metadata.namespace }}
        {{- $namespace := mustGetResourceByName $source $.context.resources.tenantNamespaces }}
        {{- $tenant := index $namespace.metadata.labels "capsule.clastix.io/tenant" }}
        ---
        apiVersion: capsule.clastix.io/v1beta2
        kind: GlobalTenantResource
        metadata:
          name: {{ printf "%s-gateway-api-access" $tenant | quote }}
        spec:
          scope: Namespace
          resyncPeriod: 60s
          pruningOnDelete: true
          serviceAccount:
            name: permit-example-reconciler
            namespace: capsule-system
          tenantSelector:
            matchLabels:
              kubernetes.io/metadata.name: {{ $tenant | quote }}
          resources:
            - generators:
                - missingKey: error
                  # This inner template is evaluated by GlobalTenantResource,
                  # so the subjects follow the Tenant's current owners.
                  template: |
                    {{`{{- if $.tenant.status.owners }}`}}
                    apiVersion: rbac.authorization.k8s.io/v1
                    kind: RoleBinding
                    metadata:
                      name: gateway-api-editors
                      namespace: {{`{{ $.namespace.metadata.name | quote }}`}}
                    roleRef:
                      apiGroup: rbac.authorization.k8s.io
                      kind: ClusterRole
                      name: playground-gateway-api-editor
                    subjects:
                    {{`{{- range $.tenant.status.owners }}`}}
                      - kind: {{`{{ .kind }}`}}
                    {{`{{- if eq .kind "ServiceAccount" }}`}}
                        name: {{`{{ last (splitList ":" .name) | quote }}`}}
                        namespace: {{`{{ index (splitList ":" .name) 2 | quote }}`}}
                    {{`{{- else }}`}}
                        apiGroup: rbac.authorization.k8s.io
                        name: {{`{{ .name | quote }}`}}
                    {{`{{- end }}`}}
                    {{`{{- end }}`}}
                    {{`{{- end }}`}}

Download platform/globalresourcepermittemplates/gateway-api-access.yaml

Apply it as a platform operator and wait for readiness:

kubectl apply -f playground/manifests/platform/globalresourcepermittemplates/gateway-api-access.yaml
kubectl wait --for=condition=Ready globalresourcepermittemplate/gateway-api --timeout=60s

Request access

apiVersion: addons.projectcapsule.dev/v1beta2
kind: ResourcePermit
metadata:
  name: gateway-api-access
  namespace: solar-system
spec:
  template:
    kind: GlobalResourcePermitTemplate
    name: gateway-api
  reason: Permanently enable Gateway API resources for the solar tenant's owners.
  params: {}

Download user/solar/resourcepermits/gateway-api-access.yaml

Submit the permit as a tenant requester, then have a configured approver review it with kubectl resource-permits review gateway-api-access -n solar-system.

Expected outcome and revocation

Once active, the permit creates the distributor. Capsule then reconciles a gateway-api-editors RoleBinding in each selected tenant namespace. Its subjects track the current tenant owners.

This example intentionally grants ongoing access: deletion: Orphan keeps the distributor and its RoleBindings after the permit expires or is deleted. To revoke that access, delete the generated <tenant>-gateway-api-access GlobalTenantResource; its pruningOnDelete: true removes the distributed RoleBindings. For temporary resources that should be removed at expiry, use deletion: Remove as in the temporary configuration example.