Skip to content

Commit e3b4766

Browse files
authored
feat: use JWT bundle's command to create keys (#234)
The idea was proposed in api-platform/docs#1446 and added to the docs in api-platform/docs#1448. The command was added to the bundle in v2.11. Composer install was moved first to ensure that the bundle is installed. This now attempts the permission modification (`setfacl`) irrespective of the previous existence of the key files. While the cost of this operation are certainly not zero, it ensures the permissions are as intended no matter how the key files came to be and leaves the configuration of the key file name entirely with the bundle/.env file.
1 parent b75b5ba commit e3b4766

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

api/docker/php/docker-entrypoint.sh

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
1818
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
1919

2020
if [ "$APP_ENV" != 'prod' ]; then
21-
if [ ! -f config/jwt/private.pem ]; then
22-
jwt_passphrase=$(grep '^JWT_PASSPHRASE=' .env | cut -f 2 -d '=')
23-
if ! echo "$jwt_passphrase" | openssl pkey -in config/jwt/private.pem -passin stdin -noout > /dev/null 2>&1; then
24-
echo "Generating public / private keys for JWT"
25-
mkdir -p config/jwt
26-
echo "$jwt_passphrase" | openssl genpkey -out config/jwt/private.pem -pass stdin -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096
27-
echo "$jwt_passphrase" | openssl pkey -in config/jwt/private.pem -passin stdin -out config/jwt/public.pem -pubout
28-
setfacl -R -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
29-
setfacl -dR -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
30-
fi
31-
fi
32-
3321
composer install --prefer-dist --no-progress --no-interaction
22+
23+
echo "Making sure public / private keys for JWT exist..."
24+
php bin/console lexik:jwt:generate-keypair --skip-if-exists --no-interaction
25+
setfacl -R -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
26+
setfacl -dR -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
3427
fi
3528

3629
if grep -q DATABASE_URL= .env; then

0 commit comments

Comments
 (0)