定制 anandukrishnakk/laravel-azure-keyvault 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

anandukrishnakk/laravel-azure-keyvault

Composer 安装命令:

composer require anandukrishnakk/laravel-azure-keyvault

包简介

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

README 文档

README

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

  • 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

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

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

Configuration

Publish the configuration file:

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

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

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

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

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

The MIT License (MIT). Please see License File for more information.

anandukrishnakk/laravel-azure-keyvault 适用场景与选型建议

anandukrishnakk/laravel-azure-keyvault 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 anandukrishnakk/laravel-azure-keyvault 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 anandukrishnakk/laravel-azure-keyvault 我们能提供哪些服务?
定制开发 / 二次开发

基于 anandukrishnakk/laravel-azure-keyvault 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-04