Azure function for rotation of Cosmos DB keys with Key Vault
Перейти к файлу
microsoft-github-policy-service[bot] a9e7e27013
Auto merge mandatory file pr
This pr is auto merged as it contains a mandatory file and is opened for more than 10 days.
2023-03-28 16:43:14 +00:00
AKVCosmosDBRotation update 2021-01-18 17:56:25 -08:00
AKVCosmosDBRotationHttp initial setup 2020-12-31 10:53:01 -08:00
ARM-Templates Add secrets deployment 2021-02-15 14:17:51 -08:00
.deployment Initial commit 2020-12-31 10:22:08 -08:00
.funcignore Initial commit 2020-12-31 10:22:08 -08:00
.gitignore Initial commit 2020-12-31 10:22:08 -08:00
CHANGELOG.md initial setup 2020-12-31 10:53:01 -08:00
CONTRIBUTING.md initial setup 2020-12-31 10:53:01 -08:00
LICENSE.md Initial commit 2020-12-31 10:22:08 -08:00
Project-Template-Instructions.md update 2021-02-15 14:53:02 -08:00
README.md Update README.md 2021-02-15 21:18:24 -08:00
SECURITY.md Microsoft mandatory file 2023-01-24 15:55:34 +00:00
host.json update 2020-12-31 12:08:23 -08:00
profile.ps1 Initial commit 2020-12-31 10:22:08 -08:00
proxies.json Initial commit 2020-12-31 10:22:08 -08:00
requirements.psd1 update 2020-12-31 12:01:18 -08:00

README.md

KeyVault-Secrets-Rotation-CosmosDB-PowerShell

Functions regenerate individual key (alternating between two keys) in CosmosDB and add regenerated key to Key Vault as new version of the same secret.

Features

This project framework provides the following features:

  • Rotation function for CosmosDB key triggered by Event Grid (AKVCosmosDBRotation)

  • Rotation function for CosmosDB key triggered by HTTP call (AKVCosmosDBRotationHttp)

  • ARM template for function deployment with secret deployment (optional)

  • ARM template for adding CosmosDB key to existing function with secret deployment (optional)

Getting Started

Functions require following information stored in secret as tags:

  • $secret.Tags["ValidityPeriodDays"] - number of days, it defines expiration date for new secret
  • $secret.Tags["CredentialId"] - CosmosDB credential id (Primary, Secondary)
  • $secret.Tags["ProviderAddress"] - CosmosDB Resource Id

You can create new secret with above tags and CosmosDB key as value or add those tags to existing secret with CosmosDB key. For automated rotation expiry date will also be required - key vault triggers 'SecretNearExpiry' event 30 days before expiry.

There are two available functions performing same rotation:

  • AKVCosmosDBRotation - event triggered function, performs CosmosDB key rotation triggered by Key Vault events. In this setup Near Expiry event is used which is published 30 days before expiration
  • AKVCosmosDBRotationHttp - on-demand function with KeyVaultName and Secret name as parameters

Functions are using Function App identity to access Key Vault and existing secret "CredentialId" tag with CosmosDB key id (key1/key2) and "ProviderAddress" with CosmosDB Resource Id.

Installation

ARM templates available:

Demo

You can find example for Storage Account rotation in tutorial below: Automate the rotation of a secret for resources that have two sets of authentication credentials

Youtube: https://youtu.be/qcdVbXJ7e-4

Project template information:

This project was generated using this template. You can find instructions here