Skip to main content

Output a Key Vault Secrets report

Project description

azure-key-vault-report

Description

Generates Markup tables, in plain text format, of secrets in the specified Key Vaults.

Summary table

Includes stats about the records in the specified Key Vaults.

Report table

A table with more info about each record.

This table is sorted (from top to bottom) by:

  • the oldest Expiration date, then by
  • the oldest Last Updated date

This table also contains a Comment columns, which may include info about:

  • Days to when the secret will expire
  • Days since the secret expired
  • Info if the secret has no expiration date set
  • Days since the Secret was last updated

MS Teams json payload

A json payload (MS Teams) with the report(s) included as a html table may also be generated.
The MS Team payload will use the following base template:

{
  "@type": "MessageCard",
  "@context": "http://schema.org/extensions",
  "themeColor": "0076D7",
  "summary": "-",
  "sections": [
    {
      "activityTitle": "<TITLE>",
      "activitySubtitle": "",
      "activityImage": "",
      "facts": [],
      "markdown": true
    },
    {
      "startGroup": true,
      "text": "<TEXT>"
    }
  ]
}
  • activityTitle will contain the value of the provided title
  • facts will contain the rows from the summary table
  • text may contain additional data. Defaults to a html table

Installation

pip install ops-py-azure-key-vault-report

Usage

The azure_key_vault_report object must be initialized with the json output of one more az keyvault list commands.
Please refer to the code documentation provided in the az_cmd.py file.

Example code:

#!/usr/bin/env python

import os
from azure_key_vault_report import az_cmd
from azure_key_vault_report import azure_key_vault_report

vaults = ["kv-qa"]
record_types = "secret"        
#record_types = "secret key"  # valid record types are: "secret key certficate"

results = []
for vault in vaults:
  results += az_cmd.az_cmd(vault, record_types)

# The azure_key_vault_report object is initialized with the json output of the `az keyvault` list commands.
kv_report = azure_key_vault_report.AzureKeyVaultReport(results)

# Parse the result
kv_report.parse_results()

# Create the summary markdown table and print it to standard output
kv_report.add_summary()
summary = kv_report.get_markdown_summary()
print(summary)

# Create the report markdown table and print it to standard output
# This table is customized by provided arguments
kv_report.add_report()
report = kv_report.get_markdown_report_only()
print(report)

# The get_markdown_report method will return both the summary table and report table
full_report = kv_report.get_markdown_report()
print(full_report)

# Create a report table including all records
kv_report.add_report(include_all=True)
full_report = kv_report.get_markdown_report()
print(full_report)

## Create a MS Teams payload output including html table
kv_report.add_report(teams_json=True)
ms_payload = kv_report.get_teams_payload("Title of the message")
print(ms_payload)

Note that the specified kv-qa Key Vault in the code example above is just a made up fictive Key Vault, as are the record names.
If the kv-qa existed and the records, the output might have looked like the following output:

| Summary                                  | Comment |
|------------------------------------------|---------|
| Total number of vaults                   |       1 |
| Total number of records                  |      15 |
| Records missing Expiration Date          |      14 |
| Records updated in the last year         |       6 |
| Records NOT updated in the last year     |       5 |
| Records NOT updated for the last 2 years |       2 |
| Records NOT updated for the last 3 years |       2 |

| Record Name | Record Type | Vault Name | Last Updated | Expiration | Comment                                       |
|-------------|-------------|------------|--------------|------------|-----------------------------------------------|
| LicenseKey  | secret      | kv-qa      | 2023-12-11   | 2024-12-26 | Will expire in 314 days. Updated 67 days ago. |

| Summary                                  | Comment |
|------------------------------------------|---------|
| Total number of vaults                   |       1 |
| Total number of records                  |      15 |
| Records missing Expiration Date          |      14 |
| Records updated in the last year         |       6 |
| Records NOT updated in the last year     |       5 |
| Records NOT updated for the last 2 years |       2 |
| Records NOT updated for the last 3 years |       2 |


| Record Name | Record Type | Vault Name | Last Updated | Expiration | Comment                                       |
|-------------|-------------|------------|--------------|------------|-----------------------------------------------|
| LicenseKey  | secret      | kv-qa      | 2023-12-11   | 2024-12-26 | Will expire in 314 days. Updated 67 days ago. |

| Summary                                  | Comment |
|------------------------------------------|---------|
| Total number of vaults                   |       1 |
| Total number of records                  |      15 |
| Records missing Expiration Date          |      14 |
| Records updated in the last year         |       6 |
| Records NOT updated in the last year     |       5 |
| Records NOT updated for the last 2 years |       2 |
| Records NOT updated for the last 3 years |       2 |


