Skip to content

Commit 2f00a21

Browse files
authored
CP-53477 Update Host/Pool Data model to Support Dom0 SSH Control (#6388)
This PR introduces support for Dom0 SSH control, providing the following capabilities: Query the SSH status. Configure a temporary SSH enable timeout for a specific host or all hosts in the pool. Configure the console idle timeout for a specific host or all hosts in the pool. Changes New Host Object Fields: - `ssh_enabled`: Indicates whether SSH is enabled. - `ssh_enabled_timeout`: Specifies the timeout for temporary SSH enablement. - `ssh_expiry`: Tracks the expiration time for temporary SSH enablement. - `console_idle_timeout`: Configures the idle timeout for the console. New Host/Pool APIs (This PR only include the change of data model, the implementation of this API will be include in the next PR): - `set_ssh_enabled_timeout`: Allows setting a temporary timeout for enabling the SSH service. - `set_console_idle_timeout`: Allows configuring the console idle timeout.
2 parents afe37ec + 12e5680 commit 2f00a21

12 files changed

+131
-4
lines changed

ocaml/idl/datamodel_common.ml

+1-1
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 = 786
13+
let schema_minor_vsn = 787
1414

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

ocaml/idl/datamodel_errors.ml

+3
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,9 @@ let _ =
20432043
error Api_errors.host_driver_no_hardware ["driver variant"]
20442044
~doc:"No hardware present for this host driver variant" () ;
20452045

2046+
error Api_errors.set_console_idle_timeout_failed ["timeout"]
2047+
~doc:"Failed to set console idle timeout." () ;
2048+
20462049
error Api_errors.tls_verification_not_enabled_in_pool []
20472050
~doc:
20482051
"TLS verification has not been enabled in the pool successfully, please \

ocaml/idl/datamodel_host.ml

+41
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,29 @@ let disable_ssh =
23682368
~params:[(Ref _host, "self", "The host")]
23692369
~allowed_roles:_R_POOL_ADMIN ()
23702370

2371+
let set_ssh_enabled_timeout =
2372+
call ~name:"set_ssh_enabled_timeout" ~lifecycle:[]
2373+
~doc:"Set the SSH service enabled timeout for the host"
2374+
~params:
2375+
[
2376+
(Ref _host, "self", "The host")
2377+
; ( Int
2378+
, "value"
2379+
, "The SSH enabled timeout in seconds (0 means no timeout, max 2 days)"
2380+
)
2381+
]
2382+
~allowed_roles:_R_POOL_ADMIN ()
2383+
2384+
let set_console_idle_timeout =
2385+
call ~name:"set_console_idle_timeout" ~lifecycle:[]
2386+
~doc:"Set the console idle timeout for the host"
2387+
~params:
2388+
[
2389+
(Ref _host, "self", "The host")
2390+
; (Int, "value", "The idle console timeout in seconds")
2391+
]
2392+
~allowed_roles:_R_POOL_ADMIN ()
2393+
23712394
let latest_synced_updates_applied_state =
23722395
Enum
23732396
( "latest_synced_updates_applied_state"
@@ -2527,6 +2550,8 @@ let t =
25272550
; emergency_clear_mandatory_guidance
25282551
; enable_ssh
25292552
; disable_ssh
2553+
; set_ssh_enabled_timeout
2554+
; set_console_idle_timeout
25302555
]
25312556
~contents:
25322557
([
@@ -2964,6 +2989,22 @@ let t =
29642989
~default_value:(Some (VString "")) "last_update_hash"
29652990
"The SHA256 checksum of updateinfo of the most recently applied \
29662991
update on the host"
2992+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
2993+
~default_value:(Some (VBool true)) "ssh_enabled"
2994+
"True if SSH access is enabled for the host"
2995+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int
2996+
~default_value:(Some (VInt 0L)) "ssh_enabled_timeout"
2997+
"The timeout in seconds after which SSH access will be \
2998+
automatically disabled (0 means never), this setting will be \
2999+
applied every time the SSH is enabled by XAPI"
3000+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:DateTime
3001+
~default_value:(Some (VDateTime Date.epoch)) "ssh_expiry"
3002+
"The time in UTC after which the SSH access will be automatically \
3003+
disabled"
3004+
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int
3005+
~default_value:(Some (VInt 0L)) "console_idle_timeout"
3006+
"The timeout in seconds after which idle console will be \
3007+
automatically terminated (0 means never)"
29673008
]
29683009
)
29693010
()

ocaml/idl/datamodel_pool.ml

+29
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,33 @@ let disable_ssh =
15711571
~params:[(Ref _pool, "self", "The pool")]
15721572
~allowed_roles:_R_POOL_ADMIN ()
15731573

1574+
let set_ssh_enabled_timeout =
1575+
call ~name:"set_ssh_enabled_timeout" ~lifecycle:[]
1576+
~doc:"Set the SSH enabled timeout for all hosts in the pool"
1577+
~params:
1578+
[
1579+
(Ref _pool, "self", "The pool")
1580+
; ( Int
1581+
, "value"
1582+
, "The SSH enabled timeout in seconds. (0 means no timeout, max 2 days)"
1583+
)
1584+
]
1585+
~allowed_roles:_R_POOL_ADMIN ()
1586+
1587+
let set_console_idle_timeout =
1588+
call ~name:"set_console_idle_timeout" ~lifecycle:[]
1589+
~doc:"Set the console idle timeout for all hosts in the pool"
1590+
~params:
1591+
[
1592+
(Ref _pool, "self", "The pool")
1593+
; ( Int
1594+
, "value"
1595+
, "The idle SSH/VNC session timeout in seconds. A value of 0 means no \
1596+
timeout."
1597+
)
1598+
]
1599+
~allowed_roles:_R_POOL_ADMIN ()
1600+
15741601
(** A pool class *)
15751602
let t =
15761603
create_obj ~in_db:true
@@ -1667,6 +1694,8 @@ let t =
16671694
; get_guest_secureboot_readiness
16681695
; enable_ssh
16691696
; disable_ssh
1697+
; set_ssh_enabled_timeout
1698+
; set_console_idle_timeout
16701699
]
16711700
~contents:
16721701
([

ocaml/idl/schematest.ml

+1-1
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 = "ad67a64cd47cdea32085518c1fb38d27"
6+
let last_known_schema_hash = "0cc42d0325bd7ea01a5024d63b835bfb"
77

88
let current_schema_hash : string =
99
let open Datamodel_types in

ocaml/tests/common/test_common.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ let make_host2 ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
215215
~last_software_update:(Xapi_host.get_servertime ~__context ~host:ref)
216216
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
217217
~pending_guidances_recommended:[] ~pending_guidances_full:[]
218-
~last_update_hash:"" ;
218+
~last_update_hash:"" ~ssh_enabled:true ~ssh_enabled_timeout:0L
219+
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ;
219220
ref
220221

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

ocaml/xapi-consts/api_errors.ml

+3
Original file line numberDiff line numberDiff line change
@@ -1424,3 +1424,6 @@ let host_driver_no_hardware = add_error "HOST_DRIVER_NO_HARDWARE"
14241424

14251425
let tls_verification_not_enabled_in_pool =
14261426
add_error "TLS_VERIFICATION_NOT_ENABLED_IN_POOL"
1427+
1428+
let set_console_idle_timeout_failed =
1429+
add_error "SET_CONSOLE_IDLE_TIMEOUT_FAILED"

ocaml/xapi/message_forwarding.ml

+28
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,18 @@ functor
11851185
let disable_ssh ~__context ~self =
11861186
info "%s: pool = '%s'" __FUNCTION__ (pool_uuid ~__context self) ;
11871187
Local.Pool.disable_ssh ~__context ~self
1188+
1189+
let set_ssh_enabled_timeout ~__context ~self ~value =
1190+
info "Pool.set_ssh_enabled_timeout: pool='%s' value='%Ld'"
1191+
(pool_uuid ~__context self)
1192+
value ;
1193+
Local.Pool.set_ssh_enabled_timeout ~__context ~self ~value
1194+
1195+
let set_console_idle_timeout ~__context ~self ~value =
1196+
info "Pool.set_console_idle_timeout: pool='%s' value='%Ld'"
1197+
(pool_uuid ~__context self)
1198+
value ;
1199+
Local.Pool.set_console_idle_timeout ~__context ~self ~value
11881200
end
11891201

11901202
module VM = struct
@@ -4035,6 +4047,22 @@ functor
40354047
let local_fn = Local.Host.disable_ssh ~self in
40364048
let remote_fn = Client.Host.disable_ssh ~self in
40374049
do_op_on ~local_fn ~__context ~host:self ~remote_fn
4050+
4051+
let set_ssh_enabled_timeout ~__context ~self ~value =
4052+
info "Host.set_ssh_enabled_timeout: host='%s' value='%Ld'"
4053+
(host_uuid ~__context self)
4054+
value ;
4055+
let local_fn = Local.Host.set_ssh_enabled_timeout ~self ~value in
4056+
let remote_fn = Client.Host.set_ssh_enabled_timeout ~self ~value in
4057+
do_op_on ~local_fn ~__context ~host:self ~remote_fn
4058+
4059+
let set_console_idle_timeout ~__context ~self ~value =
4060+
info "Host.set_console_idle_timeout: host='%s' value='%Ld'"
4061+
(host_uuid ~__context self)
4062+
value ;
4063+
let local_fn = Local.Host.set_console_idle_timeout ~self ~value in
4064+
let remote_fn = Client.Host.set_console_idle_timeout ~self ~value in
4065+
do_op_on ~local_fn ~__context ~host:self ~remote_fn
40384066
end
40394067

40404068
module Host_crashdump = struct

ocaml/xapi/xapi_host.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,9 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10421042
~multipathing:false ~uefi_certificates:"" ~editions:[] ~pending_guidances:[]
10431043
~tls_verification_enabled ~last_software_update ~last_update_hash
10441044
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
1045-
~pending_guidances_recommended:[] ~pending_guidances_full:[] ;
1045+
~pending_guidances_recommended:[] ~pending_guidances_full:[]
1046+
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Date.epoch
1047+
~console_idle_timeout:0L ;
10461048
(* If the host we're creating is us, make sure its set to live *)
10471049
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ;
10481050
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ;
@@ -3131,3 +3133,7 @@ let disable_ssh ~__context ~self =
31313133
(Api_errors.Server_error
31323134
(Api_errors.disable_ssh_failed, [Ref.string_of self])
31333135
)
3136+
3137+
let set_ssh_enabled_timeout ~__context ~self:_ ~value:_ = ()
3138+
3139+
let set_console_idle_timeout ~__context ~self:_ ~value:_ = ()

ocaml/xapi/xapi_host.mli

+6
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,9 @@ val emergency_clear_mandatory_guidance : __context:Context.t -> unit
567567
val enable_ssh : __context:Context.t -> self:API.ref_host -> unit
568568

569569
val disable_ssh : __context:Context.t -> self:API.ref_host -> unit
570+
571+
val set_ssh_enabled_timeout :
572+
__context:Context.t -> self:API.ref_host -> value:int64 -> unit
573+
574+
val set_console_idle_timeout :
575+
__context:Context.t -> self:API.ref_host -> value:int64 -> unit

ocaml/xapi/xapi_pool.ml

+4
Original file line numberDiff line numberDiff line change
@@ -4008,3 +4008,7 @@ end
40084008
let enable_ssh = Ssh.enable
40094009

40104010
let disable_ssh = Ssh.disable
4011+
4012+
let set_ssh_enabled_timeout ~__context ~self:_ ~value:_ = ()
4013+
4014+
let set_console_idle_timeout ~__context ~self:_ ~value:_ = ()

ocaml/xapi/xapi_pool.mli

+6
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,9 @@ val put_bundle_handler : Http.Request.t -> Unix.file_descr -> 'a -> unit
437437
val enable_ssh : __context:Context.t -> self:API.ref_pool -> unit
438438

439439
val disable_ssh : __context:Context.t -> self:API.ref_pool -> unit
440+
441+
val set_ssh_enabled_timeout :
442+
__context:Context.t -> self:API.ref_pool -> value:int64 -> unit
443+
444+
val set_console_idle_timeout :
445+
__context:Context.t -> self:API.ref_pool -> value:int64 -> unit

0 commit comments

Comments
 (0)