« blib/lib/Ereshkigal/App/Command/checkpoint.pm
↑ Summary
blib/lib/Ereshkigal/App/Command/remove.pm »
| 1 | package Ereshkigal::App::Command::re_init; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Ereshkigal::App -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Ereshkigal::App::Command::re_init - Rebuild kur firewall setups from their ban books. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 0.0.1 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 1 | our $VERSION = '0.0.1'; | |||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | # every kur rebuilds | ||||||||||
| 23 | ereshkigal re-init | ||||||||||
| 24 | |||||||||||
| 25 | # just sshd | ||||||||||
| 26 | ereshkigal re-init sshd | ||||||||||
| 27 | |||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||
| 29 | |||||||||||
| 30 | Has each kur tear its firewall setup down and build it again from scratch, | ||||||||||
| 31 | re-banning everything its ban book carries. This is the repair for a setup | ||||||||||
| 32 | that something outside Ereshkigal has interfered with... a C<shorewall | ||||||||||
| 33 | restart> or C<pf -F all> that dropped the rules, a firewalld reload, an ipset | ||||||||||
| 34 | flushed by hand. It also settles unban debts, as tearing down takes any rule | ||||||||||
| 35 | a failed unban left behind with it. | ||||||||||
| 36 | |||||||||||
| 37 | Bans are not enforced during the rebuild. It is brief, but it is a real | ||||||||||
| 38 | window. | ||||||||||
| 39 | |||||||||||
| 40 | Mostly a convenience... with C<self_heal> on, which is the default, each kur | ||||||||||
| 41 | already checks its setup before every ban and unban and rebuilds it if it has | ||||||||||
| 42 | gone missing. This is for when that is wanted now rather than at the next | ||||||||||
| 43 | ban, or when C<self_heal> is off. | ||||||||||
| 44 | |||||||||||
| 45 | =head1 METHODS | ||||||||||
| 46 | |||||||||||
| 47 | The App::Cmd hooks this subcommand supplies... command_names, abstract, | ||||||||||
| 48 | description, usage_desc, validate_args, and execute. | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | # accept both the dashed and underscored spellings | ||||||||||
| 53 | 113 | ▶ | sub command_names { return ( 're-init', 're_init' ); } | ||||||||
|
Subroutine
command_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | sub abstract { return 'rebuild kur firewall setups from their ban books' } | ||||||||
|
Subroutine
abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 56 | |||||||||||
| 57 | 4 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 4 | return <<'DESCRIPTION'; | |||||||||
| 59 | Rebuild a kur's firewall setup from its ban book. | ||||||||||
| 60 | |||||||||||
| 61 | The kur tears its table, set, chain, or list down and builds it again from | ||||||||||
| 62 | scratch, then re-bans everything its book is carrying. The book is the | ||||||||||
| 63 | authority here, so the firewall ends up matching what Ereshkigal believes | ||||||||||
| 64 | it is holding. | ||||||||||
| 65 | |||||||||||
| 66 | This is the repair for a setup something outside Ereshkigal has interfered | ||||||||||
| 67 | with: a "shorewall restart" or "pf -F all" that dropped the rules, a | ||||||||||
| 68 | firewalld reload, an ipset someone flushed by hand. It also settles unban | ||||||||||
| 69 | debts, since tearing down takes any rule the kur failed to remove with it. | ||||||||||
| 70 | |||||||||||
| 71 | Bans are NOT enforced during the rebuild. It is brief, but it is a real | ||||||||||
| 72 | window, so prefer a quiet moment on a busy edge. | ||||||||||
| 73 | |||||||||||
| 74 | Most kurs will not need this. With self_heal on, which is the default, a | ||||||||||
| 75 | kur already checks its setup before every ban and unban and rebuilds it | ||||||||||
| 76 | if it has gone missing... this is the manual version, for when you want | ||||||||||
| 77 | it now rather than at the next ban, or when self_heal is off. | ||||||||||
| 78 | |||||||||||
| 79 | With no args every kur rebuilds; with a kur name only that one, and naming | ||||||||||
| 80 | a fan_out gate reaches every kur behind it. | ||||||||||
| 81 | |||||||||||
| 82 | ereshkigal re-init # everything | ||||||||||
| 83 | ereshkigal re-init sshd # just that one | ||||||||||
| 84 | DESCRIPTION | ||||||||||
| 85 | } ## end sub description | ||||||||||
| 86 | |||||||||||
| 87 | 7 | ▶ | sub usage_desc { return '%c re-init %o [kur]'; } | ||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 88 | |||||||||||
| 89 | 3 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 90 | 3 | my ( $self, $opt, $args ) = @_; | |||||||||
| 91 | |||||||||||
| 92 | 3 | ▶ | if ( @{$args} > 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 1 | $self->usage_error('re-init takes at most one arg, a kur instance name'); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 2 | return; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 2 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 100 | 2 | my ( $self, $opt, $args ) = @_; | |||||||||
| 101 | |||||||||||
| 102 | 2 | ▶ | $self->run_command( 're_init', @{$args} ? { 'kur' => $args->[0] } : undef ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | |||||||||||
| 104 | 2 | return; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 1 | 1; | |||||||||