Assumptions:
- This was done as a quick and dirty PoC using the Azure Portal, I'm sure this can be done using CLI/Terraform etc... however I just wanted to verify that I could get it working quickly
- You have a Windows 2019 or newer Azure VM to test with
- Follow this doc to create an Azure KeyVault using the Portal: https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-portal, set it up using RBAC so you can use IAM and role-based access.
- Create a new secret in Azure KeyVault called
secret1, and a second one calledsecret2. - Using IAM, assign the
KeyVault Secrets Userrole to your test VM: - On your VM, install Python3 (https://www.python.org/downloads/) + required Python Packages:
pip install azure-identity pip install azure-keyvault-secrets
- Create a new Python file called
get_secrets.pyand add the following contents:import os import cmd import logging import sys import json from azure.keyvault.secrets import SecretClient from azure.identity import DefaultAzureCredential # This filters out a false warn log def filter_environment_credential_warning(record): if record.name.startswith("azure.identity") and record.levelno == logging.WARNING: message = record.getMessage() return not message.startswith("EnvironmentCredential.get_token") return True handler = logging.StreamHandler(sys.stdout) handler.addFilter(filter_environment_credential_warning) logging.basicConfig(level=logging.WARN, handlers=[handler]) # Set your KeyVault name here, or use an env variable # keyVaultName = os.environ["KEY_VAULT_NAME"] keyVaultName = "your-keyvault-name" KVUri = f"https://{keyVaultName}.vault.azure.net" credential = DefaultAzureCredential() client = SecretClient(vault_url=KVUri, credential=credential) # Put your secret name(s) here, or use an env variable(s) secret1Name = "secret1" retrieved_secret1 = client.get_secret(secret1Name) secret2Name = "secret2" retrieved_secret2 = client.get_secret(secret2Name) print(json.dumps({'secret1' : retrieved_secret1.value, 'secret2' : retrieved_secret2.value}))
- Test that your Python script works by running
python.exe get_secrets.pyfrom within the same dir you created the file in. - Once you see your results, now we need to convert it to an
.exefile. - Run
pip install pyinstaller, this is an open source Python to EXE converter: https://www.pyinstaller.org/ - Next, run
pyinstaller.exe --onefile .\get_secrets.pyfrom within the same dir as the Python file you created. - In the same dir, a new dir will be created after you run this command called
dist, cd into the dir and run the new commandget_secrets.exe, you should see your secrets output just as they were with the Python script. - You can now use this application in your Datadog config as outlined here: https://docs.datadoghq.com/agent/guide/secrets-management/?tab=windows#providing-an-executable
The Datadog Agent won't launch if the permissions are not set properly on the file, they should be as follows:
SYSTEMgroup has full controlAdministratorsgroup has full controlddagenteruser(or whatever the Agent's user was named) user has read & execute access (full control worked, too)
