Skip to content

Commit 75db25c

Browse files
authored
xapi: Add secure boot field to host datamodel (#6687)
The secure boot status can be read from the fifth byte of file /sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c This adds a secure_boot field to the host datamodel, which is set during dbsync to the value held in the above file.
2 parents b2f572d + 06e8b6b commit 75db25c

File tree

12 files changed

+54
-9
lines changed

12 files changed

+54
-9
lines changed

ocaml/idl/datamodel_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open Datamodel_roles
1010
to leave a gap for potential hotfixes needing to increment the schema version.*)
1111
let schema_major_vsn = 5
1212

13-
let schema_minor_vsn = 790
13+
let schema_minor_vsn = 791
1414

1515
(* Historical schema versions just in case this is useful later *)
1616
let rio_schema_major_vsn = 5

ocaml/idl/datamodel_host.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,13 @@ let create_params =
13671367
; param_release= numbered_release "25.27.0"
13681368
; param_default= Some (VBool Constants.default_ssh_auto_mode)
13691369
}
1370+
; {
1371+
param_type= Bool
1372+
; param_name= "secure_boot"
1373+
; param_doc= "True if the host is in secure boot mode"
1374+
; param_release= numbered_release "25.32.0"
1375+
; param_default= Some (VBool false)
1376+
}
13701377
]
13711378

13721379
let create =
@@ -3108,6 +3115,9 @@ let t =
31083115
~default_value:(Some (VBool Constants.default_ssh_auto_mode))
31093116
"ssh_auto_mode"
31103117
"Reflects whether SSH auto mode is enabled for the host"
3118+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
3119+
~default_value:(Some (VBool false)) "secure_boot"
3120+
"Whether the host has booted in secure boot mode"
31113121
]
31123122
)
31133123
()

ocaml/idl/datamodel_lifecycle.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ let prototyped_of_field = function
9797
Some "22.26.0"
9898
| "SM", "host_pending_features" ->
9999
Some "24.37.0"
100+
| "host", "secure_boot" ->
101+
Some "25.31.0"
100102
| "host", "ssh_auto_mode" ->
101103
Some "25.27.0"
102104
| "host", "console_idle_timeout" ->

ocaml/idl/schematest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
33
(* BEWARE: if this changes, check that schema has been bumped accordingly in
44
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)
55

6-
let last_known_schema_hash = "7586cb039918e573594fc358e90b0f04"
6+
let last_known_schema_hash = "3b20f4304cfaaa7b6213af91ae632e64"
77

88
let current_schema_hash : string =
99
let open Datamodel_types in

ocaml/tests/common/test_common.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,15 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
172172
?(local_cache_sr = Ref.null) ?(chipset_info = []) ?(ssl_legacy = false)
173173
?(last_software_update = Date.epoch) ?(last_update_hash = "")
174174
?(ssh_enabled = true) ?(ssh_enabled_timeout = 0L) ?(ssh_expiry = Date.epoch)
175-
?(console_idle_timeout = 0L) ?(ssh_auto_mode = false) () =
175+
?(console_idle_timeout = 0L) ?(ssh_auto_mode = false) ?(secure_boot = false)
176+
() =
176177
let host =
177178
Xapi_host.create ~__context ~uuid ~name_label ~name_description ~hostname
178179
~address ~external_auth_type ~external_auth_service_name
179180
~external_auth_configuration ~license_params ~edition ~license_server
180181
~local_cache_sr ~chipset_info ~ssl_legacy ~last_software_update
181182
~last_update_hash ~ssh_enabled ~ssh_enabled_timeout ~ssh_expiry
182-
~console_idle_timeout ~ssh_auto_mode
183+
~console_idle_timeout ~ssh_auto_mode ~secure_boot
183184
in
184185
Db.Host.set_cpu_info ~__context ~self:host ~value:default_cpu_info ;
185186
host
@@ -219,7 +220,8 @@ let make_host2 ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
219220
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
220221
~pending_guidances_recommended:[] ~pending_guidances_full:[]
221222
~last_update_hash:"" ~ssh_enabled:true ~ssh_enabled_timeout:0L
222-
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ~ssh_auto_mode:false ;
223+
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ~ssh_auto_mode:false
224+
~secure_boot:false ;
223225
ref
224226

225227
let make_pif ~__context ~network ~host ?(device = "eth0")

