forked from protonemedia/eddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve script to connect to custom servers
- Loading branch information
1 parent
e3d7341
commit c86d983
Showing
5 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Tasks; | ||
|
||
use App\Models\Server; | ||
|
||
class AuthorizeManagementRootKey extends Task | ||
{ | ||
protected int $timeout = 15; | ||
|
||
public function __construct(public Server $server) | ||
{ | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
resources/views/tasks/authorize-management-root-key.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<x-task-shell-defaults /> | ||
|
||
echo "Setup SSH keys for root" | ||
|
||
if [ ! -d /root/.ssh ] | ||
then | ||
mkdir -p /root/.ssh | ||
touch /root/.ssh/authorized_keys | ||
fi | ||
|
||
cat <<EOF >> /root/.ssh/authorized_keys | ||
|
||
{{ $server->public_key }} | ||
EOF | ||
|
||
echo "Fix root permissions" | ||
|
||
chown root:root /root | ||
chown -R root:root /root/.ssh | ||
chmod 700 /root/.ssh | ||
chmod 600 /root/.ssh/authorized_keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Tasks; | ||
|
||
use App\Models\Server; | ||
use App\Tasks\AuthorizeManagementRootKey; | ||
use Database\Factories\ServerFactory; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
|
||
class AuthorizeManagementRootKeyTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** @test */ | ||
public function it_authorizes_the_public_key() | ||
{ | ||
/** @var Server */ | ||
$server = ServerFactory::new()->create(); | ||
|
||
$this->assertMatchesBashSnapshot( | ||
(new AuthorizeManagementRootKey($server))->getScript() | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...it/Tasks/__snapshots__/AuthorizeManagementRootKeyTest__it_authorizes_the_public_key__1.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
set -eu | ||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
echo "Setup SSH keys for root" | ||
|
||
if [ ! -d /root/.ssh ] | ||
then | ||
mkdir -p /root/.ssh | ||
touch /root/.ssh/authorized_keys | ||
fi | ||
|
||
cat <<EOF >> /root/.ssh/authorized_keys | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAb5M7vlstlBOPx6NocXAewxzfxX8AujDifR0lrQf+On [email protected] | ||
EOF | ||
|
||
echo "Fix root permissions" | ||
|
||
chown root:root /root | ||
chown -R root:root /root/.ssh | ||
chmod 700 /root/.ssh | ||
chmod 600 /root/.ssh/authorized_keys |