Skip to content

Commit a5690c2

Browse files
committed
fix(api): disallow lifecycle configuration for prebuilt workspaces
1 parent 155c7bb commit a5690c2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

coderd/workspaces.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,17 @@ func (api *API) putWorkspaceAutostart(rw http.ResponseWriter, r *http.Request) {
10721072
return
10731073
}
10741074

1075+
// Autostart configuration is not supported for prebuilt workspaces.
1076+
// Prebuild lifecycle is managed by the reconciliation loop, with scheduling behavior
1077+
// defined per preset at the template level, not per workspace.
1078+
if workspace.IsPrebuild() {
1079+
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
1080+
Message: "Autostart is not supported for prebuilt workspaces",
1081+
Detail: "Prebuilt workspace scheduling is configured per preset at the template level. Workspace-level overrides are not supported.",
1082+
})
1083+
return
1084+
}
1085+
10751086
dbSched, err := validWorkspaceSchedule(req.Schedule)
10761087
if err != nil {
10771088
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
@@ -1156,6 +1167,17 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
11561167
return
11571168
}
11581169

1170+
// TTL updates are not supported for prebuilt workspaces.
1171+
// Prebuild lifecycle is managed by the reconciliation loop, with TTL behavior
1172+
// defined per preset at the template level, not per workspace.
1173+
if workspace.IsPrebuild() {
1174+
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
1175+
Message: "TTL updates are not supported for prebuilt workspaces",
1176+
Detail: "Prebuilt workspace TTL is configured per preset at the template level. Workspace-level overrides are not supported.",
1177+
})
1178+
return
1179+
}
1180+
11591181
var dbTTL sql.NullInt64
11601182

11611183
err := api.Database.InTx(func(s database.Store) error {
@@ -1272,6 +1294,16 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
12721294
return
12731295
}
12741296

1297+
// Dormancy configuration is not supported for prebuilt workspaces.
1298+
// Prebuilds are managed by the reconciliation loop and are not subject to dormancy.
1299+
if oldWorkspace.IsPrebuild() {
1300+
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
1301+
Message: "Dormancy configuration is not supported for prebuilt workspaces",
1302+
Detail: "Prebuilt workspaces are not subject to dormancy. Dormancy behavior is only applicable to regular workspaces",
1303+
})
1304+
return
1305+
}
1306+
12751307
// If the workspace is already in the desired state do nothing!
12761308
if oldWorkspace.DormantAt.Valid == req.Dormant {
12771309
rw.WriteHeader(http.StatusNotModified)
@@ -1416,6 +1448,17 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) {
14161448
return
14171449
}
14181450

1451+
// Deadline extensions are not supported for prebuilt workspaces.
1452+
// Prebuilds are managed by the reconciliation loop and must always have
1453+
// Deadline and MaxDeadline unset.
1454+
if workspace.IsPrebuild() {
1455+
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
1456+
Message: "Deadline extension is not supported for prebuilt workspaces",
1457+
Detail: "Prebuilt workspaces do not support user deadline modifications. Deadline extension is only applicable to regular workspaces",
1458+
})
1459+
return
1460+
}
1461+
14191462
code := http.StatusOK
14201463
resp := codersdk.Response{}
14211464

0 commit comments

Comments
 (0)