PHPackages                             anandukrishnakk/laravel-azure-keyvault - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. anandukrishnakk/laravel-azure-keyvault

ActiveLibrary

anandukrishnakk/laravel-azure-keyvault
======================================

Azure Key Vault integration for Laravel 12 using Managed Identity or Service Principal.

10PHP

Since Jan 17Pushed 2mo agoCompare

[ Source](https://github.com/anandukrishnakk/laravel-azure-keyvault)[ Packagist](https://packagist.org/packages/anandukrishnakk/laravel-azure-keyvault)[ RSS](/packages/anandukrishnakk-laravel-azure-keyvault/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Azure Key Vault
=======================

[](#laravel-azure-key-vault)

Azure Key Vault integration for Laravel 12, supporting Managed Identity and Service Principal authentication. This package automatically fetches database credentials from Key Vault and injects them into your configuration at runtime.

Features
--------

[](#features)

- **Automatic DB Credentials**: Injects `DB_USERNAME` and `DB_PASSWORD` from Key Vault into `config('database.connections.pgsql')`.
- **Managed Identity Support**: Zero-config authentication when running on Azure App Service or Virtual Machines.
- **Service Principal Support**: Fallback to Client ID/Secret for local development or non-Azure environments.
- **Support for Azure PostgreSQL Managed Identity**: Can automatically fetch an AAD token for database authentication if `DB_PASSWORD` is set to `MANAGED_IDENTITY`.
- **Token Caching**: Efficiently caches Azure access tokens in the filesystem to avoid repeated OAuth calls.
- **Test Command**: Built-in CLI tool to verify connectivity.

Installation
------------

[](#installation)

### 1. Add Local Repository (Optional)

[](#1-add-local-repository-optional)

If you are developing this package locally, add the following to your main project's `composer.json`:

```
"repositories": [
    {
        "type": "path",
        "url": "packages/anandukrishnakk/laravel-azure-keyvault"
    }
],
```

### 2. Install via Composer

[](#2-install-via-composer)

```
composer require anandukrishnakk/laravel-azure-keyvault:@dev
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=config --provider="AnanduKrishna\AzureKeyVault\AzureKeyVaultServiceProvider"
```

### Environment Variables

[](#environment-variables)

Add these to your `.env` file:

```
# Vault Details
AZURE_KEY_VAULT_URL=https://your-vault.vault.azure.net

# Secret Names in Key Vault
DB_USERNAME_SECRET=pg-username
DB_PASSWORD_SECRET=pg-password

# Optional: Service Principal (for local development)
AZURE_TENANT_ID=your-tenant-id
AZURE_CLIENT_ID=your-client-id
AZURE_CLIENT_SECRET=your-client-secret

# Optional: Managed Identity Client ID (if using Multiple Identities)
AZURE_MANAGED_IDENTITY_CLIENT_ID=your-identity-client-id

# CLI Settings
AZURE_KV_CLI_ENABLED=false
AZURE_KV_AUTO_RECONNECT=true
```

Usage
-----

[](#usage)

### Automatic Configuration

[](#automatic-configuration)

The package automatically runs during the `register` phase. It will:

1. Fetch the secret named in `DB_USERNAME_SECRET` and set it as `database.connections.pgsql.username`.
2. Fetch the secret named in `DB_PASSWORD_SECRET` and set it as `database.connections.pgsql.password`.
3. If `config('database.connections.pgsql.password')` is exactly `MANAGED_IDENTITY`, it will instead fetch an Azure Active Directory token for the PostgreSQL resource.

### Using for Other Databases or Services

[](#using-for-other-databases-or-services)

If you need to fetch secrets for multiple database connections or other services (like Redis, Mail, etc.), you can use the `AzureKeyVault` facade in your `AppServiceProvider.php`:

```
use AnanduKrishna\AzureKeyVault\Facades\AzureKeyVault;

public function boot(): void
{
    // Fetch and set custom database credentials
    if ($mysqlPass = AzureKeyVault::get('mysql-production-password')) {
        config(['database.connections.mysql.password' => $mysqlPass]);
    }

    // Fetch and set third-party API keys
    if ($stripeKey = AzureKeyVault::get('stripe-secret-key')) {
        config(['services.stripe.secret' => $stripeKey]);
    }
}
```

Advanced Database Configuration
-------------------------------

[](#advanced-database-configuration)

Use the built-in command to verify that your app can talk to the Vault:

```
php artisan azure:test-kv
```

You can also specify a specific secret name to fetch:

```
php artisan azure:test-kv my-custom-secret
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 11% of packages

Maintenance56

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/42e109b54ed72ea5cf22bbadefa1b8d686eaa6b0cbbd1144b7142721ea6e750b?d=identicon)[ananduk6](/maintainers/ananduk6)

---

Top Contributors

[![anandukrishnakk](https://avatars.githubusercontent.com/u/14835378?v=4)](https://github.com/anandukrishnakk "anandukrishnakk (2 commits)")

### Embed Badge

![Health badge](/badges/anandukrishnakk-laravel-azure-keyvault/health.svg)

```
[![Health](https://phpackages.com/badges/anandukrishnakk-laravel-azure-keyvault/health.svg)](https://phpackages.com/packages/anandukrishnakk-laravel-azure-keyvault)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
