Skip to content

Commit c755042

Browse files
author
laughing_man77
committed
Refs #210 - Fix failure of JWT key generation in prod docker.
1 parent bade5d2 commit c755042

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,8 @@ ApiOpenStudio 1.0.0-beta3
199199
- Fixes on testing_app OpenAPI schema.
200200
- Update User DB classes for nullable values.
201201
- Fix setting permissions on JWT keys sometimes happening before the file has been created.
202+
203+
ApiOpenStudio 1.0.0-beta4
204+
=========================
205+
206+
- Fix the `bin/aos-install` script occasionally failing on JWT creation.

includes/Cli/Install.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -708,39 +708,46 @@ public function createAdminUser(string $username = '', string $password = '', st
708708
public function generateJwtKeys($generateKeys = null)
709709
{
710710
$config = new Config();
711-
echo "You will need the public/private keys for users to login and validate.\n";
711+
echo "You will need the public/private keys for users to login.\n";
712712
echo "These can be automatically generated for you, or you can manually copy them in yourself\n\n";
713713

714714
$private_key_path = $public_key_path = '';
715715
try {
716716
$private_key_path = $config->__get(['api', 'jwt_private_key']);
717717
$public_key_path = $config->__get(['api', 'jwt_public_key']);
718-
echo "Private JWT key path: $private_key_path\n";
719-
echo "Public JWT key path: $public_key_path\n\n";
720718
} catch (ApiException $e) {
721719
$this->handleException($e);
722720
}
723721

724722
while (!is_bool($generateKeys)) {
725723
$prompt = "Automatically generate public/private keys for JWT ";
726-
$prompt .= "(WARNING, this will overwrite any existing keys at ";
724+
$prompt .= "(WARNING: this will overwrite any existing keys at ";
727725
$prompt .= "the location defined in settings.yml) [Y/n]: ";
728726
$generateKeys = strtolower($this->readlineTerminal($prompt));
729727
$generateKeys = $generateKeys === 'y' || $generateKeys === '' ? true : $generateKeys;
730728
$generateKeys = $generateKeys === 'n' ? false : $generateKeys;
731729
}
732730

733731
if ($generateKeys) {
734-
echo "Generating keys...\n";
735-
$cmd = "rm $private_key_path $public_key_path";
736-
shell_exec($cmd);
737-
$cmd = "echo -e 'y\\n' | ssh-keygen -t rsa -b 4096 -P '' -m PEM -f $private_key_path >/dev/null & sleep 2";
732+
if (file_exists($private_key_path)) {
733+
echo "Removing existing private key at $private_key_path\n";
734+
$cmd = "rm $private_key_path";
735+
shell_exec($cmd);
736+
}
737+
if (file_exists($public_key_path)) {
738+
echo "Removing existing public key at $public_key_path\n";
739+
$cmd = "rm $public_key_path";
740+
shell_exec($cmd);
741+
}
742+
echo "Generating new private key...\n";
743+
$cmd = "echo -e 'y\\n' | ssh-keygen -t rsa -b 4096 -P '' -m PEM -f $private_key_path >/dev/null; sleep 1";
738744
shell_exec($cmd);
739-
$cmd = "echo -e 'y\\n' | openssl rsa -in $private_key_path -pubout -outform PEM -out $public_key_path";
740-
$cmd .= " & sleep 2";
745+
echo "Generating new public key...\n";
746+
$cmd = "echo -e 'y\\n' | openssl rsa -in $private_key_path -pubout -outform PEM -out $public_key_path; ";
747+
$cmd .= "sleep 1";
741748
shell_exec($cmd);
742749
shell_exec("chmod 600 $private_key_path $public_key_path");
743-
echo "keys generated\n";
750+
echo "Keys generated at:\n* $private_key_path\n* $public_key_path\n";
744751
}
745752
}
746753
}

0 commit comments

Comments
 (0)