thetribeofdan / laravel_vault
A Laravel package that helps you easily integrate and manage secrets from HashiCorp Vault, with caching and env/config-style access.
Fund package maintenance!
thetribephotography
flutterwave.com/donate/43xu0cajjq1f
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
README
Easily integrate HashiCorp Vault secrets into your Laravel project with zero friction. This package allows you to manage secrets via Vault while maintaining Laravel's native config('...')
access style โ just like you would with .env
files.
What is HashiCorp Vault?
HashiCorp Vault is a tool for securely storing and accessing tokens, passwords, certificates, encryption keys, and other sensitive data. Kindly see More Here: https://github.com/hashicorp/vault-guides
๐ Why Use This Package?
Managing secrets in Laravel shouldn't require rewriting your entire application just to integrate with HashiCorp Vault. This package was built to solve one simple but powerful problem:
โ Seamlessly upgrade from
.env
-based config to Vault-based secret management โ without touching how your app reads secrets.
If you're using Laravelโs config('app.secret_key')
or similar patterns, this package lets you continue doing that while the underlying secrets are pulled from Vault securely.
๐ What Makes This Package Different?
๐งฉ 1. Plug-and-Play with Laravelโs Config System
You don't need to rewrite your codebase. Just map your Vault keys to Laravel config keys, and call them as you always have:
config('app.my_api_key')
โ๏ธ 2. Two Powerful Modes of Integration
Mode | Description |
---|---|
File Mode | Read secrets from one or more Vault-agent-generated files (supporting .env , .txt , .json , and more) โ perfect for agent setups or Docker environments. |
Token Mode | Pull secrets directly from the Vault server using a token, supporting multiple paths and tokens. Great for dynamic secret retrieval. |
๐ง 3. Configurable, Flexible, and Cache-Aware
- Supports multiple file paths or multiple Vault token sources
- Maps secrets to Laravel config effortlessly
- Uses Laravel's cache system to improve performance
๐ช 4. Transition-First Design
Unlike other packages that require rigid integration styles or special syntax, this one was designed with real-world Laravel projects in mind โ allowing teams to migrate without friction, allowing keys to be called using the default Laravel config() mechanism.
๐ฆ Installation
composer require thetribeofdan/laravel_vault
If you want to publish the config file:
php artisan vendor:publish --tag=vault-config
You'll now see a config/vault.php
file. This is your main control centre ๐ง
๐ ๏ธ Configuration
1. Choose your mode
Set the mode in .env
or directly in config/vault.php
:
VAULT_MODE=file # or 'token'
2. File Mode (๐ Local Files)
Use this when you want to load secrets from one or more files generated by the Vault Agent or by yourself on your Server (e.g. .env
, .json
):
'file_paths' => [ base_path('.vault/secrets.env'), base_path('.vault/extra.json'), ],
โ Supported formats:
.env
-style:KEY=value
.json
-style:{ "KEY": "value" }
3. Token Mode (๐ Live HashiCorp Vault)
Use this when you want to connect to a live Vault instance using the Auth token:
'token_sources' => [ [ 'token' => env('VAULT_TOKEN'), 'path' => '/v1/secret/data/app', 'url' => env('VAULT_URL'), ], [ 'token' => env('VAULT_ALT_TOKEN'), 'path' => '/v1/secret/data/billing', 'url' => env('VAULT_URL'), ], ],
๐ Supports multiple tokens, engine paths and URLs.
4. Mapping Secrets to Config ๐บ๏ธ
Map secrets from your files or Vault into Laravel config using the map
array in your config/vault.php
file:
'app.app_key' => 'APP_KEY', 'app.mailgun.secret' => 'MAILGUN_SECRET',
Usage in your Projectโs code:
config('app.app_key'); config('app.mailgun.secret');
๐ Refreshing Secrets at Runtime
Need to reload your secrets on the fly (e.g. after token rotation or file update)? Just call:
Vault::refresh();
To force a reload and cache refresh of Vault secrets.
โ ๏ธ Laravel Cache Warning
If you're using database
cache driver, make sure to run the default cache migration:
php artisan cache:table php artisan migrate
Or switch to file
or redis
temporarily.
๐ก Tips
- Make sure you run Laravel's
php artisan cache:table
& migrate if using database cache - All secrets are cached for 1 hour by default (configurable)
- This package is best used for secure, centralized secrets
Tutorials/Video Walkthrough
- Installation and Configuration https://youtu.be/7ofXmhYIKmM?si=1D7Ad5QiQ5FcGOnX
๐ Credits
Built with ๐ค by Daniel Fiyinfoluwa Egbeleke aka The Bad Guyโข. Inspired by a personal need to make secure secret integration feel effortless for my Future Projects...Hope You Like It ๐
๐ Support the Project
If this package saved you hours or helped secure your Laravel app, consider sponsoring the project:
๐ Donate via Flutterwave
๐ซถ Every contribution goes towards maintaining, improving, and supporting this tool for the community.
Massive Help by @imambash6
๐ License
MIT ยฉ 2025 Daniel Fiyinfoluwa Egbeleke