From 5c28965515982ef9f3bee6ec3cc87b9d7b083ba6 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 4 Nov 2026 16:31:30 +0000 Subject: [PATCH] api/v2: leave out empty posture expiries, as SaaS does Drop test checks for otherKnownIPs, a field main never had. Updates #2272 --- hscontrol/api/v2/devices.go | 14 ++++++-------- hscontrol/apiv2_devices_test.go | 27 +++++---------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/hscontrol/api/v2/devices.go b/hscontrol/api/v2/devices.go index 286b7cfc4..4f9687e0c 100644 --- a/hscontrol/api/v2/devices.go +++ b/hscontrol/api/v2/devices.go @@ -97,11 +97,12 @@ type DeviceRoutes struct { Enabled []string `json:"enabledRoutes" nullable:"false"` } -// DevicePostureAttributes is the Tailscale-compatible posture attribute -// response. Headscale currently exposes only the server-derived public address. +// DevicePostureAttributes is the GET /device/{id}/attributes response. Of +// Tailscale's attributes, headscale sets only ip:publicAddress, and like +// Tailscale leaves expiries out when no attribute has one. type DevicePostureAttributes struct { - Attributes map[string]any `json:"attributes" nullable:"false"` - Expiries map[string]time.Time `json:"expiries" nullable:"false"` + Attributes map[string]any `json:"attributes" nullable:"false"` + Expiries map[string]time.Time `json:"expiries,omitempty"` } // Request bodies match the Tailscale SDK wire shapes and, like Tailscale's, @@ -630,10 +631,7 @@ func devicePostureAttributesFromView(view types.NodeView) DevicePostureAttribute attributes["ip:publicAddress"] = addr.Get().String() } - return DevicePostureAttributes{ - Attributes: attributes, - Expiries: make(map[string]time.Time), - } + return DevicePostureAttributes{Attributes: attributes} } func routesFromView(view types.NodeView) DeviceRoutes { diff --git a/hscontrol/apiv2_devices_test.go b/hscontrol/apiv2_devices_test.go index 1c811baac..56e635ac9 100644 --- a/hscontrol/apiv2_devices_test.go +++ b/hscontrol/apiv2_devices_test.go @@ -146,10 +146,6 @@ func TestAPIv2Device_Get(t *testing.T) { resp := e.api.Get("/api/v2/device/" + e.deviceID + "?fields=all") require.Equalf(t, http.StatusOK, resp.Code, "body: %s", resp.Body) - var raw map[string]json.RawMessage - require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &raw)) - assert.NotContains(t, raw, "otherKnown"+"IPs") - var dev apiv2.Device require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &dev)) assert.Equal(t, e.deviceID, dev.ID) @@ -215,11 +211,10 @@ func TestAPIv2Device_GetPostureAttributes(t *testing.T) { e := newDeviceTestEnv(t) t.Run("unknown address", func(t *testing.T) { - attrs := getDevicePostureAttributes(t, e.api, e.deviceID) - assert.NotNil(t, attrs.Attributes) - assert.Empty(t, attrs.Attributes) - assert.NotNil(t, attrs.Expiries) - assert.Empty(t, attrs.Expiries) + resp := e.api.Get("/api/v2/device/" + e.deviceID + "/attributes") + require.Equalf(t, http.StatusOK, resp.Code, "body: %s", resp.Body) + // SaaS leaves expiries out when no attribute has one. + assert.JSONEq(t, `{"attributes":{}}`, resp.Body.String()) }) for _, test := range []struct { @@ -237,7 +232,6 @@ func TestAPIv2Device_GetPostureAttributes(t *testing.T) { attrs := getDevicePostureAttributes(t, e.api, e.deviceID) assert.Equal(t, test.addr, attrs.Attributes["ip:publicAddress"]) - assert.NotNil(t, attrs.Expiries) assert.Empty(t, attrs.Expiries) }) } @@ -266,21 +260,10 @@ func TestAPIv2Device_List(t *testing.T) { } require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &out)) - var raw struct { - Devices []map[string]json.RawMessage `json:"devices"` - } - require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &raw)) - - for _, device := range raw.Devices { - assert.NotContains(t, device, "otherKnown"+"IPs") - } - return out.Devices } - devices := list() - require.Len(t, devices, 1) - assert.True(t, containsDeviceID(devices, e.deviceID)) + assert.True(t, containsDeviceID(list(), e.deviceID)) assert.Len(t, list(), e.app.state.ListNodes().Len(), "list count == ListNodes") // A second node appears; deleting it removes it from both the list and state.