Skip to content

Give a pod its own Guard node

A connector lets the network reach the cluster. A sidecar is for the other direction: a pod that has to reach the network, such as a deployment tool that connects to servers, or a job that reads a database on another site.

A labelled pod gets a Guard client beside its containers. The pod becomes a node of the network and joins with its own service account token. Guard checks that token against a trusted issuer. Nothing secret is stored in the cluster.

  • The operator installed, as in Connect a Kubernetes cluster to Guard. The versions on that page apply.
  • cert-manager in the cluster. The operator uses it for the injection webhook’s certificate.
  • A Guard address with a publicly trusted certificate. A pod whose connection sets caBundleSecretRef is refused.
  • Namespaces that allow privileged pods. The sidecar adds the capabilities NET_ADMIN and MKNOD. The baseline and restricted Pod Security levels refuse NET_ADMIN, so each namespace with injected pods must enforce privileged. A namespace labelled baseline or restricted is refused even if your admission configuration exempts the pods.
  • On a private Google Kubernetes Engine cluster, a firewall rule that allows TCP 9443 from the control plane’s address range to the nodes. The injection webhook listens on that port. Without the rule, every labelled pod is refused with failed calling webhook … context deadline exceeded.
  • A container runtime that allows the tunnel device. runc 1.2.0 to 1.2.3 refuse it to unprivileged containers, and 1.2.4 restores it. Some containerd configurations also leave it out of the devices a container may open.
Terminal window
helm upgrade guard-operator \
oci://registry.authwise.com/authwise/guard-operator/charts/guard-operator \
--version 0.3.1 --namespace guard-system --reset-then-reuse-values \
--set injection.enabled=true \
--set injection.imagePullSecret=authwise-registry
  1. Find the cluster’s service account issuer.

    Terminal window
    kubectl get --raw /.well-known/openid-configuration | jq -r .issuer

    On Google Kubernetes Engine the issuer is https://container.googleapis.com/v1/projects/PROJECT/locations/LOCATION/clusters/CLUSTER.

  2. Add it to the network as a trusted issuer. Choose where Guard gets the issuer’s signing keys:

    • Discover, when the Guard control plane can reach the issuer’s published keys. That’s true of Google Kubernetes Engine, and of Amazon EKS and Azure AKS with the OIDC issuer turned on.

      Terminal window
      awctl guard trusted-issuers create --display-name ops-cluster \
      --issuer ISSUER --discover
    • Upload, for a cluster whose keys the control plane can’t reach.

      Terminal window
      kubectl get --raw /openid/v1/jwks > jwks.json
      awctl guard trusted-issuers create --display-name ops-cluster \
      --issuer ISSUER --keys-file jwks.json

      Uploaded keys go stale when the cluster rotates them. See Keep a private cluster’s keys current.

  3. Add a rule for each service account that may join. Nothing joins until a rule admits it.

    Terminal window
    awctl guard trusted-issuers rules create ops-cluster \
    --subject system:serviceaccount:deploy:argocd-application-controller \
    --node-name-prefix ops-argocd \
    --node-group deployers \
    --ephemeral
    SettingWhat to enter
    Subjectsystem:serviceaccount:NAMESPACE:SERVICE_ACCOUNT. Use the pod’s serviceAccountName, or default if it sets none. It’s matched exactly. There are no patterns.
    Node name prefixAt most 32 characters, starting and ending with a letter or digit. The node is named PREFIX-POD_NAME.
    EphemeralOn for pods of a Deployment or a Job. Their nodes are removed when the pod stops cleanly, or after about an hour offline. Off for pods of a StatefulSet and pods you mark persistent.
    Node groupThe group the nodes join. Its grants decide what the pods can reach.
    Maximum nodesHow many nodes the rule may hold at once. The default is 100.

You can do the same in the console. On the network’s Enrollment tab, select Add a trusted issuer. Then open the issuer and select Add rule under Who may join. The issuer’s page also shows the Audience. Or use the authwise_guard_trusted_issuer and authwise_guard_trusted_issuer_rule Terraform resources. In the console and awctl, these changes ask for your second factor. See Changes that need a second factor.

Sidecars join by workload identity, so they need a connection of that kind. Mark it default and pods need no further setting.

apiVersion: connect.guard.authwise.com/v1alpha1
kind: GuardConnection
metadata:
name: ops
spec:
address: guard.example.com
network: tenants/t-abc123/networks/n-def456
clusterName: ops
default: true
identity:
method: WorkloadIdentity

