Skip to main content

keyvaultlib

A KeyVault client wrapper that helps transition between using ADAL (Active Directory Authentication Libraries) and MSI (Managed Service Identity) as a token provider. Moreover, this library provides support for User-Assigned identities (MSI) and non-public (e.g. Government) Azure clouds.

What is KeyVault ?

Key Vault is an Azure managed cloud service that allows you to securely store secrets in a variety of forms:

  • Credentials
  • Connection Strings
  • Private Keys and Certificates in various formats
  • ...

It provides auditing and integrates easily with AAD (Azure-Active-Directory) for user or application based authorization. More about KeyVault can be found in the following link: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-overview

What is ADAL (Active Directory Authentication Libraries) ?

ADAL are a set of libraries provided by the AAD (Azure-Active-Directory) team in a variety of programming languages that allows one to easily interact with their cloud active directory. For example, the libraries could be used for authentication and authorization with Azure resources

More about ADAL can be found in the following link: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-libraries

What is MSI (Managed-Service-Identity) ?

MSI was created to ease the authentication flow for Azure services, while providing a per-VM granularity of control. Once MSI is enabled on your VM, your virtual machine will be assigned an application or user client ID, with which you could easily receive access tokens for Azure resources, which you may then authorize your VM to use. It also saves the need to store your service principal information on disk, or worse, in your code base.

More about MSI can be found in the following link: https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/overview

How to use this wrapper effectively ?

This KeyVault client was created for reducing the small code duplication involving the use of either MSI or ADAL / Service Principal Credentials. A common use case being - having part of your code running on Azure VMs while another part running on your local machine or VM, where MSI is not accessible.

Example

First, install the library via:

$> pip install keyvaultlib

Next, import KeyVaultOAuthClient and choose your authentication strategy;

Currently supported: Using Service Principal credentials for ADAL or MSI

from keyvaultlib.key_vault import KeyVaultOAuthClient

# MSI Example
client = KeyVaultOAuthClient(use_msi=True)
secret = client.get_secret_with_key_vault_name('my-key-vault', 'my-secret')

# MSI - User Assigned Identity example
client = KeyVaultOAuthClient(use_msi=True, client_id='my_user_assigned_client_id')
secret = client.get_secret_with_key_vault_name('my-key-vault', 'my-secret')

# ADAL / SPN Example
client = KeyVaultOAuthClient(
  client_id='my_user_or_app_client_id', 
  client_secret='my_user_or_app_client_secret', 
  tenant_id='my_AAD_tenant_id'
)
secret = client.get_secret_with_key_vault_name('my-key-vault', 'my-secret')

# Setting retry counts for request-throttling (Default is 5)
client = KeyVaultOAuthClient(
  client_id='my_user_or_app_client_id', 
  client_secret='my_user_or_app_client_secret', 
  tenant_id='my_AAD_tenant_id'
)
secret = client.get_secret_with_key_vault_name('my-key-vault', 'my-secret', throttling_retry_attempts=2)

# Using government / non-public Azure Clouds Example:
from msrestazure.azure_cloud import AZURE_US_GOV_CLOUD

client = KeyVaultOAuthClient(
  client_id='my_user_or_app_client_id', 
  client_secret='my_user_or_app_client_secret', 
  tenant_id='my_AAD_tenant_id',
  cloud=AZURE_US_GOV_CLOUD
)
secret = client.get_secret_with_key_vault_name('my-key-vault', 'my-secret')

Metadata

Release files for keyvaultlib 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keyvaultlib 1.1.4
File Size Uploaded
keyvaultlib-1.1.4.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keyvaultlib 1.1.4
File Interpreter ABI Platform
keyvaultlib-1.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 10.7 kB

Release files / keyvaultlib-1.1.4.tar.gz

Download URL keyvaultlib-1.1.4.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
21ded09979e9cf158e19d316e9dd1401419ebbcf373293b162ceab7479cfe0b7
BLAKE2b-256 checksum
How to use checksums
4638e486dd59a52711ea23813b367874e7d06b92c73ca7356ba1bf672d512756
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Release files / keyvaultlib-1.1.4-py2.py3-none-any.whl

Download URL keyvaultlib-1.1.4-py2.py3-none-any.whl
Size 5.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f5ac5f4f872c78daa8f0a43754fe593c6de713ab3753a8eb1506c0fa40c65a85
BLAKE2b-256 checksum
How to use checksums
b40cc41e9f3fcd8e3cccdf7833a923437d41b12ca477928ccf522850f507eb4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page