-
Notifications
You must be signed in to change notification settings - Fork 291
CP-53721 Enable XAPI to configure SSH auto mode #6442
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
Open
LunfanZhang
wants to merge
3
commits into
xapi-project:feature/configure-ssh-phase3
Choose a base branch
from
LunfanZhang:private/lunfan/CP-53721
base: feature/configure-ssh-phase3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−15
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -979,7 +979,7 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address | |
~external_auth_type ~external_auth_service_name ~external_auth_configuration | ||
~license_params ~edition ~license_server ~local_cache_sr ~chipset_info | ||
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled | ||
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout = | ||
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode = | ||
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent | ||
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during | ||
the initial setup of the database *) | ||
|
@@ -1044,7 +1044,7 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address | |
~tls_verification_enabled ~last_software_update ~last_update_hash | ||
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown | ||
~pending_guidances_recommended:[] ~pending_guidances_full:[] ~ssh_enabled | ||
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ; | ||
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode ; | ||
(* If the host we're creating is us, make sure its set to live *) | ||
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ; | ||
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ; | ||
|
@@ -3112,18 +3112,47 @@ let emergency_clear_mandatory_guidance ~__context = | |
) ; | ||
Db.Host.set_pending_guidances ~__context ~self ~value:[] | ||
|
||
let set_ssh_auto_mode ~__context ~self ~value = | ||
debug "Setting SSH auto mode for host %s to %B" | ||
(Helpers.get_localhost_uuid ()) | ||
value ; | ||
|
||
Db.Host.set_ssh_auto_mode ~__context ~self ~value ; | ||
|
||
try | ||
(* When enabled, the ssh_monitor_service regularly checks XAPI status to manage SSH availability. | ||
During normal operation when XAPI is running properly, SSH is automatically disabled. | ||
SSH is only enabled during emergency scenarios | ||
(e.g., when XAPI is down) to allow administrative access for troubleshooting. *) | ||
if value then ( | ||
Xapi_systemctl.enable ~wait_until_success:false | ||
!Xapi_globs.ssh_monitor_service ; | ||
LunfanZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Xapi_systemctl.start ~wait_until_success:false | ||
!Xapi_globs.ssh_monitor_service | ||
) else ( | ||
Xapi_systemctl.stop ~wait_until_success:false | ||
!Xapi_globs.ssh_monitor_service ; | ||
Xapi_systemctl.disable ~wait_until_success:false | ||
!Xapi_globs.ssh_monitor_service | ||
) | ||
with e -> | ||
error "Failed to configure SSH auto mode: %s" (Printexc.to_string e) ; | ||
Helpers.internal_error "Failed to configure SSH auto mode: %s" | ||
(Printexc.to_string e) | ||
|
||
let disable_ssh_internal ~__context ~self = | ||
try | ||
debug "Disabling SSH for host %s" (Helpers.get_localhost_uuid ()) ; | ||
Xapi_systemctl.disable ~wait_until_success:false !Xapi_globs.ssh_service ; | ||
if Db.Host.get_ssh_auto_mode ~__context ~self = false then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use |
||
Xapi_systemctl.disable ~wait_until_success:false !Xapi_globs.ssh_service ; | ||
Xapi_systemctl.stop ~wait_until_success:false !Xapi_globs.ssh_service ; | ||
Db.Host.set_ssh_enabled ~__context ~self ~value:false | ||
with e -> | ||
error "Failed to disable SSH for host %s: %s" (Ref.string_of self) | ||
(Printexc.to_string e) ; | ||
Helpers.internal_error "Failed to disable SSH: %s" (Printexc.to_string e) | ||
|
||
let schedule_disable_ssh_job ~__context ~self ~timeout = | ||
let schedule_disable_ssh_job ~__context ~self ~timeout ~auto_mode = | ||
let host_uuid = Helpers.get_localhost_uuid () in | ||
let expiry_time = | ||
match | ||
|
@@ -3152,7 +3181,11 @@ let schedule_disable_ssh_job ~__context ~self ~timeout = | |
Xapi_stdext_threads_scheduler.Scheduler.add_to_queue | ||
!Xapi_globs.job_for_disable_ssh | ||
Xapi_stdext_threads_scheduler.Scheduler.OneShot (Int64.to_float timeout) | ||
(fun () -> disable_ssh_internal ~__context ~self | ||
(fun () -> | ||
disable_ssh_internal ~__context ~self ; | ||
(* re-enable SSH auto mode if it was enabled before calling host.enable_ssh *) | ||
if auto_mode then | ||
set_ssh_auto_mode ~__context ~self ~value:true | ||
) ; | ||
|
||
Db.Host.set_ssh_expiry ~__context ~self ~value:expiry_time | ||
|
@@ -3161,6 +3194,10 @@ let enable_ssh ~__context ~self = | |
try | ||
debug "Enabling SSH for host %s" (Helpers.get_localhost_uuid ()) ; | ||
|
||
let cached_ssh_auto_mode = Db.Host.get_ssh_auto_mode ~__context ~self in | ||
(* Disable SSH auto mode when SSH is enabled manually *) | ||
set_ssh_auto_mode ~__context ~self ~value:false ; | ||
|
||
Xapi_systemctl.enable ~wait_until_success:false !Xapi_globs.ssh_service ; | ||
Xapi_systemctl.start ~wait_until_success:false !Xapi_globs.ssh_service ; | ||
|
||
|
@@ -3171,6 +3208,7 @@ let enable_ssh ~__context ~self = | |
!Xapi_globs.job_for_disable_ssh | ||
| t -> | ||
schedule_disable_ssh_job ~__context ~self ~timeout:t | ||
~auto_mode:cached_ssh_auto_mode | ||
) ; | ||
|
||
Db.Host.set_ssh_enabled ~__context ~self ~value:true | ||
|
@@ -3208,7 +3246,7 @@ let set_ssh_enabled_timeout ~__context ~self ~value = | |
!Xapi_globs.job_for_disable_ssh ; | ||
Db.Host.set_ssh_expiry ~__context ~self ~value:Date.epoch | ||
| t -> | ||
schedule_disable_ssh_job ~__context ~self ~timeout:t | ||
schedule_disable_ssh_job ~__context ~self ~timeout:t ~auto_mode:false | ||
|
||
let set_console_idle_timeout ~__context ~self ~value = | ||
let assert_timeout_valid timeout = | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we report at the API level the reference (rather the UUID) in logs. User-facing messages report the UUID, though.