Skip to content

Commit 089ca98

Browse files
authored
Merge pull request #787 from psafont/public-fix
2 parents 291d3fe + fb388e3 commit 089ca98

File tree

11 files changed

+96
-32
lines changed

11 files changed

+96
-32
lines changed

.github/workflows/0.150-lcm.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
# invalidate cache daily, gets built daily using a scheduled job
4949
key: ${{ steps.cache-key.outputs.date }}-0.150
5050

51+
- name: Update Ubuntu repositories
52+
run: sudo apt-get update
53+
5154
- name: Use ocaml
5255
uses: avsm/setup-ocaml@v1
5356
with:

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ install:
4444
install -D ./scripts/common.py $(DESTDIR)/$(LIBEXECDIR)/common.py
4545
install -D ./scripts/igmp_query_injector.py $(DESTDIR)/$(LIBEXECDIR)/igmp_query_injector.py
4646
install -D ./scripts/qemu-wrapper $(DESTDIR)/$(QEMU_WRAPPER_DIR)/qemu-wrapper
47+
install -D ./scripts/pygrub-wrapper $(DESTDIR)/$(QEMU_WRAPPER_DIR)/pygrub-wrapper
4748
DESTDIR=$(DESTDIR) SBINDIR=$(SBINDIR) QEMU_WRAPPER_DIR=$(QEMU_WRAPPER_DIR) LIBEXECDIR=$(LIBEXECDIR) ETCDIR=$(ETCDIR) ./scripts/make-custom-xenopsd.conf
4849

4950
uninstall:
@@ -70,5 +71,6 @@ uninstall:
7071
rm -f $(DESTDIR)/$(LIBEXECDIR)/common.py*
7172
rm -f $(DESTDIR)/$(LIBEXECDIR)/igmp_query_injector.py*
7273
rm -f $(DESTDIR)/$(QEMU_WRAPPER_DIR)/qemu-wrapper
74+
rm -f $(DESTDIR)/$(QEMU_WRAPPER_DIR)/pygrub-wrapper
7375

7476
.DEFAULT_GOAL := release

lib/bootloader.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ exception Error_from_bootloader of string
5959
type t = {kernel_path: string; initrd_path: string option; kernel_args: string}
6060

6161
(** Helper function to generate a bootloader commandline *)
62-
let command bootloader q pv_bootloader_args image vm_uuid =
62+
let command bootloader q pv_bootloader_args image vm_uuid domid =
6363
(* Let's not do anything fancy while parsing the pv_bootloader_args string: no
6464
escaping of spaces or quotes for now *)
6565
let pv_bootloader_args =
@@ -77,6 +77,7 @@ let command bootloader q pv_bootloader_args image vm_uuid =
7777
[
7878
["--output-format=simple"]
7979
; q
80+
; [Printf.sprintf "--domid=%d" domid]
8081
; (* --vm is unnecessary for pygrub and not supported upstream *)
8182
pv_bootloader_args
8283
; image
@@ -221,11 +222,11 @@ let sanity_check_path p =
221222
(** Extract the default kernel using the -q option *)
222223
let extract (task : Xenops_task.task_handle) ~bootloader ~disk
223224
?(legacy_args = "") ?(extra_args = "") ?(pv_bootloader_args = "")
224-
~vm:vm_uuid () =
225+
~vm:vm_uuid ~domid () =
225226
(* Without this path, pygrub will fail: *)
226227
Unixext.mkdir_rec "/var/run/xend/boot" 0o0755 ;
227228
let bootloader_path, cmdline =
228-
command bootloader true pv_bootloader_args disk vm_uuid
229+
command bootloader true pv_bootloader_args disk vm_uuid domid
229230
in
230231
debug "Bootloader commandline: %s %s\n" bootloader_path
231232
(String.concat " " cmdline) ;

lib/bootloader.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ val extract :
3838
-> ?extra_args:string
3939
-> ?pv_bootloader_args:string
4040
-> vm:string
41+
-> domid:int
4142
-> unit
4243
-> t
4344
(** Extract the default kernel from the disk *)

lib/open_uri_https.ml

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
(* This code is usually in xcp-idl but we introduced a local copy here
32
to support https, which has a dependency on stunnel and would create
43
a circular dependency. *)
@@ -21,22 +20,22 @@ let with_open_uri uri f =
2120
)
2221
)
2322
| Some "https" -> (
24-
let process (s : Stunnel.t) =
25-
finally
26-
(fun () -> f Safe_resources.Unixfd.(!(s.Stunnel.fd)))
27-
(fun () -> Stunnel.disconnect s)
28-
in
29-
match (Uri.host uri, Uri.port uri) with
30-
| Some host, Some port ->
31-
Stunnel.with_connect host port process
32-
| Some host, None ->
33-
Stunnel.with_connect host https_port process
34-
| _, _ ->
35-
failwith
36-
(Printf.sprintf "Failed to parse host and port from URI: %s"
37-
(Uri.to_string uri)
38-
)
39-
)
23+
let process (s : Stunnel.t) =
24+
finally
25+
(fun () -> f Safe_resources.Unixfd.(!(s.Stunnel.fd)))
26+
(fun () -> Stunnel.disconnect s)
27+
in
28+
match (Uri.host uri, Uri.port uri) with
29+
| Some host, Some port ->
30+
Stunnel.with_connect host port process
31+
| Some host, None ->
32+
Stunnel.with_connect host https_port process
33+
| _, _ ->
34+
failwith
35+
(Printf.sprintf "Failed to parse host and port from URI: %s"
36+
(Uri.to_string uri)
37+
)
38+
)
4039
| Some "file" ->
4140
let filename = Uri.path_and_query uri in
4241
let sockaddr = Unix.ADDR_UNIX filename in
@@ -48,5 +47,3 @@ let with_open_uri uri f =
4847
failwith (Printf.sprintf "Unsupported URI scheme: %s" x)
4948
| None ->
5049
failwith (Printf.sprintf "Failed to parse URI: %s" (Uri.to_string uri))
51-
52-

