Skip to content

Day 2

Rotate cluster credentials

Keep the published kubeconfig and talosconfig short-lived. Change a CA of a cluster when it is necessary.

Item The operator
Admin kubeconfig <cluster>-kubeconfig Issues it again when less than one third of its TTL is left
Admin talosconfig <cluster>-talosconfig The same
Reader talosconfig <cluster>-talosconfig-reader Publishes it when readerTalosconfig: true
Talos, Kubernetes and etcd CAs Does not rotate them. You do it with talosctl.
  1. Set spec.credentials on the TalosCluster.

    spec:
    credentials:
    ttl: 8h
    readerTalosconfig: true
  2. Apply it.

    Terminal window
    kubectl apply -f cluster.yaml

    The operator replaces a credential with a longer TTL at once.

  3. Read when the first published credential expires.

    Terminal window
    kubectl get taloscluster prod -o jsonpath='{.status.credentialsExpireAt}'

A tool that copies a credential out of the cluster must copy it again before that time.

talosctl rotate-ca changes the machine configs directly. The operator still renders with the old bundle. Its dry run then shows drift, and a Config rollout would put the old CA back. While the operator holds the bundle (SecretsBundleHeld=True), the operator proposes and plans no rollout that applies a config. Between step 1 and step 4 there is no hold yet.

  1. Rotate the CA on each node of the cluster with talosctl, as the Talos documentation says. The operator continues with the old bundle.

  2. Read the machine config of one control plane after the rotation.

    Terminal window
    talosctl -n <control-plane> read /system/state/config.yaml > cp.yaml
  3. Make the new bundle from it.

    Terminal window
    talosctl gen secrets --from-controlplane-config cp.yaml -o secrets.yaml
  4. When each machine trusts the new bundle, put it into the Secret that spec.secretsRef names. The key must be secrets.yaml.

    Terminal window
    kubectl -n pk-metal create secret generic prod-talos-secrets --from-file=secrets.yaml \
    --dry-run=client -o yaml | kubectl apply -f -
  5. Delete the two files. They hold the keys of the cluster.

    Terminal window
    shred -u cp.yaml secrets.yaml
  6. Make sure that the cluster shows SecretsBundleHeld=True. The operator still uses its copy.

    Terminal window
    kubectl describe taloscluster prod
  7. Delete the copy of the old bundle.

    Terminal window
    kubectl -n pk-metal delete secret prod-bundle-applied

    The operator takes the bundle from the spec and makes a new copy.

  • SecretsBundleHeld=False.
  • kubectl --kubeconfig prod.kubeconfig get nodes works with a fresh copy of the kubeconfig.

If you changed the bundle Secret by mistake, put the old bundle back. SecretsBundleHeld returns to False.