provision script fixes, flash the server creds to the user on server create

This commit is contained in:
2025-03-30 12:37:34 +00:00
parent 435a7ac1e3
commit 5ba1ac9c92
5 changed files with 21 additions and 1 deletions

View File

@@ -94,6 +94,10 @@ class ServerController extends Controller
sudoPassword: $sudoPassword, sudoPassword: $sudoPassword,
))->delay(now()->addSeconds(30)); ))->delay(now()->addSeconds(30));
session()->flash('server-credentials', [
'sudo_password' => $sudoPassword,
]);
return redirect()->route('servers.show', ['organisation' => $organisation->id, 'server' => $server->id]); return redirect()->route('servers.show', ['organisation' => $organisation->id, 'server' => $server->id]);
} }

View File

@@ -31,6 +31,11 @@ class HandleInertiaRequests extends Middleware
'name' => config('app.name'), 'name' => config('app.name'),
'organisation' => $request->route('organisation') ? Organisation::with('applications')->findOrFail($request->route('organisation')) : null, 'organisation' => $request->route('organisation') ? Organisation::with('applications')->findOrFail($request->route('organisation')) : null,
'application' => $request->route('application') ? Application::with('environments')->findOrFail($request->route('application')) : null, 'application' => $request->route('application') ? Application::with('environments')->findOrFail($request->route('application')) : null,
'flash' => [
'server_credentials' => $request->session()->has('sudo_password') ? [
'sudo_password' => $request->session()->get('sudo_password'),
] : null,
],
'auth' => [ 'auth' => [
'user' => $request->user()?->load('organisations'), 'user' => $request->user()?->load('organisations'),
], ],

View File

@@ -2,6 +2,7 @@
# [!hostname!] - server hostname # [!hostname!] - server hostname
# [!sudo_password!] - the sudo password to set # [!sudo_password!] - the sudo password to set
# [!server_id!] - the servers id # [!server_id!] - the servers id
# [!keystonepublickey!] - keystone's public key
apt_wait() { apt_wait() {
while fuser /var/lib/dpkg/lock >/dev/null 2>&1; do while fuser /var/lib/dpkg/lock >/dev/null 2>&1; do
@@ -74,7 +75,7 @@ usermod --password $PASSWORD keystone
# Build Formatted Keys & Copy Keys To Keystone # Build Formatted Keys & Copy Keys To Keystone
cat >/root/.ssh/authorized_keys <<EOF cat >/root/.ssh/authorized_keys <<EOF
# Keystone # Keystone
@TODO INJECT KEY HERE [!keystonepublickey!]
EOF EOF
cp /root/.ssh/authorized_keys /home/keystone/.ssh/authorized_keys cp /root/.ssh/authorized_keys /home/keystone/.ssh/authorized_keys

View File

@@ -18,6 +18,13 @@ const props = defineProps({
<AppLayout> <AppLayout>
<div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4"> <div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4">
{{ server }} {{ server }}
<div v-if="$page.props.flash?.server_credentials" class="p-5">
<div class="mb-4 text-sm font-medium text-gray-900 dark:text-white">
WILL NOT BE SHOWN AGAIN:
{{ $page.props.flash.server_credentials }}
</div>
</div>
</div> </div>
</AppLayout> </AppLayout>
</template> </template>

View File

@@ -46,9 +46,12 @@ Route::get('/provision-script', function (Request $request) {
$script = file_get_contents(base_path('provision.sh')); $script = file_get_contents(base_path('provision.sh'));
$keystonePublicKey = file_get_contents(storage_path('app/private/ssh/id_ed25519.pub'));
$script = str_replace('[!hostname!]', $validated['hostname'], $script); $script = str_replace('[!hostname!]', $validated['hostname'], $script);
$script = str_replace('[!sudo_password!]', $validated['sudo_password'], $script); $script = str_replace('[!sudo_password!]', $validated['sudo_password'], $script);
$script = str_replace('[!server_id!]', $validated['server_id'], $script); $script = str_replace('[!server_id!]', $validated['server_id'], $script);
$script = str_replace('[!keystonepublickey!]', $keystonePublicKey, $script);
return response($script) return response($script)
->header('Content-Type', 'text/plain'); ->header('Content-Type', 'text/plain');