Coder Social home page Coder Social logo

azure-keyvault-secret-rotation-demo's Introduction

Azure Key Vault - Rotate Secrets using Function App Event Handler

Usecase - Rotate( Storage Account) Secrets
Current State

  • Storage Account (ksripadastorageaccount) is being used by multiple applications/processes.
  • Handover secrets manually /email to the applications /processes owners.
  • Secrets have no expiry.

Why - MS recommendation is to rotate secrets, every 90 days

How - Rotate secrets using Azure Key Vault .
Other available options HashiCorp vault

Demo -

  • Rotate & retrieve secrets using Azure KV.

Future State

  • Ability to rotate secrets on a 90 day frequency
  • The ability for applications to retrieve secrets instead of handing secrets to owners

Demo Highlights -

  1. Create secret in AKV acces_keys for ksripadastorageaccount
  2. Rotate Secrets using MS recommended option
  3. Access Secrets (Client Applications, Processess) Retrieve secrets Secure secret retrieval
  4. Notify & Alert(nice to have )
  5. Learnings / Next steps

1.Create a secret in AKV

Azure Key Vault is a cloud service for securely storing and accessing secrets.
A secret is anything that you want to tightly control access to, such as API keys, passwords, certificates, or cryptographic key
image
image

2.Rotate Secrets

The azure key vault provides the option to set the expiry when we provision/store an entity in the Key Vault.
We can then monitor events related to an upcoming expiry date.
image image

Rotate keys image

      Prerequisites
        An Azure App Service plan
        A storage account to manage function app triggers
        An access policy to access secrets in Key Vault
        The Storage Account Key Operator Service role is assigned to the function app so it can access storage account access keys
        A key rotation function with an event trigger and an HTTP trigger (on-demand rotation)
        An Event Grid event subscription for the SecretNearExpiry eve

3.Access Secrets

Enable a system-assigned managed identity for the application.
Register the application with your Azure AD tenant.
Option #2 Applications can access secrets using service principal image

Applications can access secrets using service principal image

4. Notify & Alert

notify-webhook copyimage

5. Learnings

Intermittent Errors / Exceptions encountered during POC

  1. [Error] Singleton lock renewal failed for blob 'ksripada-storagekey-rotation-fna/host' with error code 409:LeaseIdMismatchWithLeaseOperation.
    QuickFix:- Restart Function app event handler

  2. [Error]Azure.KeyVault.Models.KeyVaultErrorException: Operation returned an invalid status code 'Forbidden'at Microsoft.Azure.KeyVault.KeyVaultClient.GetSecretWithHttpMessagesAsy
    QuickFix:- Validate permissions to function app . the Restart function app event handler

References #
https://github.com/Azure-Samples/KeyVault-Rotation-StorageAccountKey-PowerShell.git
https://dev.to/cheahengsoon/configure-and-manage-azure-key-vault-3foj
https://github.com/Azure-Samples/event-grid-node-publish-consume-events

azure-keyvault-secret-rotation-demo's People

Contributors

kiransripada avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.