lib/resources.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let rmmod = ref "/usr/sbin/rmmod"
2828

2929
let hvmloader = ref "hvmloader"
3030

31-
let pygrub = ref "pygrub"
31+
let pygrub = ref "pygrub-wrapper"
3232

3333
let eliloader = ref "eliloader"
3434

lib/xcp_client_https.ml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ let switch_rpc ?timeout queue_name string_of_call response_of_string =
4242
response_of_string
4343
(get_ok
4444
(Message_switch_unix.Protocol_unix.Client.rpc ~t ?timeout
45-
~queue:queue_name ~body:(string_of_call call) ()))
45+
~queue:queue_name ~body:(string_of_call call) ()
46+
)
47+
)
4648

4749
let split_colon str =
4850
try
@@ -94,7 +96,8 @@ let http_rpc string_of_call response_of_string ?(srcstr = "unset")
9496
| `Invalid x ->
9597
failwith
9698
(Printf.sprintf "Failed to read HTTP response from: %s (got '%s')"
97-
(url ()) x)
99+
(url ()) x
100+
)
98101
| `Ok response -> (
99102
let body = Buffer.create 16 in
100103
let reader = Response.make_body_reader response ic in
@@ -115,8 +118,10 @@ let http_rpc string_of_call response_of_string ?(srcstr = "unset")
115118
| bad ->
116119
failwith
117120
(Printf.sprintf "Unexpected HTTP response code: %s"
118-
(Cohttp.Code.string_of_status bad))
119-
))
121+
(Cohttp.Code.string_of_status bad)
122+
)
123+
)
124+
)
120125

121126
let xml_http_rpc = http_rpc Xmlrpc.string_of_call Xmlrpc.response_of_string
122127

@@ -129,9 +134,11 @@ let () =
129134
| Xmlm.Error ((line, col), error) ->
130135
Some
131136
(Printf.sprintf "Xmlm.Error(%d:%d, \"%s\")" line col
132-
(Xmlm.error_message error))
137+
(Xmlm.error_message error)
138+
)
133139
| _ ->
134-
None)
140+
None
141+
)
135142

136143
(* Use a binary 16-byte length to frame RPC messages *)
137144
let binary_rpc string_of_call response_of_string ?(srcstr = "unset")
@@ -153,7 +160,8 @@ let binary_rpc string_of_call response_of_string ?(srcstr = "unset")
153160
let (response : Rpc.response) =
154161
response_of_string (Bytes.unsafe_to_string msg_buf)
155162
in
156-
response)
163+
response
164+
)
157165

158166
let json_binary_rpc =
159167
binary_rpc Jsonrpc.string_of_call Jsonrpc.response_of_string

scripts/make-custom-xenopsd.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ qemu-dm-wrapper=${LIBEXECDIR}/qemu-dm-wrapper
4646
setup-vif-rules=${LIBEXECDIR}/setup-vif-rules
4747
sockets-group=$group
4848
qemu-wrapper=${QEMU_WRAPPER_DIR}/qemu-wrapper
49+
pygrub-wrapper=${QEMU_WRAPPER_DIR}/pygrub-wrapper
4950
5051
disable-logging-for=http
5152
# Workaround xenopsd bug #45

scripts/pygrub-wrapper

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#! /usr/bin/python
2+
#
3+
# Copyright (C) 2023 Cloud Software Group
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU Lesser General Public License as published
7+
# by the Free Software Foundation; version 2.1 only. with the special
8+
# exception on linking described in file LICENSE.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Lesser General Public License for more details.
14+
15+
from __future__ import print_function
16+
import pwd, subprocess, sys
17+
import grp, os, stat
18+
19+
cmd = ["pygrub"]
20+
21+
# Get the usage string. We can't use check_output() because the exit status isn't 0
22+
pygrub_usage = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1]
23+
24+
with_depriv = False
25+
for arg in sys.argv[1:]:
26+
# Catch the synthetic --domid argument and turn it into --runas
27+
argname_domid = "--domid="
28+
if arg.startswith(argname_domid):
29+
if "[--runas=]" not in pygrub_usage:
30+
# Skip depriv if pygrub doesn't support it
31+
continue
32+
with_depriv = True
33+
domid = int(arg[len(argname_domid):])
34+
uid = pwd.getpwnam('qemu_base').pw_uid + domid
35+
cmd += ["--runas=" + str(uid)]
36+
37+
# Set group permissions on the disk so a depriv pygrub can read it
38+
disk = sys.argv[-1]
39+
gid = grp.getgrnam('disk').gr_gid
40+
disk_stat = os.stat(disk)
41+
os.chown(disk, uid, gid)
42+
os.chmod(disk, disk_stat.st_mode | stat.S_IRGRP)
43+
else:
44+
cmd += [arg]
45+
46+
if 'PYGRUB_FORCE_DEPRIV' in os.environ.keys() and not with_depriv:
47+
raise RuntimeError("Trying to run pygrub as root: %s" % pygrub_usage)
48+
49+
sys.exit(subprocess.call(cmd))

xapi-xenopsd.opam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ depends: [
2424
"rpclib"
2525
"sexplib"
2626
"stdext"
27+
"stunnel"
2728
"base-threads"
2829
"uri"
2930
"uuidm"
3031
"uutf"
3132
"xapi-idl"
33+
"xapi-test-utils" {with-test}
3234
"xenctrl"
3335
"xmlm"
3436
"fmt" { >= "0.8.8" }

0 commit comments

Comments
 (0)