Skip to content

Commit 43eb040

Browse files
authored
feat: use JWT bundle's command to create keys
Creation of directory and files is now covered by lexik/jwt-authentication-bundle's command. This somewhat causes the directory/file location somewhat pop up out of nowhere in the subsequent permission change (`setfacl`). That could be avoided by extracting JWT_SECRET_KEY and JWT_PUBLIC_KEY from api's `.env` file (section maintained by the bundle) but it adds bloat without apparent benefit. The previously documented behaviour was closer to using the `--overwrite` option on the command, but I doubt it is in the user's best interest in a starter guide. Using `--skip-if-exists` would make some sense, but bailing feels like the sane option – the user obviously touched this area before and should be made aware. Resolves #1446
1 parent 29bffd0 commit 43eb040

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

core/jwt.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ Then we need to generate the public and private keys used for signing JWT tokens
2424
docker-compose exec php sh -c '
2525
set -e
2626
apk add openssl
27-
mkdir -p config/jwt
28-
jwt_passphrase=${JWT_PASSPHRASE:-$(grep ''^JWT_PASSPHRASE='' .env | cut -f 2 -d ''='')}
29-
echo "$jwt_passphrase" | openssl genpkey -out config/jwt/private.pem -pass stdin -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096
30-
echo "$jwt_passphrase" | openssl pkey -in config/jwt/private.pem -passin stdin -out config/jwt/public.pem -pubout
27+
php bin/console lexik:jwt:generate-keypair
3128
setfacl -R -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
3229
setfacl -dR -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
3330
'
3431
```
3532

3633
Note that the `setfacl` command relies on the `acl` package. This is installed by default when using the API Platform docker distribution but may need be installed in your working environment in order to execute the `setfacl` command.
3734

38-
This takes care of using the correct passphrase to encrypt the private key, and setting the correct permissions on the
35+
This takes care of keypair creation (incl. using the correct passphrase to encrypt the private key), and setting the correct permissions on the
3936
keys allowing the web server to read them.
4037

4138
Since these keys are created by the `root` user from a container, your host user will not be able to read them during the `docker-compose build caddy` process. Add the `config/jwt/` folder to the `api/.dockerignore` file so that they are skipped from the result image.

0 commit comments

Comments
 (0)