| Record Name      | Record Type | Vault Name | Last Updated | Expiration | Comment                                        |
|------------------|-------------|------------|--------------|------------|------------------------------------------------|
| LicenseKey       | secret      | kv-qa      | 2023-12-11   | 2024-12-26 | Will expire in 314 days. Updated 67 days ago.  |
| ConnectionString | secret      | kv-qa      | 2020-10-12   |            | Has no expiration date. Updated 1222 days ago. |
| ApplicationKey   | secret      | kv-qa      | 2020-10-22   |            | Has no expiration date. Updated 1212 days ago. |
| MaintenanceKey   | secret      | kv-qa      | 2021-10-15   |            | Has no expiration date. Updated 854 days ago.  |
| ApimKey          | secret      | kv-qa      | 2021-10-27   |            | Has no expiration date. Updated 842 days ago.  |
| TestBearerToken  | secret      | kv-qa      | 2022-05-02   |            | Has no expiration date. Updated 655 days ago.  |
| ClientId         | secret      | kv-qa      | 2022-06-09   |            | Has no expiration date. Updated 617 days ago.  |
| EmailPassword    | secret      | kv-qa      | 2022-06-17   |            | Has no expiration date. Updated 609 days ago.  |
| AzureString      | secret      | kv-qa      | 2022-06-24   |            | Has no expiration date. Updated 602 days ago.  |
| SubscriptionKey  | secret      | kv-qa      | 2022-12-02   |            | Has no expiration date. Updated 441 days ago.  |
| ApiToken         | secret      | kv-qa      | 2023-04-11   |            | Has no expiration date. Updated 311 days ago.  |
| Secret           | secret      | kv-qa      | 2023-06-01   |            | Has no expiration date. Updated 260 days ago.  |
| MyClientSecret   | secret      | kv-qa      | 2023-06-08   |            | Has no expiration date. Updated 253 days ago.  |
| SubscriptionKey  | secret      | kv-qa      | 2023-08-24   |            | Has no expiration date. Updated 176 days ago.  |
| ApiSnKey         | secret      | kv-qa      | 2023-09-08   |            | Has no expiration date. Updated 161 days ago.  |

{"@type": "MessageCard", "@context": "http://schema.org/extensions", "themeColor": "0076D7", "summary": "-", "sections": [{"activityTitle": "Title of the message", "activitySubtitle": "", "activityImage": "", "facts": [{"name": "Total number of Key Vaults:", "value": 1}, {"name": "Total number of records:", "value": 15}, {"name": "Records missing Expiration Date:", "value": 14}, {"name": "Records updated in the last year:", "value": 6}, {"name": "Records NOT updated in the last year:", "value": 5}, {"name": "Records NOT updated for the last 2 years:", "value": 2}, {"name": "Records NOT updated for the last 3 years:", "value": 2}], "markdown": true}, {"startGroup": true, "text": "<table bordercolor='black' border='2'>    <thead>    <tr style='background-color : Teal; color: White'>        <th>Record Name</th>        <th>Record Type</th>        <th>Vault Name</th>        <th>Last Updated</th>        <th>Expiration</th>        <th>Comment</th>    </tr>    </thead>    <tbody>    <tr><td>LicenseKey</td><td>secret</td><td>kv-qa</td><td>2023-12-11</td><td>2024-12-26</td><td>Will expire in 314 days<br>Updated 67 days ago<br></td></tr></tbody></table>"}]}

Arguments

add_report()

This method accepts the following arguments:

  • expire_threshold : int
    Ignore to report the record if days till the secret will expire are more than specified value.
    NOTE: Secrets expiring today or has already expired will always be reported.
    Default: None

  • ignore_no_expiration : bool
    Report all records if set to False. If set to True only secrets with a Expiration Date set will be reported.
    Default: True

  • include_all : bool
    If set to True all records are included in the output.
    Default: False

  • teams_json : bool
    If set to True a html table will also be generated which might be used in the MS Teams payload.
    Default: False

get_teams_payload()

This method accepts the following arguments:

  • title : txt
    The activityTitle of the payload.

  • text : txt
    Additional text. Default to the generated html table.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ops_py_azure_key_vault_report-5.0.2.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file ops_py_azure_key_vault_report-5.0.2.tar.gz.

File metadata

File hashes

Hashes for ops_py_azure_key_vault_report-5.0.2.tar.gz
Algorithm Hash digest
SHA256 97273b5b3fa5d5d39ddb08e9c1e4c2471f59062ed0da9bb515cb6718278f4b78
MD5 464f584df221e98b9d1485692f0cf78b
BLAKE2b-256 9cd13141e7cfce7a689b16010ed33aa1ffcb651b52a0aff4a039f14a5bef0a34

See more details on using hashes here.

File details

Details for the file ops_py_azure_key_vault_report-5.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ops_py_azure_key_vault_report-5.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ddd18bf92cd54b835bfe646bc081fc8471036623166705a981dbf872ac86e80
MD5 481ad497b7d30c9d43846e4d21fcb0be
BLAKE2b-256 99ba3e948de7c6ea2d6239f8a0f6057b6a422e53f719ae4d96b990dc3e8e6969

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page