mirror of
https://github.com/ovh/the-bastion.git
synced 2025-01-08 00:12:10 +08:00
69 lines
2.2 KiB
Perl
Executable file
69 lines
2.2 KiB
Perl
Executable file
#! /usr/bin/env perl
|
|
# vim: set filetype=perl ts=4 sw=4 sts=4 et:
|
|
use common::sense;
|
|
|
|
use File::Basename;
|
|
use lib dirname(__FILE__) . '/../../../lib/perl';
|
|
use OVH::Result;
|
|
use OVH::Bastion;
|
|
use OVH::Bastion::Plugin qw( :DEFAULT help );
|
|
use OVH::Bastion::Plugin::ACL;
|
|
|
|
my $remainingOptions = OVH::Bastion::Plugin::begin(
|
|
argv => \@ARGV,
|
|
header => "removing personal access to a server from an account",
|
|
options => {
|
|
"user-any" => \my $userAny,
|
|
"port-any" => \my $portAny,
|
|
"scpup" => \my $scpUp,
|
|
"scpdown" => \my $scpDown,
|
|
"sftp" => \my $sftp,
|
|
},
|
|
helptext => <<'EOF',
|
|
Remove a personal server access from your account
|
|
|
|
Usage: --osh SCRIPT_NAME --host HOST [OPTIONS]
|
|
|
|
--host IP|HOST|IP/MASK Server to remove access from
|
|
--user USER Remote user that was allowed, if any user was allowed, use --user-any
|
|
--user-any Use if any remote login was allowed
|
|
--port PORT Remote SSH port that was allowed, if any port was allowed, use --port-any
|
|
--port-any Use if any remote port was allowed
|
|
--scpup Remove SCP upload right, you--bastion-->server (omit --user in this case)
|
|
--scpdown Remove SCP download right, you<--bastion--server (omit --user in this case)
|
|
--sftp Remove usage of the SFTP subsystem, you<--bastion-->server (omit --user in this case)
|
|
EOF
|
|
);
|
|
|
|
my $fnret;
|
|
|
|
if (!$ip) {
|
|
help();
|
|
osh_exit 'ERR_MISSING_PARAMETER', "Missing parameter 'host' or didn't resolve correctly";
|
|
}
|
|
|
|
$fnret = OVH::Bastion::Plugin::ACL::check(
|
|
user => $user,
|
|
userAny => $userAny,
|
|
port => $port,
|
|
portAny => $portAny,
|
|
scpUp => $scpUp,
|
|
scpDown => $scpDown,
|
|
sftp => $sftp
|
|
);
|
|
if (!$fnret) {
|
|
help();
|
|
osh_exit($fnret);
|
|
}
|
|
$user = $fnret->value->{'user'};
|
|
|
|
my @command = qw{ sudo -n -u allowkeeper -- /usr/bin/env perl -T };
|
|
push @command, $OVH::Bastion::BASEPATH . '/bin/helper/osh-accountModifyPersonalAccess';
|
|
push @command, '--target', 'self';
|
|
push @command, '--action', 'del';
|
|
push @command, '--account', $self;
|
|
push @command, '--ip', $ip;
|
|
push @command, '--user', $user if $user;
|
|
push @command, '--port', $port if $port;
|
|
|
|
osh_exit OVH::Bastion::helper(cmd => \@command);
|