umar-jimoh / laravel-secretsync
Sync secrets from secret managers into your Laravel app with ease.
Requires
- php: ^8.2
Requires (Dev)
- laravel/pint: ^1.22
- orchestra/testbench: ^10.2
- pestphp/pest: ^3.8
README
Introduction
This package allows you to easily sync secrets from secret managers into your Laravel app. Currently, only Infisical is supported.
Once installed you can do stuff like this:
php artisan secretsync
๐ฆ Installation
You can install the package via composer:
composer require umar-jimoh/laravel-secretsync
Publish Config:
php artisan vendor:publish --provider="UmarJimoh\SecretSync\SecretSyncServiceProvider" --tag=config
๐งช Usage
Before syncing secrets, ensure you've properly set up your secret manager (e.g., Infisical) and provided the necessary credentials or identifiers in your .env file.
SECRETSYNC_PROVIDER="infisical"
INFISICAL_API_ENDPOINT=
INFISICAL_TOKEN=
INFISICAL_ENV=
INFISICAL_WORK_ID=
๐ APP_KEY Requirement
This package requires APP_KEY
to be set in the .env
file before the application boots.
It uses Laravelโs encryption system to decrypt cached secrets. Without APP_KEY
, the package will not work.
Ensure APP_KEY
is set locally in .env
:
APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
NOTE: Do not include or fetch
APP_KEY
from your secret manager. It must be defined only in the.env
file to avoid conflicts and ensure proper Laravel encryption.
Once the package is installed, you can sync secrets by running:
php artisan secretsync
This command fetches and applies secrets from your configured provider into your Laravel application.
You can enable caching so that secrets are stored and retrieved locally instead of fetching them from the provider every time. To enable this, configure the following in your .env file:
SECRETSYNC_CACHE=true SECRETSYNC_CACHE_TTL=300 # (in seconds) SECRETSYNC_CACHE_DRIVER= # (optional, defaults to Laravel's default cache driver)
Secrets are securely encrypted using Laravel's cache driver.
You may also define these values in config/secretsync.php
.
If you encounter issues during sync, use the --debug
flag for more detailed error messages:
php artisan secretsync --debug
Alternatively, enable debugging via .env:
SECRETSYNC_DEBUG=true
NOTE: In production if you run
php artisan optimize
make sure you runphp artisan secretsync
afterward to ensure secrets are properly synced.
๐ค Contributing
Feel free to open issues or pull requests to improve the package. I welcome contributions that help make this package better!
๐ง Contact
If you have any questions, feel free to reach out to me at umarjimoh@hotmail.com or via Twitter.
๐ License
This package is open-source software licensed under the . MIT License.