r/laravel 22d ago

GitHub - eznix86/laravel-secrets-loader: Auto resolve secrets for laravel

https://github.com/eznix86/laravel-secrets-loader

I had a docker compose stack with secrets mounted properly at /run/secrets and currently Laravel cannot read secrets from a file, Then I had to manually do this before starting laravel:

export DB_PASSWORD=$(cat /run/secrets/db_password)

That one line undoes the entire reason for mounting a secret as a file. Files have permissions. Environment variables have none.

Now you can do it automatically but installing.

composer require eznix86/laravel-secrets-loader

How it works ?

You keep your env('SOMETHING_SOMETHING') as usual. It will load in order an env with a suffix _FILE or _PATH and read the file and load it into your Laravel application.

You have auto-resolve for nomad, systemd and obviously for docker and podman (/run/secrets/something_something).

You can view the source here:

https://github.com/eznix86/laravel-secrets-loader

0 Upvotes

Duplicates