Eaf.KeyVault 9.1.0

Prefix Reserved
dotnet add package Eaf.KeyVault --version 9.1.0
                    
NuGet\Install-Package Eaf.KeyVault -Version 9.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Eaf.KeyVault" Version="9.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Eaf.KeyVault" Version="9.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Eaf.KeyVault" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Eaf.KeyVault --version 9.1.0
                    
#r "nuget: Eaf.KeyVault, 9.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Eaf.KeyVault@9.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Eaf.KeyVault&version=9.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Eaf.KeyVault&version=9.1.0
                    
Install as a Cake Tool

Eaf.KeyVault

Descrição Técnica

O Eaf.KeyVault é um módulo de gerenciamento de segredos do Enterprise Application Foundation (EAF). Este módulo fornece integração com Azure Key Vault e Oracle Cloud Infrastructure (OCI) para armazenamento seguro de credenciais, chaves de API, strings de conexão e outros segredos sensíveis.

Este módulo abstrai a complexidade de acessar serviços de gerenciamento de segredos, fornecendo uma interface unificada que suporta múltiplos provedores de nuvem.

Relação com o EAF e ASP.NET Boilerplate

Integração com ABP

  • Abp: Framework base para injeção de dependência e configuração
  • Microsoft.Extensions.Hosting.Abstractions: Integração com hosting do ASP.NET Core

Dependências Externas

  • Azure.Identity: Autenticação com Azure AD
  • Azure.Security.KeyVault.Secrets: Cliente de Key Vault do Azure
  • Azure.Extensions.AspNetCore.Configuration.Secrets: Integração com configuração do ASP.NET Core
  • OCI.DotNetSDK.Identity: SDK de identidade da Oracle Cloud
  • OCI.DotNetSDK.Secrets: SDK de segredos da Oracle Cloud
  • Microsoft.IdentityModel.JsonWebTokens: Processamento de tokens JWT
  • System.IdentityModel.Tokens.Jwt: Validação de tokens JWT

Principais Componentes

IKeyVaultSecretManager

Interface principal para gerenciamento de segredos, fornecendo métodos para:

  • Recuperar segredos
  • Definir segredos
  • Remover segredos
  • Listar segredos
KeyVaultSecretManager

Implementação concreta que suporta:

  • Azure Key Vault
  • Oracle Cloud Infrastructure (OCI) Vault
  • Cache local de segredos para performance
  • Retries automáticos em falhas
Hosting

Integração com ASP.NET Core Hosting para:

  • Configuração automática no startup
  • Injeção de dependência
  • Configuração de logging

Guia de Instalação

Pré-requisitos

  • .NET 10.0 SDK ou superior
  • ASP.NET Boilerplate 10.4.0
  • Azure Key Vault ou OCI Vault configurado
  • Credenciais de acesso (Azure AD ou OCI)

Instalação via NuGet

dotnet add package Eaf.KeyVault --version 10.4.0

Instalação via Referência de Projeto

Adicione a referência ao seu arquivo .csproj:

<ProjectReference Include="..\Eaf.KeyVault\Eaf.KeyVault.csproj" />

Exemplo Básico de Uso

1. Registrando o Módulo

No seu módulo principal, herde de EafKeyVaultModule:

[DependsOn(
    typeof(EafKeyVaultModule),
    typeof(AbpModule)
)]
public class MyApplicationModule : AbpModule
{
    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
    }
}

2. Configurando Azure Key Vault

No appsettings.json:

{
  "KeyVault": {
    "Provider": "Azure",
    "Azure": {
      "VaultName": "my-vault-name",
      "TenantId": "your-tenant-id",
      "ClientId": "your-client-id",
      "ClientSecret": "your-client-secret"
    }
  }
}

3. Configurando OCI Vault

No appsettings.json:

{
  "KeyVault": {
    "Provider": "OCI",
    "OCI": {
      "VaultId": "ocid1.vault.oc1...",
      "Region": "us-ashburn-1",
      "TenancyId": "ocid1.tenancy.oc1...",
      "UserId": "ocid1.user.oc1...",
      "Fingerprint": "your-fingerprint",
      "PrivateKeyFilePath": "path/to/private_key.pem",
      "PrivateKeyPassphrase": "your-passphrase"
    }
  }
}

4. Usando o KeyVaultSecretManager

public class MyService : ApplicationService
{
    private readonly IKeyVaultSecretManager _keyVaultManager;

    public MyService(IKeyVaultSecretManager keyVaultManager)
    {
        _keyVaultManager = keyVaultManager;
    }

    public async Task<string> GetSecretAsync(string secretName)
    {
        var secret = await _keyVaultManager.GetSecretAsync(secretName);
        return secret.Value;
    }

    public async Task SetSecretAsync(string secretName, string secretValue)
    {
        await _keyVaultManager.SetSecretAsync(secretName, secretValue);
    }
}

5. Integrando com Configuration do ASP.NET Core

public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        // Adiciona KeyVault como fonte de configuração
        var keyVaultManager = services.BuildServiceProvider()
            .GetRequiredService<IKeyVaultSecretManager>();

        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.AddAzureKeyVault(keyVaultManager);
    }
}

Estrutura do Módulo

Eaf.KeyVault/
├── Hosting/               # Integração com ASP.NET Core Hosting
├── KeyVault/             # Implementações específicas do KeyVault
├── IKeyVaultSecretManager.cs  # Interface principal
├── KeyVaultSecretManager.cs   # Implementação concreta
└── EafKeyVaultModule.cs   # Módulo ABP

Configurações Opcionais

Cache de Segredos

public override void PreInitialize()
{
    Configuration.Modules.EafKeyVault().EnableCache = true;
    Configuration.Modules.EafKeyVault().CacheDuration = TimeSpan.FromMinutes(30);
}

Retries Automáticos

public override void PreInitialize()
{
    Configuration.Modules.EafKeyVault().EnableRetries = true;
    Configuration.Modules.EafKeyVault().MaxRetries = 3;
    Configuration.Modules.EafKeyVault().RetryDelay = TimeSpan.FromSeconds(2);
}

Testes

Os testes para este módulo estão localizados em:

test/Eaf.KeyVault.Tests/

Para executar os testes:

dotnet test test/Eaf.KeyVault.Tests/Eaf.KeyVault.Tests.csproj

Licença

Este projeto faz parte do Enterprise Application Foundation (EAF) e está licenciado sob os mesmos termos do projeto principal.

Suporte

Para issues e perguntas, consulte o repositório principal do EAF: https://github.com/afonsoft/EAF

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Eaf.KeyVault:

Package Downloads
Eaf.KeyVault.AspNetCore

Enterprise Application Foundation - KeyVault AspNetCore Azure or OCI

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.1.0 38 6/17/2026