Skip to content

This project provides a minimal ASP.NET Core web API for retrieving configuration secrets from HashiCorp Vault using VaultSharp. It is designed as a foundational microservice for configuration management within a microservices architecture.

Notifications You must be signed in to change notification settings

felixojiambo/ConfigService

Repository files navigation

ConfigService

About

ConfigService is a minimal ASP.NET Core web API designed to retrieve configuration secrets from HashiCorp Vault using VaultSharp. It serves as a foundational microservice for managing configuration secrets in a microservices architecture.

Table of Contents


Prerequisites

Before setting up the project, ensure the following are installed:

  1. .NET SDK 8.0 or later
    Download and install the .NET SDK from the official .NET Download Page.

  2. HashiCorp Vault

    • Install HashiCorp Vault locally: Vault Installation Guide.
    • Start a development server (for testing):
      vault server -dev
  3. VaultSharp Package
    The project uses the VaultSharp NuGet package to communicate with HashiCorp Vault.


Installation

  1. Clone the Repository:

    git clone <repository-url>
    cd ConfigService
  2. Restore Dependencies:

    Run the following command to restore all required dependencies:

    dotnet restore
  3. Build the Project:

    Build the project using:

    dotnet build

Configuration

The application retrieves configuration secrets from HashiCorp Vault. Ensure the following settings are properly configured:

  • Vault Address:
    Default: http://127.0.0.1:8200
    Override by setting the environment variable: Vault:Address.

  • Vault Token:
    Default: myroot
    Override by setting the environment variable: Vault:Token.

Note: For production, sensitive information like Vault tokens should be managed securely through environment variables, Azure Key Vault, or Kubernetes secrets.


Implementation Details

Key features of the ConfigService:

  1. VaultSharp Integration:
    The service integrates with VaultSharp to interact with the HashiCorp Vault API. It uses the Key/Value v2 secrets engine to retrieve secrets.

  2. Minimal API Design:
    ConfigService uses the ASP.NET Core minimal API framework for simplicity and lightweight performance.

  3. Error Handling:
    The service includes error handling for scenarios like invalid secret paths or Vault connectivity issues. It ensures clear error messages are returned to users.

For more details on the implementation, refer to the Program.cs file in the repository.


Usage

  1. Run the Service:

    Start the application with the following command:

    dotnet run

    By default, the service will be available at http://localhost:5000.

  2. Retrieve a Secret:

    Use any HTTP client (e.g., Postman, curl) to fetch secrets from Vault. Example:

    curl http://localhost:5000/config/secret/data/my-secret

    Replace secret/data/my-secret with the appropriate secret path configured in your Vault.

  3. Expected Response:

    For a secret stored in Vault as:

    {
        "key1": "value1",
        "key2": "value2"
    }

    The API will return:

    {
        "key1": "value1",
        "key2": "value2"
    }

Testing

  • Verify API Response:
    Use test tools like Postman or curl to confirm that secrets are retrieved correctly.

  • Simulate Error Handling:
    Test the service with invalid secret paths or by stopping the Vault server to verify the error responses.


Contribution Guidelines

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request with a clear description of the changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

This project provides a minimal ASP.NET Core web API for retrieving configuration secrets from HashiCorp Vault using VaultSharp. It is designed as a foundational microservice for configuration management within a microservices architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages