+53
-0
lines changedFilter options
+53
-0
lines changed Original file line number Diff line number Diff line change
@@ -1080,6 +1080,18 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
1080
1080
if manifest.AgentID == uuid.Nil {
1081
1081
return xerrors.New("nil agentID returned by manifest")
1082
1082
}
1083
+
if manifest.ParentID != uuid.Nil {
1084
+
// This is a sub agent, disable all the features that should not
1085
+
// be used by sub agents.
1086
+
a.logger.Debug(ctx, "sub agent detected, disabling features",
1087
+
slog.F("parent_id", manifest.ParentID),
1088
+
slog.F("agent_id", manifest.AgentID),
1089
+
)
1090
+
if a.experimentalDevcontainersEnabled {
1091
+
a.logger.Info(ctx, "devcontainers are not supported on sub agents, disabling feature")
1092
+
a.experimentalDevcontainersEnabled = false
1093
+
}
1094
+
}
1083
1095
a.client.RewriteDERPMap(manifest.DERPMap)
1084
1096
1085
1097
// Expand the directory and send it back to coderd so external
Original file line number Diff line number Diff line change
@@ -2423,6 +2423,34 @@ waitForOutcomeLoop:
2423
2423
}(container)
2424
2424
}
2425
2425
2426
+
func TestAgent_DevcontainersDisabledForSubAgent(t *testing.T) {
2427
+
t.Parallel()
2428
+
2429
+
// Create a manifest with a ParentID to make this a sub agent.
2430
+
manifest := agentsdk.Manifest{
2431
+
AgentID: uuid.New(),
2432
+
ParentID: uuid.New(),
2433
+
}
2434
+
2435
+
// Setup the agent with devcontainers enabled initially.
2436
+
//nolint:dogsled
2437
+
conn, _, _, _, _ := setupAgent(t, manifest, 0, func(_ *agenttest.Client, o *agent.Options) {
2438
+
o.ExperimentalDevcontainersEnabled = true
2439
+
})
2440
+
2441
+
// Query the containers API endpoint. This should fail because
2442
+
// devcontainers have been disabled for the sub agent.
2443
+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
2444
+
defer cancel()
2445
+
2446
+
_, err := conn.ListContainers(ctx)
2447
+
require.Error(t, err)
2448
+
2449
+
// Verify the error message contains the expected text.
2450
+
require.Contains(t, err.Error(), "The agent dev containers feature is experimental and not enabled by default.")
2451
+
require.Contains(t, err.Error(), "To enable this feature, set CODER_AGENT_DEVCONTAINERS_ENABLE=true in your template.")
2452
+
}
2453
+
2426
2454
func TestAgent_Dial(t *testing.T) {
2427
2455
t.Parallel()
2428
2456
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ type PostMetadataRequest struct {
102
102
type PostMetadataRequestDeprecated = codersdk.WorkspaceAgentMetadataResult
103
103
104
104
type Manifest struct {
105
+
ParentID uuid.UUID `json:"parent_id"`
105
106
AgentID uuid.UUID `json:"agent_id"`
106
107
AgentName string `json:"agent_name"`
107
108
// OwnerUsername and WorkspaceID are used by an open-source user to identify the workspace.
Original file line number Diff line number Diff line change
@@ -15,6 +15,14 @@ import (
15
15
)
16
16
17
17
func ManifestFromProto(manifest *proto.Manifest) (Manifest, error) {
18
+
parentID := uuid.Nil
19
+
if pid := manifest.GetParentId(); pid != nil {
20
+
var err error
21
+
parentID, err = uuid.FromBytes(pid)
22
+
if err != nil {
23
+
return Manifest{}, xerrors.Errorf("error converting workspace agent parent ID: %w", err)
24
+
}
25
+
}
18
26
apps, err := AppsFromProto(manifest.Apps)
19
27
if err != nil {
20
28
return Manifest{}, xerrors.Errorf("error converting workspace agent apps: %w", err)
@@ -36,6 +44,7 @@ func ManifestFromProto(manifest *proto.Manifest) (Manifest, error) {
36
44
return Manifest{}, xerrors.Errorf("error converting workspace agent devcontainers: %w", err)
37
45
}
38
46
return Manifest{
47
+
ParentID: parentID,
39
48
AgentID: agentID,
40
49
AgentName: manifest.AgentName,
41
50
OwnerName: manifest.OwnerUsername,
@@ -62,6 +71,7 @@ func ProtoFromManifest(manifest Manifest) (*proto.Manifest, error) {
62
71
return nil, xerrors.Errorf("convert workspace apps: %w", err)
63
72
}
64
73
return &proto.Manifest{
74
+
ParentId: manifest.ParentID[:],
65
75
AgentId: manifest.AgentID[:],
66
76
AgentName: manifest.AgentName,
67
77
OwnerUsername: manifest.OwnerName,
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
19
19
func TestManifest(t *testing.T) {
20
20
t.Parallel()
21
21
manifest := agentsdk.Manifest{
22
+
ParentID: uuid.New(),
22
23
AgentID: uuid.New(),
23
24
AgentName: "test-agent",
24
25
OwnerName: "test-owner",
@@ -142,6 +143,7 @@ func TestManifest(t *testing.T) {
142
143
require.NoError(t, err)
143
144
back, err := agentsdk.ManifestFromProto(p)
144
145
require.NoError(t, err)
146
+
require.Equal(t, manifest.ParentID, back.ParentID)
145
147
require.Equal(t, manifest.AgentID, back.AgentID)
146
148
require.Equal(t, manifest.AgentName, back.AgentName)
147
149
require.Equal(t, manifest.OwnerName, back.OwnerName)
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4