Files
nvke/controller/internal/spiffe/node_agent_test.go
Abhay Krishna bcea532293 refactor(capi): read node identity from Machines (#2088)
machine-spire-entry, nico-spiffe and launchlayer-spiffe live in the
capi package, whose controllers are meant to reconcile Kubernetes
state only, but each looked its node up in Postgres: to learn whether
the node uses TLS-JWT, which SPIRE attestation method it was pinned
to, and whether SPIFFE is on.

Publish that on the Machine instead. MachineAnnotations now writes
spire-attestation-method and spiffe-enabled beside agent-connection,
and the API refuses both from operator-supplied metadata. The three
controllers read these annotations and wait while one is missing; the
shared Machine predicate wakes them when one changes.

A new machine-annotations controller copies the three annotations
from the node record onto Machines created before they were written,
and only onto a Machine whose host-id names the node, so existing
clusters converge after an upgrade.

The SPIFFE ID format moves to spiffe.NodeAgentID, which
db.Node.GetSpiffeID now calls, and the LaunchLayer agent path is
exposed as launchlayer.DSXImdsAgentPath.

Signed-off-by: Abhay Krishna Arunachalam <abhaykrishna@nvidia.com>
2026-11-03 11:21:19 -08:00

36 lines
853 B
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package spiffe
import (
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
func TestUnit_NodeAgentID(t *testing.T) {
t.Parallel()
const nodeID = "45f59791-87df-4e85-9430-e565166ad020"
tests := map[string]struct {
tlsJWT bool
want string
}{
"legacy SPIFFE identity": {
want: "spiffe://example.org/host/" + nodeID,
},
"canonical DSX exchange identity": {
tlsJWT: true,
want: "spiffe://example.org/tenant/tenant-a/service/dsx/bm/" + nodeID,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
require.Equal(t, test.want, NodeAgentID("example.org", "tenant-a", "dsx", uuid.MustParse(nodeID), test.tlsJWT))
})
}
}