damienfern/vault-symfony-bundle
.env files, config files) by integrating HashiCorp Vault as a centralized secrets provider. This reduces hardcoded credentials in codebases and enables dynamic secrets injection.register() in a service provider)..env files can be dynamically populated from Vault at runtime (e.g., via bootstrap/app.php or a custom bootloader).HttpClient and DependencyInjection may require wrappers for Laravel’s Illuminate\Http and ServiceProvider.HttpClient facade or a lightweight adapter (e.g., symfony/http-client as a Composer dependency).Cache::forget() on secret updates) or use Vault’s native lease durations.403 Forbidden).try-catch with custom logging..env variables, or only specific ones (e.g., DB_PASSWORD)? Partial integration may require conditional logic..env fallback or fail gracefully?symfony/http-client or a custom adapter.ServiceProvider can bind the bundle’s services (e.g., VaultClient) to Laravel’s container.config/vault.php to mirror the Symfony bundle’s YAML structure.spatie/laravel-vault or laravel/vault for feature parity (e.g., dynamic config, caching).HttpClient to fetch secrets directly.Phase 1: Proof of Concept
.env via a custom bootloader (e.g., bootstrap/app.php):
$vaultClient = new \DamienFern\VaultBundle\Client\VaultClient($config);
$secrets = $vaultClient->getSecrets('myapp/config');
putenv('DB_PASSWORD=' . $secrets['password']);
config('database.connections.mysql.password').Phase 2: Service Provider Integration
VaultServiceProvider to register the bundle’s services:
public function register()
{
$this->app->singleton(VaultClient::class, function ($app) {
return new VaultClient($app['config']['vault']);
});
}
Phase 3: Dynamic Configuration
.env values with Vault-fetched ones in config/app.php or service bindings:
'database' => [
'connections' => [
'mysql' => [
'password' => fn() => app(VaultClient::class)->getSecret('DB_PASSWORD'),
],
],
]
Cache facade can be used as a drop-in replacement.myapp/config).composer.json and publish the config:
composer require damienfern/vault-symfony-bundle
php artisan vendor:publish --provider="DamienFern\VaultBundle\VaultBundle"
config/vault.php with Vault credentials.VaultServiceProvider.Log facade).Log::debug() to log Vault API responses and errors..env fallback for development or during Vault outages:
$password = app(VaultClient::class)->getSecret('DB_PASSWORD') ?? env('DB_PASSWORD');
Notifiable interface if Vault is unreachable.Cache::remember() for secrets).dev, staging, and production (configured via Laravel’s config('vault.path')).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Vault server unavailable | App crashes if no fallback | Local .env fallback + health checks |
| Expired Vault token | Secrets fetch fails | Automated token rotation (e.g., cron job) |
| Misconfigured Vault path | Wrong secrets injected | Validation in config/vault.php |
| Network partition | Secrets time out | Retry logic with exponential backoff |
| Vault API rate limiting | Throttled requests | Cache secrets aggressively |
vault kv put, AppRole auth) and Laravel’s integration points.VaultException).vault login) into the team’s workflow for local development.telescope to monitor Vault API calls in production.How can I help you explore Laravel packages today?