Give host services kubernetes access #40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@hermes-bot I need a way for my systems to interact directly with kubernetes. Lurch has the credentials stored on it, and could do so itself, but I need other hosts to make kubectl calls as well. What would be the best way to do this? As a user, I'm using oidc through authentik for my access. Could this be done through authentik? Should it? This flows from #4, where chicken needs a way to inject secrets.
Short answer
Yes, this can be done through Authentik — and yes, it should be. The cluster already validates Authentik JWTs; what's missing is per-service machine identities. The one thing not to do is copy Lurch's admin credentials out to other hosts: the kubeconfig template sitting commented-out in
modules/kubernetes/client.nixissues acluster-admin(O=system:masters) cert — distributing that shape makes every host full admin, gives you one identity in the audit log, and revocation means CA rotation. Three tiers:A. Humans (your kubectl): keep exactly what's wired.
modules/kubernetes/master.nixalready runs the apiserver against Authentik (--oidc-issuer-url=https://auth.richardpickler.com/application/o/kubeapiserver/,--oidc-client-id=kube-apiserver, username claimemail, groups claimgroups), and thebootstrapAddonsbinding maps Authentik groupkubernetes→ cluster-admin. This is working as designed — don't extend it to machines.B. Host services: same issuer, machine identities via OAuth2 client credentials.
kubeapiserverOAuth2 app, enable theclient_credentialsgrant with a confidential client per host/service (svc-chicken, …). Since the apiserver readsemailandgroupsclaims, bind an expression scope mapping that emits them for machine tokens, e.g.{"email": "svc-chicken@services.richardpickler.com", "groups": ["kubernetes-host-services"]}.Group: oidcgroup:kubernetes-host-servicesto a deliberate ClusterRole. ⚠️ Do not add machine accounts to the Authentikkubernetesgroup — the bootstrapAddons binding would silently hand them cluster-admin.kubelogin-oidcis already installed on client hosts (modules/kubernetes/client.nix); point a kubeconfigusers[].execplugin at it with--grant-type client-credentials(exact flags depend on the kubelogin generation; a 5-line curl-against-the-token-endpoint exec plugin works identically if the binary is the older int128 flavor). Client secret comes from sops-nix, one per host.C. The concrete #4 need (chicken injecting postgres credentials): a scoped ServiceAccount is better than general host access.
pickler-postgres-k8s-synconly needs to create/updatesecretsin its target namespace(s) — it shouldn't hold anything broader:Feed the resulting token into a single-context kubeconfig against
https://lurch.lan:6443and drop it into the sops secret PR #6 already gates on (pickler.postgres.kubernetes.kubeconfigSecret) — the sync service activates with zero broader privileges, and revocation is deleting one Secret.What about client certs? They're the cluster-native machine identity and the repo is half-set-up for them (cfssl + certmgr in
client.nix,services.certmgrrenewing daily on lurch). But the commented template signs admin certs by hand, and K8s has effectively no cert revocation short of CA rotation. If you want this path anyway, do it as CSR auto-signing — each host generates its key locally, submits aCertificateSigningRequestwith bootstrap creds, certmgr signs against a SigningProfile (per-hostCN=host:<name>,O=kubernetes-host-services, short validity) — private keys never leave their host. More machinery than B; pick it only if you want the machine path to survive an Authentik outage.Should it be Authentik? Yes, with two forward-looking notes:
services.kubernetesmodule this cluster runs on is legacy upstream, so the rebuild is coming regardless — the OIDC flags, RBAC bindings, and both B and C carry over unchanged to k3s/kubeadm, so adopt them now.Suggested next step: pick the RBAC tier for host services (B), and I can PR the reusable NixOS module — sops secret for the client secret + exec-plugin kubeconfig template — plus the Authentik app/scope-mapping walk-through. C is ready to wire into PR #6 today.