Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak to cluster internal relocation #1378

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/incusd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ func isClusterNotification(r *http.Request) bool {
return r.Header.Get("User-Agent") == clusterRequest.UserAgentNotifier
}

func isClusterInternal(r *http.Request) bool {
return r.Header.Get("User-Agent") == clusterRequest.UserAgentClient
}

type uiHttpDir struct {
http.FileSystem
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request) (bool, str
return false, "", "", fmt.Errorf("Cluster notification isn't using trusted server certificate")
}

// Cluster internal client with wrong certificate.
if isClusterInternal(r) {
return false, "", "", fmt.Errorf("Cluster internal client isn't using trusted server certificate")
}

// Bad query, no TLS found.
if r.TLS == nil {
return false, "", "", fmt.Errorf("Bad/missing TLS on network query")
Expand Down
10 changes: 8 additions & 2 deletions cmd/incusd/instance_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
internalInstance "github.com/lxc/incus/v6/internal/instance"
"github.com/lxc/incus/v6/internal/server/auth"
"github.com/lxc/incus/v6/internal/server/cluster"
clusterRequest "github.com/lxc/incus/v6/internal/server/cluster/request"
"github.com/lxc/incus/v6/internal/server/db"
dbCluster "github.com/lxc/incus/v6/internal/server/db/cluster"
"github.com/lxc/incus/v6/internal/server/db/operationtype"
Expand Down Expand Up @@ -336,7 +337,7 @@ func instancePost(d *Daemon, r *http.Request) response.Response {
Devices: inst.ExpandedDevices().CloneNative(),
},
},
Project: projectName,
Project: instProject,
Reason: apiScriptlet.InstancePlacementReasonRelocation,
}

Expand Down Expand Up @@ -595,7 +596,12 @@ func migrateInstance(ctx context.Context, s *state.State, inst instance.Instance
// Handle pool and project moves.
if req.Project != "" || req.Pool != "" {
// Get a local client.
target, err := incus.ConnectIncusUnix(s.OS.GetUnixSocket(), nil)
args := &incus.ConnectionArgs{
SkipGetServer: true,
UserAgent: clusterRequest.UserAgentClient,
}

target, err := incus.ConnectIncusUnix(s.OS.GetUnixSocket(), args)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/incusd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {

targetProjectName := request.ProjectParam(r)
clusterNotification := isClusterNotification(r)
clusterInternal := isClusterInternal(r)

logger.Debug("Responding to instance create")

Expand Down Expand Up @@ -1102,7 +1103,7 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {
return response.BadRequest(err)
}

if s.ServerClustered && !clusterNotification {
if s.ServerClustered && !clusterNotification && !clusterInternal {
// If a target was specified, limit the list of candidates to that target.
if targetMemberInfo != nil {
candidateMembers = []db.NodeInfo{*targetMemberInfo}
Expand Down Expand Up @@ -1142,7 +1143,7 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {
}

// Record the cluster group as a volatile config key if present.
if !clusterNotification && targetGroupName != "" {
if !clusterNotification && !clusterInternal && targetGroupName != "" {
req.Config["volatile.cluster.group"] = targetGroupName
}

Expand Down
9 changes: 9 additions & 0 deletions internal/server/cluster/request/clienttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ package request
// notifying other nodes of a cluster change.
const UserAgentNotifier = "incus-cluster-notifier"

// UserAgentClient used to distinguish between a regular client request and an internal cluster request when
// performing a regular API interaction as an internal client.
const UserAgentClient = "incus-cluster-client"

// UserAgentJoiner used to distinguish between a regular client request and an internal cluster request when
// joining a node to a cluster.
const UserAgentJoiner = "incus-cluster-joiner"
Expand All @@ -20,13 +24,18 @@ const ClientTypeJoiner ClientType = "joiner"
// ClientTypeNormal normal client.
const ClientTypeNormal ClientType = "normal"

// ClientTypeInternal cluster internal client.
const ClientTypeInternal ClientType = "internal"

// UserAgentClientType converts user agent to client type.
func UserAgentClientType(userAgent string) ClientType {
switch userAgent {
case UserAgentNotifier:
return ClientTypeNotifier
case UserAgentJoiner:
return ClientTypeJoiner
case UserAgentClient:
return ClientTypeInternal
}

return ClientTypeNormal
Expand Down
5 changes: 4 additions & 1 deletion internal/server/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9329,7 +9329,10 @@ func (d *qemu) ConsoleLog() (string, error) {
return "", err
}

defer op.Done(nil)
// Only mark the operation as done if only processing the console retrieval.
if op.Action() == operationlock.ActionConsoleRetrieve {
defer op.Done(nil)
}

// Check if the agent is running.
monitor, err := qmp.Connect(d.monitorPath(), qemuSerialChardevName, d.getMonitorEventHandler(), d.QMPLogFilePath())
Expand Down
Loading