feat: return hostname suffix on AgentConnectionInfo (#17334)

Adds the Hostname Suffix to `AgentConnectionInfo` --- the VPN provider will use it to control the suffix for DNS hostnames.

part of: #16828
This commit is contained in:
Spike Curtis
2025-04-11 13:09:51 +04:00
committed by GitHub
parent 60fbe675ed
commit 12dc086628
7 changed files with 45 additions and 2 deletions
+3
View File
@@ -18615,6 +18615,9 @@ const docTemplate = `{
},
"disable_direct_connections": {
"type": "boolean"
},
"hostname_suffix": {
"type": "string"
}
}
},
+3
View File
@@ -17050,6 +17050,9 @@
},
"disable_direct_connections": {
"type": "boolean"
},
"hostname_suffix": {
"type": "string"
}
}
},
+2
View File
@@ -882,6 +882,7 @@ func (api *API) workspaceAgentConnection(rw http.ResponseWriter, r *http.Request
DERPMap: api.DERPMap(),
DERPForceWebSockets: api.DeploymentValues.DERP.Config.ForceWebSockets.Value(),
DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
HostnameSuffix: api.DeploymentValues.WorkspaceHostnameSuffix.Value(),
})
}
@@ -903,6 +904,7 @@ func (api *API) workspaceAgentConnectionGeneric(rw http.ResponseWriter, r *http.
DERPMap: api.DERPMap(),
DERPForceWebSockets: api.DeploymentValues.DERP.Config.ForceWebSockets.Value(),
DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
HostnameSuffix: api.DeploymentValues.WorkspaceHostnameSuffix.Value(),
})
}
+31
View File
@@ -2560,3 +2560,34 @@ func requireEqualOrBothNil[T any](t testing.TB, a, b *T) {
}
require.Equal(t, a, b)
}
func TestAgentConnectionInfo(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
dv := coderdtest.DeploymentValues(t)
dv.WorkspaceHostnameSuffix = "yallah"
dv.DERP.Config.BlockDirect = true
dv.DERP.Config.ForceWebSockets = true
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{DeploymentValues: dv})
user := coderdtest.CreateFirstUser(t, client)
r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
OrganizationID: user.OrganizationID,
OwnerID: user.UserID,
}).WithAgent().Do()
info, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx)
require.NoError(t, err)
require.Equal(t, "yallah", info.HostnameSuffix)
require.True(t, info.DisableDirectConnections)
require.True(t, info.DERPForceWebSockets)
ws, err := client.Workspace(ctx, r.Workspace.ID)
require.NoError(t, err)
agnt := ws.LatestBuild.Resources[0].Agents[0]
info, err = workspacesdk.New(client).AgentConnectionInfo(ctx, agnt.ID)
require.NoError(t, err)
require.Equal(t, "yallah", info.HostnameSuffix)
require.True(t, info.DisableDirectConnections)
require.True(t, info.DERPForceWebSockets)
}
+1
View File
@@ -143,6 +143,7 @@ type AgentConnectionInfo struct {
DERPMap *tailcfg.DERPMap `json:"derp_map"`
DERPForceWebSockets bool `json:"derp_force_websockets"`
DisableDirectConnections bool `json:"disable_direct_connections"`
HostnameSuffix string `json:"hostname_suffix"`
}
func (c *Client) AgentConnectionInfoGeneric(ctx context.Context) (AgentConnectionInfo, error) {
+2 -1
View File
@@ -698,7 +698,8 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent}/con
}
}
},
"disable_direct_connections": true
"disable_direct_connections": true,
"hostname_suffix": "string"
}
```
+3 -1
View File
@@ -11514,7 +11514,8 @@ None
}
}
},
"disable_direct_connections": true
"disable_direct_connections": true,
"hostname_suffix": "string"
}
```
@@ -11525,6 +11526,7 @@ None
| `derp_force_websockets` | boolean | false | | |
| `derp_map` | [tailcfg.DERPMap](#tailcfgderpmap) | false | | |
| `disable_direct_connections` | boolean | false | | |
| `hostname_suffix` | string | false | | |
## wsproxysdk.CryptoKeysResponse