Skip to content

CP-53802: Restore SSH service to default state in pool eject #6399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions ocaml/idl/datamodel_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ let create_params =
; param_name= "ssh_enabled"
; param_doc= "True if SSH access is enabled for the host"
; param_release= numbered_release "25.14.0-next"
; param_default= Some (VBool true)
; param_default= Some (VBool Constants.default_ssh_enabled)
}
; {
param_type= Int
Expand All @@ -1315,7 +1315,7 @@ let create_params =
disabled (0 means never), this setting will be applied every time the \
SSH is enabled by XAPI"
; param_release= numbered_release "25.14.0-next"
; param_default= Some (VInt 0L)
; param_default= Some (VInt Constants.default_ssh_enabled_timeout)
}
; {
param_type= DateTime
Expand All @@ -1333,7 +1333,7 @@ let create_params =
"The timeout in seconds after which idle console will be automatically \
terminated (0 means never)"
; param_release= numbered_release "25.14.0-next"
; param_default= Some (VInt 0L)
; param_default= Some (VInt Constants.default_console_idle_timeout)
}
]

Expand Down Expand Up @@ -2436,7 +2436,7 @@ let set_console_idle_timeout =
~params:
[
(Ref _host, "self", "The host")
; (Int, "value", "The idle console timeout in seconds")
; (Int, "value", "The console idle timeout in seconds")
]
~allowed_roles:_R_POOL_ADMIN ()

Expand Down Expand Up @@ -3039,10 +3039,11 @@ let t =
"The SHA256 checksum of updateinfo of the most recently applied \
update on the host"
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
~default_value:(Some (VBool true)) "ssh_enabled"
"True if SSH access is enabled for the host"
~default_value:(Some (VBool Constants.default_ssh_enabled))
"ssh_enabled" "True if SSH access is enabled for the host"
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int
~default_value:(Some (VInt 0L)) "ssh_enabled_timeout"
~default_value:(Some (VInt Constants.default_ssh_enabled_timeout))
"ssh_enabled_timeout"
"The timeout in seconds after which SSH access will be \
automatically disabled (0 means never), this setting will be \
applied every time the SSH is enabled by XAPI"
Expand All @@ -3051,7 +3052,8 @@ let t =
"The time in UTC after which the SSH access will be automatically \
disabled"
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Int
~default_value:(Some (VInt 0L)) "console_idle_timeout"
~default_value:(Some (VInt Constants.default_console_idle_timeout))
"console_idle_timeout"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you replace them all? I remembered there are some default values to be set in last merged PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #6395, xapi_host.ml, dbsync_slave.ml ...
Also suggest splitting to a single commit for the default value

"The timeout in seconds after which idle console will be \
automatically terminated (0 means never)"
]
Expand Down
6 changes: 6 additions & 0 deletions ocaml/xapi-consts/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,9 @@ let observer_components_all =
let tgroups_enabled = ref false

let when_tgroups_enabled f = if !tgroups_enabled then f () else ()

let default_ssh_enabled = true

let default_ssh_enabled_timeout = 0L

let default_console_idle_timeout = 0L
7 changes: 5 additions & 2 deletions ocaml/xapi/dbsync_slave.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ let create_localhost ~__context info =
~external_auth_configuration:[] ~license_params:[] ~edition:""
~license_server:[("address", "localhost"); ("port", "27000")]
~local_cache_sr:Ref.null ~chipset_info:[] ~ssl_legacy:false
~last_software_update:Date.epoch ~last_update_hash:"" ~ssh_enabled:true
~ssh_enabled_timeout:0L ~ssh_expiry:Date.epoch ~console_idle_timeout:0L
~last_software_update:Date.epoch ~last_update_hash:""
~ssh_enabled:Constants.default_ssh_enabled
~ssh_enabled_timeout:Constants.default_ssh_enabled_timeout
~ssh_expiry:Date.epoch
~console_idle_timeout:Constants.default_console_idle_timeout
in
()

Expand Down
17 changes: 17 additions & 0 deletions ocaml/xapi/xapi_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,23 @@ let eject_self ~__context ~host =
control_domains_to_destroy
with _ -> ()
) ;
( try
(* Restore console idle timeout *)
Xapi_host.set_console_idle_timeout ~__context ~self:host
~value:Constants.default_console_idle_timeout ;
(* Restore SSH service to default state *)
Xapi_host.set_ssh_enabled_timeout ~__context ~self:host
~value:Constants.default_ssh_enabled_timeout ;
match Constants.default_ssh_enabled with
| true ->
Xapi_host.enable_ssh ~__context ~self:host
| false ->
Xapi_host.disable_ssh ~__context ~self:host
with e ->
warn "Caught %s while restoring ssh service. Ignoring"
(Printexc.to_string e)
) ;

debug "Pool.eject: setting our role to be master" ;
Xapi_pool_transition.set_role Pool_role.Master ;
debug "Pool.eject: forgetting pool secret" ;
Expand Down
Loading