diff --git a/bin/plugin/group-aclkeeper/groupAddServer b/bin/plugin/group-aclkeeper/groupAddServer index 6e435f6..65bf8c6 100755 --- a/bin/plugin/group-aclkeeper/groupAddServer +++ b/bin/plugin/group-aclkeeper/groupAddServer @@ -130,6 +130,12 @@ else { osh_info "Forcing add as asked, we didn't test the SSH connection, maybe it won't work!"; } +# if no comment is specified, but we're adding the server by hostname, +# use it to craft a comment +if (!$comment && $host ne $ip) { + $comment = "hostname=$host"; +} + my @command = qw{ sudo -n -u }; push @command, ($group, '--', '/usr/bin/env', 'perl', '-T', $OVH::Bastion::BASEPATH . '/bin/helper/osh-groupAddServer'); push @command, '--group', $group; diff --git a/bin/plugin/restricted/selfAddPersonalAccess b/bin/plugin/restricted/selfAddPersonalAccess index 9d41ad5..89a28e6 100755 --- a/bin/plugin/restricted/selfAddPersonalAccess +++ b/bin/plugin/restricted/selfAddPersonalAccess @@ -111,6 +111,12 @@ else { osh_info "Forcing add as asked, we didn't test the SSH connection, maybe it won't work!"; } +# if no comment is specified, but we're adding the server by hostname, +# use it to craft a comment +if (!$comment && $host ne $ip) { + $comment = "hostname=$host"; +} + 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'; diff --git a/tests/functional/tests.d/340-selfaccesses.sh b/tests/functional/tests.d/340-selfaccesses.sh index c0bea9c..384ee0a 100644 --- a/tests/functional/tests.d/340-selfaccesses.sh +++ b/tests/functional/tests.d/340-selfaccesses.sh @@ -129,6 +129,11 @@ testsuite_selfaccesses() contain "Access denied for" json .command null .value null .error_code KO_ACCESS_DENIED + # auto hostname=$host comment + + success selfAddPersonalAccess self_add_personal_access_auto_comment $a0 --osh selfAddPersonalAccess --host localhost -u autocomment -p 1234 --force --ttl 1 + json .command selfAddPersonalAccess .error_code OK .value.comment "hostname=localhost" .value.user autocomment .value.port 1234 .value.ttl 1 + # forcekey success selfListIngressKeys for_force_key $a0 --osh selfListEgressKeys