Commit Graph
15 Commits
Author SHA1 Message Date
Abhinav Pandey 407218a442 feat(controller): adopt the cluster the NVKE controller runs (#2415)
* feat(controller): adopt the cluster the controller runs on behind a flag

Add POST /clusters/self-adopt, which records the cluster the controller runs
on as a cluster NVKE manages, without running kubeadm init. The endpoint is
served only when clusterSelfAdoptionEnabled is set in nvke-controller-config
(chart value clusterSelfAdoptionEnabled, default false). Otherwise it answers
400.

The controller reads the cluster with its own service account: the
control-plane Nodes, each with an InternalIP, and the Kubernetes version and
pod and service CIDRs from kube-system/kubeadm-config. The request carries
only what NVKE cannot read: name, NICo site and VPC (orgID optional), CNI
plugin and version, and etcdEncrypted. While the flag is on, the chart grants
that service account list on Nodes and get on kube-system/kubeadm-config.
Self-adopt returns 400 for no control-plane node, a node without an
InternalIP, a kubelet that differs from kubeadm-config, a version that is not
X.Y.Z, no or unsupported pod or service CIDRs, a second adoption, or an
existing Cluster API Cluster of the same name.

The adopted control plane stays with its operator, outside NVKE. Adoption
marks the cluster and its control-plane nodes as adopted, records desiredCount
as their number with no control-plane machine settings, and turns off
recycling, automatic scale-down and rebalancing:

- PATCH /clusters/{id} refuses turning those back on, controlPlaneConfig.nico,
  controlPlaneKubernetesVersion, any desiredCount change and any control-plane
  rollout field.
- DELETE /nodes/{id} on an adopted node returns 409, refused in the handler.
- The node-status sync never marks an adopted node for recycling, so
  control-plane remediation never replaces it.

DELETE /clusters/{id} on an adopted cluster removes only NVKE's records and
leaves the cluster running. It returns 409 while the cluster has node pools,
so their workers are drained and released through the node pool delete first.
TeardownCluster then deletes the Cluster API Cluster and NicoCluster and the
adopted node and cluster rows, and never tears down a node.

An adopted cluster gets OIDCAuthEnabled false, since NVKE cannot configure its
API servers. Its provisioning workflow applies only the Cluster API scaffold:
node-local DNS and the Pod Security namespace labels stay with the operator.

Signed-off-by: Abhinav Pandey <abhinavmpandey08@gmail.com>

* fix(controller): keep maintenance off an adopted cluster and serialize self-adopt

Address review on the self-adopt change.

Keep NVKE from changing an adopted control plane in place:
- PATCH /clusters/{id} refuses turning on enableEtcdEncryption or enableOidc
  for an adopted cluster, alongside the existing control-plane refusals.
- Scheduled certificate renewal skips an adopted cluster.
- stableControlPlane refuses an adopted control plane, which keeps on-demand
  certificate renewal and etcd key rotation off it.

Make "adopts at most one cluster" hold across concurrent requests:
SelfAdoptCluster takes a transaction-scoped advisory lock (LockSelfAdoption)
and checks for an adopted cluster again inside the transaction that records
it, so a second adoption gets a 400. Also fix a stale comment that said an
adopted record cannot be deleted.

Signed-off-by: Abhinav Pandey <abhinavmpandey08@gmail.com>

---------

Signed-off-by: Abhinav Pandey <abhinavmpandey08@gmail.com>
2026-11-30 15:32:32 -08:00
Meet Vadaria 8cf1dd3faf feat(chart): grant CAPLL tenant Node access when launchLayer is enabled (#2139)
With the shared OIDC provider on, the management plane reaches tenant clusters through a SPIRE kubeconfig, and CAPLL reads that same kubeconfig to set each Node's providerID. The tenant RBAC manifest bound only the CAPI controllers, so CAPLL authenticated and was then denied. It now carries nvke:capll-manager (nodes get, list, patch) for spiffe.capllManagerSubject when supportedInfraProviders includes launchLayer.

With token exchange and no subject the binding is left out rather than failing the render, so a site that already grants CAPLL through tenantAccess.additionalRBAC keeps upgrading.

Signed-off-by: Meet Vadaria <mvadaria@nvidia.com>
2026-11-06 09:16:04 +05:30
Ryan Bever ab0154a7bc feat(controller): authorize SPIFFE bootstrap identities (#2130)
Add a controller that grants labeled, joining Machines the tenant RBAC required by kubeadm. Reconcile six kubeadm bindings from resolved SPIFFE identities and remove subjects after each Machine receives a node reference.

Gate the controller's tenant permissions on the bootstrap controller setting, report synchronization through Machine conditions, and cover the behavior with unit and chart assertions. CSR approval remains separate.

Signed-off-by: Ryan Bever <rbever@nvidia.com>
2026-11-05 07:23:44 -07:00
Terry Howe 589d922c83 feat(chart): make the tenant RBAC ConfigMap name a value and move it to nvke (#1891)
* feat(chart): make the tenant RBAC ConfigMap name a value and move it to nvke

The nke-rbac ConfigMap name was a literal in two templates and a compiled
constant in controller/internal/nvkerbac, so a site could not keep it while the
chart's defaults moved. rbacConfigMap.name now drives the ConfigMap, the Role
and RoleBinding that grant get on it, and that Role's resourceNames, and the
controller reads it from rbacConfigMapName in nvke-controller-config rather
than from the constant. The default is nvke-rbac; a site installed before the
value pins nke-rbac, which is also what the Go fallback resolves to, so a
binary upgrade alone never moves a site that has not pinned.

The Role's resourceNames is the entry that matters: a ConfigMap the Role does
not name renders clean, installs clean, and is then denied at reconcile time,
leaving tenant RBAC unapplied. check_pinnable_names now asserts all four
consumers plus the rendered config key follow the value together.

nvkerbac.Source carries the namespace and the name as one value, because a name
resolved against the wrong namespace silently reads nothing — and a missing
read degrades the reserved-subject control that stops a fleet-wide OIDC
provider claiming an NVKE identity.

Closes #1862

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix(chart): follow rbacConfigMap.name in the RBAC and identity assertions

chart-rbac-check looked up a literal nke-rbac ConfigMap and failed once the
default moved. It asserts what the manifest grants, not what it is called, so
it now renders with rbacConfigMap.name set and resolves the ConfigMap by that;
moving the default again cannot break it.

chart-identity-assertions.py had the same literal in two scenario-scoped
places. Both passed only because the legacy scenario pins the old name and the
default scenario renders no RBAC ConfigMap at all, so the namespace and SPIFFE
subject checks silently skipped a default render. Both now read the scenario's
own name, and each scenario asserts rbacConfigMapName in its rendered config.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix(chart): quote the rendered RBAC ConfigMap name

rbacConfigMap.name is operator-supplied, and a DNS-1123-valid name YAML 1.1
reads as another scalar type (n, y, true, off) rendered as a bare scalar: the
ConfigMap metadata.name and the Role resourceNames entry both became booleans
and the install failed. Quote both. The Role and RoleBinding names interpolate
after controller.fullname and a dash, so they are already strings.

Signed-off-by: Terry Howe <thowe@nvidia.com>

---------

Signed-off-by: Terry Howe <thowe@nvidia.com>
2026-10-28 16:54:03 -04:00
Giuseppe Laguteta 2b483215c9 fix(controller): restrict additional RBAC objects (#1915)
* fix(controller): restrict additional RBAC objects

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>

* fix(controller): require namespaces for tenant roles

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>

---------

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>
2026-10-22 14:49:24 -07:00
Giuseppe Laguteta c919cb7284 feat(controller): configure additional tenant RBAC (#1896)
* feat(controller): configure additional tenant RBAC

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>

* fix(controller): validate additional RBAC identities

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>

* fix(controller): distinguish tenant RBAC identity sources

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>

---------

Signed-off-by: Giuseppe Laguteta <glaguteta@nvidia.com>
2026-10-22 17:09:04 -04:00
Terry Howe a9aa1b975d refactor(chart): rename nkeSystemNamespace and nkeOIDCAuth values keys, failing on the old ones (#1562)
* refactor(chart): rename nkeSystemNamespace and nkeOIDCAuth values keys, failing the render on the old ones

Helm ignores an unknown values key silently, so a site still setting the old keys would fall back to chart defaults, including tenant-cluster OIDC reverting to disabled. Rename both keys to nvkeSystemNamespace and nvkeOIDCAuth, keep the old keys in values.yaml empty, and add a render guard that fails naming the replacement.

Part of #1496. Closes #1550.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix(chart): key the renamed-values guard off presence, not truth

An explicitly supplied empty map is false in a Helm condition, so
--set-json 'nkeOIDCAuth={}' slipped past the guard and rendered on the
new key's defaults. Drop the empty defaults for both legacy keys so
presence only ever comes from the caller, switch the guard to hasKey,
and assert the empty-map case.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix: rename the last nkeOIDCAuth readers the chart rename missed

The site deploy path still wrote nkeOIDCAuth into the controller values,
which the new guard refuses outright, and the CAPD and NICo VMs e2e
preflights still read nkeOIDCAuth.enabled from the installed release, so
they saw null and failed the run.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* docs(chart): document the renamed values keys and their replacements

Signed-off-by: Terry Howe <thowe@nvidia.com>

---------

Signed-off-by: Terry Howe <thowe@nvidia.com>
2026-10-14 10:27:21 -06:00
Terry Howe 5427e14ac7 refactor: launch rename E, identity and RBAC dual-accept windows and nke: prune (#1563)
* refactor: accept both identity spellings and rename tenant RBAC to nvke

Accept both forms for one release on the receiving side: the nvke-controller
and nke-controller JWT audiences, the nke: and nvke: reserved identity
prefixes, and the auth.nvke/auth.nke auth-config apiVersions.

Rename the tenant RBAC objects to nvke:cwe and nvke:capi-cluster-admin, move
the server-side-apply field manager to nvke, and prune the old nke: objects
from each tenant cluster after the new manifest applies. A site that pins the
old tenantRbacName keeps what it applies.

Make the Teleport resource-group label a setting and move the managed-by,
token prefix and resource-group defaults to nvke for new sites; existing
sites pin the old values.

Leave the leader-election leases alone permanently and record them under
existing-sites identity in the name-check allowlist.

Part of #1496

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix: align the local controller config with the new Teleport defaults

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix: satisfy the controller linters in the legacy RBAC prune

golangci-lint flagged the new prune helper: legacyRBACObjects as a package
global, the repeated "nke:cwe" literal, and the Delete error checked inline
through IgnoreNotFound. Make the list a function, name the literal, and split
the Delete out of the if. Also fix a misspelling the US locale rejects.

Signed-off-by: Terry Howe <thowe@nvidia.com>

---------

Signed-off-by: Terry Howe <thowe@nvidia.com>
2026-10-13 10:08:43 -06:00
Aaron Patten 596f26ddd1 feat(chart): name the tenant RBAC subject spiffe.controllerSubject (#1383)
* feat(chart): name the tenant RBAC subject spiffe.controllerSubject

spiffe.controllerSubject is the chart's name for the subject the tenant RBAC
bindings grant. spiffe.cweSubject is still read; when both are set,
spiffe.controllerSubject wins. With spiffe.jwtExchangeEndpoint set, either key
satisfies the required-subject check.

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* docs(chart): note that spiffe.cweSubject still satisfies the exchange requirement

Signed-off-by: Aaron Patten <apatten@nvidia.com>

---------

Signed-off-by: Aaron Patten <apatten@nvidia.com>
2026-10-09 13:16:47 +00:00
Eric Staples 0d1d2a5541 fix(controller): give the kubeadm bootstrap controller SPIFFE tenant access (#1331)
Tenant kubeconfig Secrets use SPIRE exec auth, but the exec-auth overlay, ClusterSPIFFEID namespaces, and nke:capi-cluster-admin binding covered only the core, kubeadm control-plane, and CAPD controllers. The kubeadm bootstrap controller could not reach tenant clusters to create join tokens, so replacement workers never provisioned.

Signed-off-by: Eric Staples <estaples@nvidia.com>
2026-10-08 09:12:10 -06:00
Dan BudrisandClaude Opus 5.5 be7b060aa3 feat(temporal): label tenant cluster system namespaces for PSA audit (#738)
* feat(temporal): label tenant cluster system namespaces for PSA audit

## Description

Adds `pod-security.kubernetes.io/enforce=privileged` labels to the tenant system namespaces NKE provisions: `kube-system`, and the CNI's namespace (`tigera-operator` for Calico, `ovn-kubernetes` for OVN-Kubernetes). Calico's other namespace, `calico-system`, is left alone: the tigera operator creates it already labeled `enforce=privileged` and keeps it that way, so NKE has nothing to add there.

`privileged` is the level these namespaces need, not a compromise — kube-proxy (kube-system), the CNI's own components, and node-local-dns's hostPath mount all need host access that even `baseline` forbids. It also matches how [GKE](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/podsecurityadmission) and [EKS](https://aws.github.io/aws-eks-best-practices/security/docs/pods/) treat the same namespaces — both keep `kube-system` unrestricted regardless of what a customer configures.

Closes #739.

**What this actually fixes:** the underlying problem isn't "these namespaces should be restricted" — it's that PodSecurity is enabled but silently has no opinion anywhere, so it *looks* configured while doing nothing. An unlabeled namespace and one explicitly labeled `privileged` behave identically at runtime; the label is what turns "PSA appears present but nothing shows intent" into an explicit, auditable decision. Tenant-owned namespaces are never touched — that stays the tenant's responsibility.

**Where it lives:** folded into the existing `InstallKubeLocalDNS` activity rather than a separate one. It already runs once per cluster right after CNI bring-up and already holds a tenant client for that cluster; with only one level and no configurable mode, a dedicated activity/workflow-step/version-gate wasn't earning its keep.

Also grants the tenant `nke:cwe` ClusterRole scoped `get`/`patch` on exactly the namespaces this touches (`kube-system`, `tigera-operator`, `ovn-kubernetes`) — it had no `namespaces` permission at all, which would have 403'd every call. `hack/chart-rbac-assertions.py` asserts these grants render correctly.

## Testing

Automated:
```bash
make preflight
```
Unit tests cover labeling `kube-system` + the CNI namespace for Calico, OVN-Kubernetes, and an unrecognized plugin (no-op), plus idempotency. They also check that a missing `calico-system` neither fails the activity nor gets created, and that a missing `kube-system`, `tigera-operator` or `ovn-kubernetes` is still an error: each exists before this activity runs.

Manual, against a local Tilt + CAPD tenant cluster (Calico): confirmed `kube-proxy` genuinely fails `baseline` PSA (the reason `privileged` is correct here, not a guess).

Against a real OVN-Kubernetes cluster: manually dispatched the `NICo VMs E2E` workflow (real KVM tenant nodes) against this branch — [run 34896035329](https://github.com/dsx-ai-factory/nke/actions/runs/34896035329), `16 Passed | 0 Failed | 0 Pending | 222 Skipped`, including the entry that sets `cniPlugin: ovn-kubernetes` and validates Open vSwitch.

Also fixed a real bug found in CI: the gofail e2e crash-recovery test's fake tenant API server never advertised `Namespace` as a resource type, so the production activity's real Get/Patch calls failed with a REST-mapper error once it started touching `Namespace` objects. Added `namespaces` to the fixture's discovery document and seeded a `kube-system` object; verified locally with `make e2e-gofail`.

## Checklist
- [x] I am familiar with the [Contributing Guidelines](https://github.com/dsx-ai-factory/nke/blob/main/CONTRIBUTING.md).
- [x] New or existing tests cover these changes.
- [x] The documentation is up to date with these changes.


Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: dbudris <dbudris@nvidia.com>

* refactor(temporal): move PSA namespace labeling into its own activity

InstallKubeLocalDNS goes back to DNS only. LabelSystemNamespacesForPSA
labels kube-system and the CNI namespace enforce=privileged, with the
same behavior as before: kube-system and the CNI namespace must exist,
an unrecognized plugin is a no-op, and calico-system is not waited on.

ProvisionCluster and UpgradeControlPlaneAddons run it right after
InstallKubeLocalDNS, gated by workflow.GetVersion change ID
"psa-label-system-namespaces" so histories from before this change
replay without it. It gets a 1m start-to-close timeout and 10 attempts
(10s initial interval, 1m max), since it is a DB read plus a few
namespace Get/Patch calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: dbudris <dbudris@nvidia.com>

---------

Signed-off-by: dbudris <dbudris@nvidia.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 14:49:54 -04:00
srekhi93andClaude Sonnet 5 a81a1f2785 feat(chart): parameterize tenant RBAC object names (#837)
* feat(chart): parameterize tenant RBAC object names

Nine nke:cwe literals in nke-rbac.yaml (six metadata.name, three
roleRef.name) now derive from nkeOIDCAuth.tenantRbacName, defaulting to
"cwe" so a legacy render is byte-identical to today. A greenfield site
sets it to "controller", producing nke:controller ClusterRole/Role/
Binding objects in every tenant cluster instead of nke:nke-controller
(the nke: prefix already carries the namespace).

chart-rbac-assertions.py gains a --tenant-rbac-suffix flag so it
validates the rendered manifest against either name.

These objects are applied server-side into tenant clusters without
pruning, so the name has to be right before the first greenfield site
exists rather than migrated after.

Closes NKX-16644

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(chart): store full nke:cwe literal in tenantRbacName default

Match the convention every other renamed identifier in this chart
follows (appDb.dbName, temporal.cloudWorkflow.namespace/queue): the
value holds the complete literal, not a fragment concatenated with a
hardcoded prefix in the template. A greenfield site now sets
tenantRbacName: "nke:controller" directly instead of just "controller".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* docs(chart): stop hardcoding nke:cwe in value comments

The two spiffe.* comments describing the tenant RBAC subject/name
still referenced the literal "nke:cwe", which stopped being accurate
once nkeOIDCAuth.tenantRbacName made that name configurable.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-19 08:04:15 -04:00
Chao 705db3c214 test(controller): exercise DSX identity exchange in CAPD (#484)
* test(controller): exercise DSX identity exchange in CAPD

* fix(test): sync identity exchange E2E module

* docs(test): explain identity exchange server state

* docs(test): describe CAPD identity exchange environment
2026-09-03 18:11:46 -07:00
Chao bb9fb2639d fix(chart): authorize exchanged CAPI identity (#457)
Signed-off-by: Chao Chen <chaoch@nvidia.com>
2026-09-02 14:41:18 -04:00
Davanum Srinivas 55068cb639 fix(chart): make validation complete and fail closed (#305)
* fix(chart): make validation complete and fail closed

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* fix(chart): consume the complete package listing

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

---------

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
2026-08-26 09:15:42 -04:00