ocaml/tests/test_host.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let add_host __context name =
2525
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
2626
~last_software_update:Clock.Date.epoch ~last_update_hash:""
2727
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Clock.Date.epoch
28-
~console_idle_timeout:0L ~ssh_auto_mode:false
28+
~console_idle_timeout:0L ~ssh_auto_mode:false ~secure_boot:false
2929
)
3030

3131
(* Creates an unlicensed pool with the maximum number of hosts *)

ocaml/xapi-cli-server/records.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,9 @@ let host_record rpc session_id host =
33933393
~value:(safe_bool_of_string "ssh-auto-mode" value)
33943394
)
33953395
()
3396+
; make_field ~name:"secure-boot"
3397+
~get:(fun () -> string_of_bool (x ()).API.host_secure_boot)
3398+
()
33963399
]
33973400
}
33983401

ocaml/xapi/dbsync_slave.ml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ let create_localhost ~__context info =
6565
~ssh_expiry:Date.epoch
6666
~console_idle_timeout:Constants.default_console_idle_timeout
6767
~ssh_auto_mode:!Xapi_globs.ssh_auto_mode_default
68+
~secure_boot:false
6869
in
6970
()
7071

@@ -408,5 +409,17 @@ let update_env __context sync_keys =
408409
Xapi_host.set_console_idle_timeout ~__context ~self:localhost
409410
~value:console_timeout
410411
) ;
411-
412+
switched_sync Xapi_globs.sync_secure_boot (fun () ->
413+
let result =
414+
try
415+
let contents = Unixext.string_of_file !Xapi_globs.secure_boot_path in
416+
contents.[4] <> '\x00'
417+
with e ->
418+
warn "%s error while reading %S: %s" __FUNCTION__
419+
!Xapi_globs.secure_boot_path
420+
(Printexc.to_string e) ;
421+
false
422+
in
423+
Db.Host.set_secure_boot ~__context ~self:localhost ~value:result
424+
) ;
412425
remove_pending_guidances ~__context

ocaml/xapi/xapi_globs.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ let sync_chipset_info = "sync_chipset_info"
374374

375375
let sync_ssh_status = "sync_ssh_status"
376376

377+
let sync_secure_boot = "sync_secure_boot"
378+
377379
let sync_pci_devices = "sync_pci_devices"
378380

379381
let sync_gpus = "sync_gpus"
@@ -1330,6 +1332,10 @@ let ssh_monitor_service = ref "xapi-ssh-monitor"
13301332

13311333
let ssh_auto_mode_default = ref true
13321334

1335+
let secure_boot_path =
1336+
ref
1337+
"/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c"
1338+
13331339
(* Fingerprint of default patch key *)
13341340
let citrix_patch_key =
13351341
"NERDNTUzMDMwRUMwNDFFNDI4N0M4OEVCRUFEMzlGOTJEOEE5REUyNg=="
@@ -1786,6 +1792,11 @@ let other_options =
17861792
, "Defaults to true; overridden to false via \
17871793
/etc/xapi.conf.d/ssh-auto-mode.conf(e.g., in XenServer 8)"
17881794
)
1795+
; ( "secure-boot-efi-path"
1796+
, Arg.Set_string secure_boot_path
1797+
, (fun () -> !secure_boot_path)
1798+
, "Path to secure boot status file"
1799+
)
17891800
; ( "vm-sysprep-enabled"
17901801
, Arg.Set vm_sysprep_enabled
17911802
, (fun () -> string_of_bool !vm_sysprep_enabled)

ocaml/xapi/xapi_host.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,8 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10271027
~external_auth_type ~external_auth_service_name ~external_auth_configuration
10281028
~license_params ~edition ~license_server ~local_cache_sr ~chipset_info
10291029
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled
1030-
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode =
1030+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode
1031+
~secure_boot =
10311032
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent
10321033
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during
10331034
the initial setup of the database *)
@@ -1092,7 +1093,8 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10921093
~tls_verification_enabled ~last_software_update ~last_update_hash
10931094
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
10941095
~pending_guidances_recommended:[] ~pending_guidances_full:[] ~ssh_enabled
1095-
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode ;
1096+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode
1097+
~secure_boot ;
10961098
(* If the host we're creating is us, make sure its set to live *)
10971099
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ;
10981100
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ;

0 commit comments

Comments
 (0)