Skip to content

Commit

Permalink
lxd: Use auth method instead of devlxdRemoteAddress
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Sep 10, 2024
1 parent 4009564 commit 9b6d519
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request) (trusted b
}

// Devlxd unix socket credentials on main API.
if r.RemoteAddr == devlxdRemoteAddress {
authMethod, _ := auth.GetAuthenticationMethodFromCtx(r.Context())
if authMethod == api.AuthenticationMethodDevLxd {
return false, "", "", nil, fmt.Errorf("Main API query can't come from /dev/lxd socket")
}

Expand Down
5 changes: 4 additions & 1 deletion lxd/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -4107,7 +4107,10 @@ func imageExport(d *Daemon, r *http.Request) response.Response {
return response.SmartError(err)
}

isDevLXDQuery := r.RemoteAddr == devlxdRemoteAddress
// Verify the auth method in the request context to determine if the request comes from the /dev/lxd socket.
authMethod, _ := auth.GetAuthenticationMethodFromCtx(r.Context())
isDevLXDQuery := authMethod == api.AuthenticationMethodDevLxd

secret := r.FormValue("secret")
trusted := auth.IsTrusted(r.Context())

Expand Down

0 comments on commit 9b6d519

Please sign in to comment.