# Kubernetes temporary access

Issue a short-lived token for an existing service account using the customer-run
[Rust provisioner](/docs/guides/provisioner). Both inbound HTTPS and outbound-only
mode work with the same connection token. Configure every target in Seekrit;
no per-target environment variables, local files, or persistent volume are needed.

## Connect a cluster

In **Temporary access → Add target**, select **Kubernetes**, choose your registered
provisioner, and enter the cluster's HTTPS API endpoint, namespace, service-account
name and token audiences. Paste the cluster CA certificate if it uses a private CA.
TLS certificates and hostnames are always verified. Enter the management bearer
token in the credential field; the browser encrypts it and the target settings to
the provisioner before uploading them.

The management identity needs `create` on `serviceaccounts/token` for the chosen
service account, plus `create`, `get`, and `delete` on Secrets in that namespace.
The requested token inherits the existing service account's RBAC permissions.
Use a dedicated service account with only the access you intend to issue.

For example, this Role permits the provisioner to issue tokens for `reader` in `ci`.
Bind it to your management identity using a RoleBinding.

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: seekrit-token-manager
  namespace: ci
rules:
  - apiGroups: [""]
    resources: ["serviceaccounts/token"]
    resourceNames: ["reader"]
    verbs: ["create"]
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["create", "get", "delete"]
```

## Request and revoke access

Members and service tokens with an access grant use their existing Seekrit keys.
Request a lifetime of at least 15 minutes. The provisioner calls Kubernetes'
TokenRequest API and encrypts the resulting token directly to the requester.
The response includes the endpoint, namespace, service account, CA and actual
expiry; the cluster may issue a shorter lifetime. A token longer than the requested
lease is rejected and the lease's resources are queued for cleanup.

Each token is bound to a new, empty Secret with a unique lease name. Revoking or
expiring the lease deletes only that Secret, checking its ownership label and UID.
The existing service account and its roles stay intact. Kubernetes API token
validation checks the bound object; external JWT consumers that validate tokens
offline may accept the token until its signed expiry. Use short lifetimes.

## CLI and API

The same target can be registered with `seekrit dynamic target add --name ci-reader
--config target.json`, piping the management token on stdin. For example:

```json
{
  "provider": "kubernetes",
  "executor": "remote",
  "provisionerId": "prv_REPLACE_WITH_REGISTERED_ID",
  "settings": {
    "endpoint": "https://kubernetes.default.svc",
    "namespace": "ci",
    "serviceAccount": "reader",
    "audiences": ["https://kubernetes.default.svc"]
  },
  "maxTtlSeconds": 3600
}
```

Use `seekrit dynamic lease <id> --ttl 1h` to receive the decrypted credential.
The API uses the existing lease routes and `provider: "kubernetes"`; it relays
ciphertext and independently signed customer requests.

See [Kubernetes TokenRequest](https://kubernetes.io/docs/reference/kubernetes-api/authentication-resources/token-request-v1/)
for audience and bound-object behavior.