The connection that joins by enrollment key stays for your connectors. Name it in each connector’s spec.connection.

  1. Prepare the pod’s namespace: allow privileged pods, and add the registry credential. The operator doesn’t copy credentials between namespaces.

    Terminal window
    kubectl label namespace deploy pod-security.kubernetes.io/enforce=privileged
    kubectl -n deploy create secret docker-registry authwise-registry \
    --docker-server=registry.authwise.com \
    --docker-username=REGISTRY_USER \
    --docker-password="$(cat token)"
  2. Label the pod template.

    spec:
    template:
    metadata:
    labels:
    connect.guard.authwise.com/inject: "true"

The pod’s own containers start only after the sidecar has joined and its routes and names are in place. A short Guard outage delays a rollout and doesn’t fail it.

KeyKindMeaning
connect.guard.authwise.com/inject: "true"Label on the podAsks for the sidecar.
connect.guard.authwise.com/connection: NAMELabel on the pod or its namespaceWhich connection to use. Without it, the default connection.
connect.guard.authwise.com/persistent: "true"Annotation on the podKeeps the node when the pod stops. Pods of a StatefulSet are persistent without it.
  • A container named guard runs beside the pod’s own, with 10m CPU and 32Mi of memory requested and a 128Mi memory limit.
  • The pod’s DNS goes through the sidecar. Names that Guard owns are answered from the network. Every other name goes to the cluster’s DNS as before, with the same search list.
  • The pod’s termination grace period is raised to 15 seconds if it was lower, so that an ephemeral node can leave cleanly.
  • A persistent pod gets a Secret named guard-node-POD_NAME in its namespace. It holds the node’s key. Don’t delete it.

A labelled pod is refused at admission, with the reason, when:

  • the cluster runs Kubernetes older than 1.29;
  • its namespace enforces baseline or restricted;
  • no connection is named and none is the default, or two are;
  • its connection joins by enrollment key, or sets caBundleSecretRef;
  • it sets hostNetwork: true, dnsPolicy: Default, or dnsPolicy: None with no name servers;
  • the operator can’t find the cluster’s DNS address. Set spec.dns.clusterDNS on the connection;
  • it’s marked persistent and has no name at admission. A Deployment’s pods are like that. Persistent pods need a StatefulSet, or a pod that you name yourself.
Terminal window
kubectl -n deploy get pod POD -o jsonpath='{.metadata.annotations.connect\.guard\.authwise\.com/injected}'
kubectl -n deploy logs POD -c guard

In Guard, the node appears as PREFIX-POD_NAME, and its page shows the rule it joined by. If the sidecar doesn’t start:

  • The join is refused. The sidecar’s log says the identity token was not accepted, with the token’s issuer and subject. No rule matches that subject exactly, the rule is at its maximum, the issuer’s keys are stale, or the connection’s network uses short names where it needs ids.
  • The sidecar’s log says the container runtime refuses /dev/net/tun, and the pod stays in Init. See Before you begin. Upgrade the runtime, or have your platform team allow the device c 10:200 to the pod.
  • The image can’t be pulled. The pod’s namespace has no Secret with the name set in injection.imagePullSecret, which is authwise-registry in this guide.

Keys that you upload by hand go stale when the cluster rotates its signing keys, and pods then can’t join. To keep them current without a person, let one connector report them.

  1. Set issuerKeySource: true on one connector in the cluster. It must join by enrollment key.

    spec:
    issuerKeySource: true
  2. Read the issuer address and the connector’s node names.

    Terminal window
    kubectl -n monitoring get gconnector observability \
    -o jsonpath='{.status.issuerKeys.issuer}{"\n"}{.status.nodes}{"\n"}'
  3. In Guard, name one of those nodes as the trusted issuer’s key source.

    Terminal window
    awctl guard trusted-issuers update ops-cluster --key-source-node NODE_NAME

That node reports the cluster’s keys whenever they change, under its own identity. Upload the keys once first, or pods can’t join until the first report arrives.

A change reaches Guard in up to 11 minutes: the operator reads the cluster’s keys every 10 minutes, and the node reports within about a minute after that. Rotate by adding the new key while the old one still verifies, and wait at least 11 minutes before you retire the old one.

Guard holds a report that would replace every key at once. Pods keep joining with the stored keys, and the trusted issuer shows the held keys for an administrator to accept:

Terminal window
awctl guard trusted-issuers describe ops-cluster
awctl guard trusted-issuers update ops-cluster --adopt-held-keys

While the key-source node is down, a rotation waits for it. You can name another of the connector’s nodes instead.

The injection webhook fails closed: when no operator pod is ready, a labelled pod is refused. Unlabelled pods are never affected. The operator runs two pods by default, with a rolling update that keeps one ready and a PodDisruptionBudget. With --set replicas=1, labelled pods are refused for the seconds the operator takes to restart.

helm uninstall keeps the webhook configuration. While the operator is uninstalled, new pods with the inject label are refused. Install the operator again, or delete the webhook configuration to admit them without a sidecar:

Terminal window
kubectl delete mutatingwebhookconfiguration guard-operator