Skip to content

Commit a875364

Browse files
committed
CP-53711: Copy SSH settings from pool coordinator in pool join
During pool join, create a new host obj in the remote pool coordinator DB with the same SSH settings as pool coordinator. Also configure SSH service locally before xapi restart which will persist after xapi restart. Signed-off-by: Gang Ji <[email protected]>
1 parent db38cb0 commit a875364

File tree

7 files changed

+92
-8
lines changed

7 files changed

+92
-8
lines changed

ocaml/idl/datamodel_host.ml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,41 @@ let create_params =
13001300
; param_release= numbered_release "24.40.0"
13011301
; param_default= Some (VString "")
13021302
}
1303+
; {
1304+
param_type= Bool
1305+
; param_name= "ssh_enabled"
1306+
; param_doc= "True if SSH access is enabled for the host"
1307+
; param_release= numbered_release "25.14.0-next"
1308+
; param_default= Some (VBool true)
1309+
}
1310+
; {
1311+
param_type= Int
1312+
; param_name= "ssh_enabled_timeout"
1313+
; param_doc=
1314+
"The timeout in seconds after which SSH access will be automatically \
1315+
disabled (0 means never), this setting will be applied every time the \
1316+
SSH is enabled by XAPI"
1317+
; param_release= numbered_release "25.14.0-next"
1318+
; param_default= Some (VInt 0L)
1319+
}
1320+
; {
1321+
param_type= DateTime
1322+
; param_name= "ssh_expiry"
1323+
; param_doc=
1324+
"The time in UTC after which the SSH access will be automatically \
1325+
disabled"
1326+
; param_release= numbered_release "25.14.0-next"
1327+
; param_default= Some (VDateTime Date.epoch)
1328+
}
1329+
; {
1330+
param_type= Int
1331+
; param_name= "console_idle_timeout"
1332+
; param_doc=
1333+
"The timeout in seconds after which idle console will be automatically \
1334+
terminated (0 means never)"
1335+
; param_release= numbered_release "25.14.0-next"
1336+
; param_default= Some (VInt 0L)
1337+
}
13031338
]
13041339

13051340
let create =
@@ -1312,6 +1347,12 @@ let create =
13121347
, "Added --last_update_hash option to allow last_update_hash to be \
13131348
kept for host joined a pool"
13141349
)
1350+
; ( Changed
1351+
, "25.14.0-next"
1352+
, "Added --ssh_enabled --ssh_enabled_timeout --ssh_expiry \
1353+
--console_idle_timeout options to allow them to be configured for \
1354+
new host"
1355+
)
13151356
]
13161357
~versioned_params:create_params ~doc:"Create a new host record"
13171358
~result:(Ref _host, "Reference to the newly created host object.")

ocaml/tests/common/test_common.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
170170
?(external_auth_service_name = "") ?(external_auth_configuration = [])
171171
?(license_params = []) ?(edition = "free") ?(license_server = [])
172172
?(local_cache_sr = Ref.null) ?(chipset_info = []) ?(ssl_legacy = false)
173-
?(last_software_update = Date.epoch) ?(last_update_hash = "") () =
173+
?(last_software_update = Date.epoch) ?(last_update_hash = "")
174+
?(ssh_enabled = true) ?(ssh_enabled_timeout = 0L) ?(ssh_expiry = Date.epoch)
175+
?(console_idle_timeout = 0L) () =
174176
let host =
175177
Xapi_host.create ~__context ~uuid ~name_label ~name_description ~hostname
176178
~address ~external_auth_type ~external_auth_service_name
177179
~external_auth_configuration ~license_params ~edition ~license_server
178180
~local_cache_sr ~chipset_info ~ssl_legacy ~last_software_update
179-
~last_update_hash
181+
~last_update_hash ~ssh_enabled ~ssh_enabled_timeout ~ssh_expiry
182+
~console_idle_timeout
180183
in
181184
Db.Host.set_cpu_info ~__context ~self:host ~value:default_cpu_info ;
182185
host

ocaml/tests/test_host.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ let add_host __context name =
2424
~license_params:[] ~edition:"" ~license_server:[]
2525
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
2626
~last_software_update:Clock.Date.epoch ~last_update_hash:""
27+
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Clock.Date.epoch
28+
~console_idle_timeout:0L
2729
)
2830

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

