Skip to content

Commit 6e6c0ed

Browse files
authored
CP-53711: Copy SSH settings from pool coordinator in pool join (#6395)
2 parents 497bbfa + a875364 commit 6e6c0ed

File tree

8 files changed

+113
-13
lines changed

8 files changed

+113
-13
lines changed

ocaml/idl/datamodel_host.ml

+51-2
Original file line numberDiff line numberDiff line change
@@ -1297,14 +1297,63 @@ let create_params =
12971297
; param_doc=
12981298
"The SHA256 checksum of updateinfo of the most recently applied update \
12991299
on the host"
1300-
; param_release= numbered_release "24.39.0-next"
1300+
; 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 =
13061341
call ~name:"create" ~in_oss_since:None
1307-
~lifecycle:[(Published, rel_rio, "Create a new host record")]
1342+
~lifecycle:
1343+
[
1344+
(Published, rel_rio, "Create a new host record")
1345+
; ( Changed
1346+
, "24.40.0"
1347+
, "Added --last_update_hash option to allow last_update_hash to be \
1348+
kept for host joined a pool"
1349+
)
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+
)
1356+
]
13081357
~versioned_params:create_params ~doc:"Create a new host record"
13091358
~result:(Ref _host, "Reference to the newly created host object.")
13101359
~hide_from_docs:true ~allowed_roles:_R_POOL_OP ()

ocaml/idl/datamodel_pool.ml

+11-3
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,15 @@ let remove_repository =
12491249

12501250
let sync_updates =
12511251
call ~name:"sync_updates"
1252-
~lifecycle:[(Published, "1.329.0", "")]
1252+
~lifecycle:
1253+
[
1254+
(Published, "1.329.0", "")
1255+
; ( Changed
1256+
, "25.7.0"
1257+
, "Added --username --password options to allow syncing updates from a \
1258+
remote_pool type repository"
1259+
)
1260+
]
12531261
~doc:"Sync with the enabled repository"
12541262
~versioned_params:
12551263
[
@@ -1286,14 +1294,14 @@ let sync_updates =
12861294
param_type= String
12871295
; param_name= "username"
12881296
; param_doc= "The username of the remote pool"
1289-
; param_release= numbered_release "25.6.0-next"
1297+
; param_release= numbered_release "25.7.0"
12901298
; param_default= Some (VString "")
12911299
}
12921300
; {
12931301
param_type= String
12941302
; param_name= "password"
12951303
; param_doc= "The password of the remote pool"
1296-
; param_release= numbered_release "25.6.0-next"
1304+
; param_release= numbered_release "25.7.0"
12971305
; param_default= Some (VString "")
12981306
}
12991307
]

ocaml/tests/common/test_common.ml

+5-2
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

+2
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

+2-1
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

+4-4
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

+4
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

+34-1
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)