Skip to content

Commit 2e3b83b

Browse files
committed
CA-370858: disallow VM exports with VTPMs attached
We're unable to serialize the data because the field for the contents is not exposed in the API and it's based on a secret, which can be dangerous once it's been implemented. Exports are exposed using an HTTP endpoint, this means it's an indirect operation and that other operations that use the feature will fail in extraneous ways in a non-instantaneous way. To avoid this the two methods that use it in xapi are changed as well (vm-export and VM cross-pool migrations). This makes the failure immediate and clear. Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
1 parent 9c43b22 commit 2e3b83b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,6 +5794,13 @@ let export_common fd _printer rpc session_id params filename num ?task_uuid
57945794
in
57955795
let vm_metadata_only = get_bool_param params "metadata" in
57965796
let vm_record = vm.record () in
5797+
(* disallow exports and cross-pool migrations of VMs with VTPMs *)
5798+
( if vm_record.API.vM_VTPMs <> [] then
5799+
let message = "Exporting VM metadata with VTPMs attached" in
5800+
(* Helpers.maybe_raise_vtpm_unimplemented cannot be used due to the
5801+
xapi_globs dependence *)
5802+
raise Api_errors.(Server_error (not_implemented, [message]))
5803+
) ;
57975804
let exporttask, task_destroy_fn =
57985805
match task_uuid with
57995806
| None ->

ocaml/xapi/export.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ let make_host table __context self =
210210
let make_vm ?(with_snapshot_metadata = false) ~preserve_power_state table
211211
__context self =
212212
let vm = Db.VM.get_record ~__context ~self in
213+
let vM_VTPMs = filter table (List.map Ref.string_of vm.API.vM_VTPMs) in
214+
(* disallow exports and cross-pool migrations of VMs with VTPMs *)
215+
( if vM_VTPMs <> [] then
216+
let message = "Exporting VM metadata with VTPMs attached" in
217+
Helpers.maybe_raise_vtpm_unimplemented __FUNCTION__ message
218+
) ;
213219
let vm =
214220
{
215221
vm with
@@ -251,7 +257,7 @@ let make_vm ?(with_snapshot_metadata = false) ~preserve_power_state table
251257
; API.vM_VBDs= filter table (List.map Ref.string_of vm.API.vM_VBDs)
252258
; API.vM_VGPUs= filter table (List.map Ref.string_of vm.API.vM_VGPUs)
253259
; API.vM_crash_dumps= []
254-
; API.vM_VTPMs= []
260+
; API.vM_VTPMs
255261
; API.vM_resident_on= lookup table (Ref.string_of vm.API.vM_resident_on)
256262
; API.vM_affinity= lookup table (Ref.string_of vm.API.vM_affinity)
257263
; API.vM_consoles= []

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,11 @@ let assert_can_migrate ~__context ~vm ~dest ~live:_ ~vdi_map ~vif_map ~options
17191719
, [Ref.string_of vm; Ref.string_of remote.dest_host]
17201720
)
17211721
) ;
1722+
(* VTPMs can't be exported currently, which will make the migration fail *)
1723+
( if Db.VM.get_VTPMs ~__context ~self:vm <> [] then
1724+
let message = "Cross-pool VM migration with VTPMs attached" in
1725+
Helpers.maybe_raise_vtpm_unimplemented __FUNCTION__ message
1726+
) ;
17221727
(* Check VDIs are not migrating to or from an SR which doesn't have required_sr_operations *)
17231728
assert_sr_support_operations ~__context ~vdi_map ~remote
17241729
~ops:required_sr_operations ;

quality-gate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ structural-equality () {
5858
}
5959

6060
vtpm-unimplemented () {
61-
N=5
61+
N=8
6262
VTPM=$(git grep -r --count 'maybe_raise_vtpm_unimplemented' -- **/*.ml | cut -d ':' -f 2 | paste -sd+ - | bc)
6363
if [ "$VTPM" -eq "$N" ]; then
6464
echo "OK found $VTPM usages of vtpm unimplemented errors"

0 commit comments

Comments
 (0)