Skip to content

Commit 9cf0f87

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 c550029 commit 9cf0f87

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-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_uninmplemented 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_uninmplemented __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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@ let migrate_send' ~__context ~vm ~dest ~live:_ ~vdi_map ~vif_map ~vgpu_map
11671167
true
11681168
with _ -> false
11691169
in
1170+
( if (not is_intra_pool) && Db.VM.get_VTPMs ~__context ~self:vm <> [] then
1171+
let message = "Cross-pool VM migration with VTPMs attached" in
1172+
Helpers.maybe_raise_vtpm_uninmplemented __FUNCTION__ message
1173+
) ;
11701174
let is_same_host = is_intra_pool && remote.dest_host = localhost in
11711175
if copy && is_intra_pool then
11721176
raise

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_uninmplemented' -- **/*.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)