Robocorp Vault
Robocorp Vault is a Python library that provides an API for securely accessing secrets stored in the Robocorp Control Room Vault. It allows bots and assistants to retrieve sensitive information like usernames, passwords, and API keys. The library is part of the larger Robocorp ecosystem, offering a stable interface, with releases occurring as needed to support platform updates or introduce new features.
Warnings
- gotcha The `robocorp-vault` library is designed to operate within a Robocorp execution environment (e.g., a Robocorp Task or Action). When running code locally outside this environment, you must manually configure specific environment variables (`RC_API_SECRET_HOST`, `RC_API_SECRET_TOKEN`, or `ROBOCORP_WORKITEM_STATE`) to enable communication with your Control Room Vault. Without these, `get_secret` calls will likely fail.
- gotcha Attempting to retrieve a secret that does not exist or whose name is misspelled will raise a `robocorp.vault.SecretNotFound` exception. This can lead to unhandled crashes if not properly anticipated.
- gotcha Sensitive secret values (like passwords) should never be logged directly to console output, work item logs, or external systems, as this defeats the purpose of secure secret management. While `secret.password` and `secret.value` provide access to the data, exercise extreme caution.
Install
-
pip install robocorp-vault
Imports
- get_secret
from robocorp.vault import get_secret
- SecretNotFound
from robocorp.vault import SecretNotFound
- get_secret_names
from robocorp.vault import get_secret_names
Quickstart
import os
from robocorp.vault import get_secret, SecretNotFound
# This example demonstrates how to retrieve a secret using robocorp-vault.
# It requires a Robocorp environment (e.g., running within a Robocorp Task
# or locally with appropriate environment variables like RC_API_SECRET_HOST
# and RC_API_SECRET_TOKEN set to connect to your Control Room Vault).
def access_my_example_secret():
secret_name = "MyTestSecret" # Replace with an actual secret name from your Control Room
print(f"Attempting to retrieve secret: '{secret_name}'")
try:
# The get_secret function internally handles authentication using the
# Robocorp environment context or configured API access details.
secret = get_secret(secret_name)
print(f"Successfully retrieved secret: {secret_name}")
print(f" Username: {secret.username}")
# For security, avoid printing raw passwords or sensitive values directly to logs.
# print(f" Password: {secret.password}")
if secret.value:
print(f" Generic Value (first 5 chars): {secret.value[:5]}...")
else:
print(" This secret does not have a generic 'value'.")
except SecretNotFound:
print(f"Error: Secret '{secret_name}' not found. "
"Please ensure it exists in your Robocorp Control Room Vault "
"and the bot/robot has access permissions.")
except Exception as e:
print(f"An unexpected error occurred while accessing the vault: {e}")
if __name__ == "__main__":
# Simulate environment check for local execution.
# In a real Robocorp run, these environment variables are automatically set.
if not os.environ.get("RC_API_SECRET_HOST") and not os.environ.get("ROBOCORP_WORKITEM_STATE"):
print("\n--- Local Execution Warning --- ")
print("Running outside a Robocorp environment. Secret retrieval may fail.")
print("To run locally, you need to configure RC_API_SECRET_HOST, RC_API_SECRET_TOKEN (or ROBOCORP_WORKITEM_STATE)")
print("refer to Robocorp documentation for local testing secrets.")
print("-------------------------------\n")
access_my_example_secret()