-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component to manage port 1022 for do-release-upgrade
Case RE-943: When performing an elevation from u20->u22, we rely on the do-release-upgrade script to perform the OS upgrade. do-release-upgrade will create a secondary SSH connection on port 1022 as a fallback mechanism in the event that the primary SSH connection is disrupted during the upgrade process. This change ensures that port 1022 is open before executing do-release-upgrade so that the fallback method will work if it is required during the upgrade. It also ensures that port 1022 is closed once the upgrade is complete if it was closed before the upgrade started. Changelog: Add component to manage port 1022 for ELevations that rely on the do-release-upgrade script to perform the OS upgrade
- Loading branch information
Travis Holloway
committed
Dec 10, 2024
1 parent
d1491a9
commit b6003b6
Showing
5 changed files
with
427 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package Elevate::Components::Ufw; | ||
|
||
=encoding utf-8 | ||
=head1 NAME | ||
Elevate::Components::Ufw | ||
=head2 check | ||
noop | ||
=head2 pre_distro_upgrade | ||
Open port 1022 for upgrades using do-release-upgrade | ||
=head2 post_distro_upgrade | ||
Close port 1022 for upgrades using do-release-upgrade | ||
=cut | ||
|
||
use cPstrict; | ||
|
||
use Elevate::OS (); | ||
use Elevate::StageFile (); | ||
|
||
use Log::Log4perl qw(:easy); | ||
|
||
use parent qw{Elevate::Components::Base}; | ||
|
||
use constant UFW => '/usr/sbin/ufw'; | ||
|
||
sub pre_distro_upgrade ($self) { | ||
return unless $self->upgrade_distro_manually(); # skip when --upgrade-distro-manually is provided | ||
return unless Elevate::OS::needs_do_release_upgrade(); | ||
|
||
if ( !-x UFW ) { | ||
my $ufw = UFW; | ||
WARN( <<~"EOS" ); | ||
'$ufw' is either missing or not executable on this server. Unable to | ||
ensure that port 1022 is open as a secondary ssh option for | ||
do-release-upgrade. | ||
EOS | ||
|
||
return; | ||
} | ||
|
||
my $current_status = $self->ssystem_capture_output( UFW, 'status' ); | ||
my $is_active = grep { $_ =~ m/^Status:\sactive$/ } @{ $current_status->{stdout} }; | ||
my $is_open = grep { $_ =~ m{^1022/tcp.*ALLOW.*Anywhere} } @{ $current_status->{stdout} }; | ||
|
||
my $data = { | ||
is_active => $is_active, | ||
is_open => $is_open, | ||
}; | ||
|
||
Elevate::StageFile::update_stage_file( { ufw => $data } ); | ||
|
||
return if $is_active && $is_open; | ||
|
||
$self->ssystem_and_die( UFW, 'allow', '1022/tcp' ); | ||
|
||
$is_active ? $self->ssystem_and_die( UFW, 'reload' ) : $self->ssystem_and_die( UFW, '--force', 'enable' ); | ||
|
||
return; | ||
} | ||
|
||
sub post_distro_upgrade ($self) { | ||
my $ufw_data = Elevate::StageFile::read_stage_file( 'ufw', '' ); | ||
|
||
return unless ref $ufw_data && ref $ufw_data eq 'HASH'; | ||
|
||
return if $ufw_data->{is_active} && $ufw_data->{is_open}; | ||
|
||
$self->ssystem_and_die( UFW, 'delete', 'allow', '1022/tcp' ); | ||
|
||
return if $ufw_data->{is_active}; | ||
|
||
$self->ssystem_and_die( UFW, 'disable' ); | ||
|
||
return; | ||
} | ||
|
||
1; |
This file contains 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.