ocaml/xapi/dbsync_slave.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ let create_localhost ~__context info =
5959
~external_auth_configuration:[] ~license_params:[] ~edition:""
6060
~license_server:[("address", "localhost"); ("port", "27000")]
6161
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
62-
~last_software_update:Date.epoch ~last_update_hash:""
62+
~last_software_update:Date.epoch ~last_update_hash:"" ~ssh_enabled:true
63+
~ssh_enabled_timeout:0L ~ssh_expiry:Date.epoch ~console_idle_timeout:0L
6364
in
6465
()
6566

ocaml/xapi/xapi_host.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,8 @@ let is_host_alive ~__context ~host =
978978
let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
979979
~external_auth_type ~external_auth_service_name ~external_auth_configuration
980980
~license_params ~edition ~license_server ~local_cache_sr ~chipset_info
981-
~ssl_legacy:_ ~last_software_update ~last_update_hash =
981+
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled
982+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout =
982983
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent
983984
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during
984985
the initial setup of the database *)
@@ -1042,9 +1043,8 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10421043
~multipathing:false ~uefi_certificates:"" ~editions:[] ~pending_guidances:[]
10431044
~tls_verification_enabled ~last_software_update ~last_update_hash
10441045
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
1045-
~pending_guidances_recommended:[] ~pending_guidances_full:[]
1046-
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Date.epoch
1047-
~console_idle_timeout:0L ;
1046+
~pending_guidances_recommended:[] ~pending_guidances_full:[] ~ssh_enabled
1047+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ;
10481048
(* If the host we're creating is us, make sure its set to live *)
10491049
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ;
10501050
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ;

ocaml/xapi/xapi_host.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ val create :
130130
-> ssl_legacy:bool
131131
-> last_software_update:API.datetime
132132
-> last_update_hash:string
133+
-> ssh_enabled:bool
134+
-> ssh_enabled_timeout:int64
135+
-> ssh_expiry:API.datetime
136+
-> console_idle_timeout:int64
133137
-> [`host] Ref.t
134138

135139
val destroy : __context:Context.t -> self:API.ref_host -> unit

ocaml/xapi/xapi_pool.ml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,38 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
943943
create_or_get_sr_on_master __context rpc session_id
944944
(my_local_cache_sr, my_local_cache_sr_rec)
945945
in
946+
let remote_coordinator = get_master ~rpc ~session_id in
947+
let ssh_enabled =
948+
Client.Host.get_ssh_enabled ~rpc ~session_id ~self:remote_coordinator
949+
in
950+
let ssh_enabled_timeout =
951+
Client.Host.get_ssh_enabled_timeout ~rpc ~session_id
952+
~self:remote_coordinator
953+
in
954+
let console_idle_timeout =
955+
Client.Host.get_console_idle_timeout ~rpc ~session_id
956+
~self:remote_coordinator
957+
in
958+
(* Configure SSH service on local host *)
959+
Xapi_host.set_console_idle_timeout ~__context ~self:host_ref
960+
~value:console_idle_timeout ;
961+
Xapi_host.set_ssh_enabled_timeout ~__context ~self:host_ref
962+
~value:ssh_enabled_timeout ;
963+
( match ssh_enabled with
964+
| true ->
965+
Xapi_host.enable_ssh ~__context ~self:host_ref
966+
| false ->
967+
Xapi_host.disable_ssh ~__context ~self:host_ref
968+
) ;
969+
(* As ssh_expiry will be updated by host.enable_ssh and host.disable_ssh,
970+
there is a corner case when the joiner's SSH state will not match SSH
971+
service state in its new coordinator exactly: if the joiner joins when
972+
SSH service has been enabled in the new coordinator, while not timed
973+
out yet, the joiner will start SSH service with timeout
974+
host.ssh_enabled_timeout, which means SSH service in the joiner will
975+
be disabled later than in the new coordinator. *)
976+
let ssh_expiry = Db.Host.get_ssh_expiry ~__context ~self:host_ref in
977+
946978
debug "Creating host object on master" ;
947979
let ref =
948980
Client.Host.create ~rpc ~session_id ~uuid:my_uuid
@@ -962,7 +994,8 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
962994
~local_cache_sr ~chipset_info:host.API.host_chipset_info
963995
~ssl_legacy:false
964996
~last_software_update:host.API.host_last_software_update
965-
~last_update_hash:host.API.host_last_update_hash
997+
~last_update_hash:host.API.host_last_update_hash ~ssh_enabled
998+
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout
966999
in
9671000
(* Copy other-config into newly created host record: *)
9681001
no_exn

0 commit comments

Comments
 (0)