mirror of
https://github.com/ovh/the-bastion.git
synced 2025-01-08 00:12:10 +08:00
107 lines
3.8 KiB
Perl
Executable file
107 lines
3.8 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::groupSetRole;
|
|
use OVH::Bastion::Plugin::ACL;
|
|
|
|
my $remainingOptions = OVH::Bastion::Plugin::begin(
|
|
argv => \@ARGV,
|
|
header => "add access to one server of a group to an account",
|
|
options => {
|
|
"group=s" => \my $group,
|
|
"account=s" => \my $account,
|
|
"user-any" => \my $userAny,
|
|
"port-any" => \my $portAny,
|
|
"scpup" => \my $scpUp,
|
|
"scpdown" => \my $scpDown,
|
|
"sftp" => \my $sftp,
|
|
"ttl=s" => \my $ttl,
|
|
"comment=s" => \my $comment,
|
|
},
|
|
helptext => <<'EOF',
|
|
Add a specific group server access to an account
|
|
|
|
Usage: --osh SCRIPT_NAME --group GROUP --account ACCOUNT [OPTIONS]
|
|
|
|
--group GROUP group to add guest access to
|
|
--account ACCOUNT name of the other bastion account to add access to, they'll be given access to the GROUP key
|
|
--host HOST|IP add access to this HOST (which must belong to the GROUP)
|
|
--user USER allow connecting to HOST only with remote login USER
|
|
--user-any allow connecting to HOST with any remote login
|
|
--port PORT allow connecting to HOST only to remote port PORT
|
|
--port-any allow connecting to HOST with any remote port
|
|
--scpup allow SCP upload, you--bastion-->server (omit --user in this case)
|
|
--scpdown allow SCP download, you<--bastion--server (omit --user in this case)
|
|
--sftp allow usage of the SFTP subsystem, you<--bastion-->server (omit --user in this case)
|
|
--ttl SECONDS|DURATION specify a number of seconds after which the access will automatically expire
|
|
--comment '"ANY TEXT"' add a comment alongside this access.
|
|
If omitted, we'll use the closest preexisting group access' comment as seen in groupListServers
|
|
|
|
This command adds, to an existing bastion account, access to the egress keys of a group,
|
|
but only to accessing one or several given servers, instead of all the servers of this group.
|
|
|
|
If you want to add complete access to an account to all the present and future servers
|
|
of the group, using the group key, please use ``groupAddMember`` instead.
|
|
|
|
If you want to add access to an account to a group server but using his personal bastion
|
|
key instead of the group key, please use ``accountAddPersonalAccess`` instead (his public key
|
|
must be on the remote server).
|
|
|
|
This command is the opposite of ``groupDelGuestAccess``.
|
|
EOF
|
|
);
|
|
|
|
my $fnret;
|
|
|
|
if (not $ip and $host) {
|
|
osh_exit 'ERR_INVALID_HOST',
|
|
"Specified host ($host) didn't resolve correctly, fix your DNS or specify the IP instead";
|
|
}
|
|
|
|
$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'};
|
|
|
|
if (defined $ttl) {
|
|
$fnret = OVH::Bastion::is_valid_ttl(ttl => $ttl);
|
|
$fnret or osh_exit $fnret;
|
|
$ttl = $fnret->value->{'seconds'};
|
|
}
|
|
|
|
$fnret = OVH::Bastion::Plugin::groupSetRole::act(
|
|
account => $account,
|
|
group => $group,
|
|
action => 'add',
|
|
type => 'guest',
|
|
user => $user,
|
|
userAny => $userAny,
|
|
port => $port,
|
|
portAny => $portAny,
|
|
host => ($ip || $host),
|
|
ttl => $ttl,
|
|
comment => $comment,
|
|
sudo => 0,
|
|
silentoverride => 0,
|
|
self => $self,
|
|
scriptName => $scriptName,
|
|
savedArgs => $savedArgs
|
|
);
|
|
help() if not $fnret;
|
|
osh_exit($fnret);
|