| 1 | package Ereshkigal::App::Command::clear_retries; | ||||||||||||||||||||||||||||
| 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::clear_retries - Forget unbans still owed to the firewall. | ||||||||||||||||||||||||||||
| 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 | # forget every owed unban, on every kur | ||||||||||||||||||||||||||||
| 23 | ereshkigal clear-retries | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # just the ones sshd is carrying | ||||||||||||||||||||||||||||
| 26 | ereshkigal clear-retries sshd | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # just this one IP, everywhere | ||||||||||||||||||||||||||||
| 29 | ereshkigal clear-retries --ip 1.2.3.4 | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # and a range, on the one kur | ||||||||||||||||||||||||||||
| 32 | ereshkigal clear-retries blocklist --cidr 1.2.3.0/24 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | When a ban's sentence runs out but the backend refuses the unban, the kur | ||||||||||||||||||||||||||||
| 37 | still drops it from the ban book and hands the firewall side to a retry that | ||||||||||||||||||||||||||||
| 38 | backs off until it lands. Those owed unbans show up under C<unban_retries> in | ||||||||||||||||||||||||||||
| 39 | the output of L<banned|Ereshkigal::App::Command::banned> and are counted by | ||||||||||||||||||||||||||||
| 40 | L<status|Ereshkigal::App::Command::status>. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | This forgets them. It is the escape hatch for one that will never land, the | ||||||||||||||||||||||||||||
| 43 | rule having been removed by hand or the backend having never had it to begin | ||||||||||||||||||||||||||||
| 44 | with. Nothing is asked of the firewall, so anything genuinely still banished | ||||||||||||||||||||||||||||
| 45 | there stays banished... this only stops the kur from asking. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Which is the thing to be careful of. If the rule really is still in place, | ||||||||||||||||||||||||||||
| 48 | forgetting it leaves that address blocked indefinitely with nothing tracking | ||||||||||||||||||||||||||||
| 49 | it... it will not appear in C<banned> and no expiry will ever release it. So | ||||||||||||||||||||||||||||
| 50 | check C<banned> first, and where the backend is healthy again prefer a plain | ||||||||||||||||||||||||||||
| 51 | C<unban>, which asks the firewall to remove the rule for real and settles the | ||||||||||||||||||||||||||||
| 52 | debt when it does. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 METHODS | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | The App::Cmd hooks this subcommand supplies... command_names, abstract, | ||||||||||||||||||||||||||||
| 57 | description, usage_desc, opt_spec, validate_args, and execute. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # accept both the dashed and underscored spellings | ||||||||||||||||||||||||||||
| 62 | 113 | ▶ | sub command_names { return ( 'clear-retries', 'clear_retries' ); } | ||||||||||||||||||||||||||
|
Subroutine
command_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub abstract { return 'forget unbans still owed to the firewall' } | ||||||||||||||||||||||||||
|
Subroutine
abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 5 | return <<'DESCRIPTION'; | |||||||||||||||||||||||||||
| 68 | Forget unbans that are still owed to the firewall. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | When a ban's sentence runs out but the backend refuses the unban, the kur | ||||||||||||||||||||||||||||
| 71 | drops it from the ban book and keeps owing the firewall the removal, | ||||||||||||||||||||||||||||
| 72 | retrying with a backoff until it lands. Those debts survive a restart. | ||||||||||||||||||||||||||||
| 73 | "status --all" counts them per kur and "banned" names each one, with how | ||||||||||||||||||||||||||||
| 74 | many times it has been tried and when it is next due. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | This forgets them. With no args every kur forgets every debt it carries; a | ||||||||||||||||||||||||||||
| 77 | kur name scopes it to that one; --ip or --cidr, at most one of the two, | ||||||||||||||||||||||||||||
| 78 | forgets a single entry. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | BEWARE: nothing is sent to the firewall, this only stops the kur asking. | ||||||||||||||||||||||||||||
| 81 | If the rule really is still in place, forgetting it leaves it there with | ||||||||||||||||||||||||||||
| 82 | nothing tracking it, blocking that address indefinitely and no record | ||||||||||||||||||||||||||||
| 83 | anywhere of why. This is for a debt that can never be paid because the | ||||||||||||||||||||||||||||
| 84 | rule is already gone... removed by hand, or on a backend that never | ||||||||||||||||||||||||||||
| 85 | carried it. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | So check "banned" first. If the backend is healthy again, an ordinary | ||||||||||||||||||||||||||||
| 88 | "ereshkigal unban <IP>" is the honest way out: it asks the firewall to | ||||||||||||||||||||||||||||
| 89 | remove the rule for real, and settles the debt when it does. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | ereshkigal clear-retries # every debt, every kur | ||||||||||||||||||||||||||||
| 92 | ereshkigal clear-retries sshd # just that kur's | ||||||||||||||||||||||||||||
| 93 | ereshkigal clear-retries --ip 1.2.3.4 # that one, everywhere | ||||||||||||||||||||||||||||
| 94 | ereshkigal clear-retries blocklist --cidr 1.2.3.0/24 | ||||||||||||||||||||||||||||
| 95 | DESCRIPTION | ||||||||||||||||||||||||||||
| 96 | } ## end sub description | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 10 | ▶ | sub usage_desc { return '%c clear-retries %o [kur]'; } | ||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 10 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | return ( | ||||||||||||||||||||||||||||
| 102 | 10 | [ 'ip=s', 'forget the owed unban of just this IP' ], | |||||||||||||||||||||||||||
| 103 | [ 'cidr=s', 'forget the owed unban of just this CIDR range' ], | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 5 | ▶ | sub validate_args { | ||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 5 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 5 | ▶ | if ( @{$args} > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 1 | $self->usage_error('clear-retries takes at most one arg, a kur instance name'); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 4 | ▶ | if ( defined( $opt->ip ) && defined( $opt->cidr ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opt->ip and defined $opt->cidr
MC/DC100%2/2
defined $opt->ip and defined $opt->cidr
defined $opt->ip
defined $opt->cidr
Truth table100%3/3
A and B
A= defined $opt->ipB= defined $opt->cidr
| |||||||||||||||||||||||||||||
| 114 | 1 | $self->usage_error('--ip and --cidr may not be used together'); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 3 | return; | |||||||||||||||||||||||||||
| 118 | } ## end sub validate_args | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 3 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 3 | my $command_args = {}; | |||||||||||||||||||||||||||
| 124 | 3 | ▶ | if ( @{$args} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 1 | $command_args->{kur} = $args->[0]; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 3 | ▶ | if ( defined( $opt->ip ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 1 | $command_args->{ip} = $opt->ip; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 3 | ▶ | if ( defined( $opt->cidr ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | $command_args->{cidr} = $opt->cidr; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 3 | ▶ | $self->run_command( 'clear_retries', %{$command_args} ? $command_args : undef ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 3 | return; | |||||||||||||||||||||||||||
| 137 | } ## end sub execute | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | 1; | |||||||||||||||||||||||||||