Skip to content

Commit

Permalink
lxd/instances: Check instance creation limits on target cluster member
Browse files Browse the repository at this point in the history
If a malicious request sets `User-Agent: lxd-cluster-notifier`, project
limits would not be checked.

I don't see a way to reuse the transaction without including the instance
placement scriptlet.

Signed-off-by: Wesley Hershberger <[email protected]>
  • Loading branch information
MggMuggins committed Aug 30, 2024
1 parent 2677eb6 commit aeeee30
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lxd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,6 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {
}
}

if !clusterNotification {
// Check that the project's limits are not violated. Note this check is performed after
// automatically generated config values (such as ones from an InstanceType) have been set.
err = project.AllowInstanceCreation(s.GlobalConfig, tx, targetProjectName, req)
if err != nil {
return err
}
}

return nil
})
if err != nil {
Expand Down Expand Up @@ -1320,6 +1311,15 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {
return operations.ForwardedOperationResponse(targetProjectName, &opAPI)
}

// Check that the project's limits are not violated. Note this check is performed after
// automatically generated config values (such as ones from an InstanceType) have been set.
err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error {
return project.AllowInstanceCreation(s.GlobalConfig, tx, targetProjectName, req)
})
if err != nil {
return response.SmartError(err)
}

switch req.Source.Type {
case "image":
return createFromImage(s, r, *targetProject, profiles, sourceImage, sourceImageRef, &req)
Expand Down

0 comments on commit aeeee30

Please sign in to comment.