1. Secure AI API Keys with Vault Okta Integration

    Python

    When working with sensitive information like AI API keys, it's crucial to store them securely and control access. HashiCorp Vault is an excellent tool for secrets management as it allows you to securely store, manage, and control access to tokens, passwords, certificates, API keys, and other secrets. In addition, integrating Vault with Okta can provide a robust solution for authentication and multi-factor authentication (MFA), ensuring only authorized users can access these secrets.

    Below, we'll go through the steps to set up a secure storage system using Pulumi with Vault and Okta integration. This integration allows us to take advantage of Okta's authentication mechanisms to secure access to the Vault, where we'll securely store an AI API key.

    Here's what we need to do:

    1. Configure Vault to use Okta as the authentication backend.
    2. Store an AI API key securely in Vault.
    3. Optionally, configure MFA with Okta to require a second factor when performing authentication.

    We will be using the Vault and Pulumi providers to create these resources. The Vault provider allows us to interact with a Vault server, setting up the necessary configurations for Okta integration and storing secrets. The Pulumi provider allows us to write our infrastructure as code.

    Let's start with our Pulumi program:

    import pulumi import pulumi_vault as vault # Assume that the Vault server is already set up and running. # Create an Okta authentication backend in Vault. okta_auth_backend = vault.okta.AuthBackend("okta-auth-backend", organization="example-organization", # The organization name in Okta. description="Okta auth backend for secure AI API keys", token="sensitive-token", # The Okta token for API access. This should be kept secret. # You might want to pull this value from Pulumi config or another secrets manager for better security. ) # Configure an Okta application that matches the configuration in Okta. okta_app = vault.okta.AuthBackendGroup("okta-auth-backend-group", path=okta_auth_backend.path, groups=["MyOktaGroup"], # The Okta groups that are allowed access. Replace with your group. policies=["default"], # The Vault policies that grant permissions to the API keys. ) # Store an AI API key securely in Vault. The key is assumed to be sensitive and is provided here directly. # In a real-world scenario, the key should never be hardcoded and should be provided via a secure input method. ai_api_key_secret = vault.GenericSecret("ai-api-key-secret", path="secret/ai/api-key", # The path where the secret will be stored in Vault. data={ "api_key": "my-very-sensitive-api-key", # The actual AI API key. Treat this as sensitive information. }, ) # Output the path to the AI API key securely stored in Vault. pulumi.export("ai_api_key_vault_path", ai_api_key_secret.path)

    Explanation:

    • vault.okta.AuthBackend represents the configuration of the Okta authentication backend in Vault. We need to specify the organization in Okta and a token which allows Vault to communicate with the Okta API.

    • vault.okta.AuthBackendGroup ties a group of Okta users to a set of Vault policies, determining what they have access to. The groups attribute specifies which Okta group's members are allowed to authenticate, and the policies attribute specifies which Vault policies will be applied to them.

    • vault.GenericSecret is used to store a secret in Vault at a specified path. Here we are storing an AI API key as a generic secret. In the data dictionary, you provide the key-value pairs of the secret.

    • pulumi.export outputs the Vault path where the AI API key is stored. This is how you can reference this secret in other parts of your infrastructure or applications – by its path in Vault.

    Keep in mind that the above code is for illustrative purposes and should not be used as-is in production. The Okta token and AI API key are sensitive values and should be obtained through secure means, such as environment variables or Pulumi's configuration system.

    This setup ensures that your AI API key is securely stored in Vault and that only authorized users in the specified Okta group can access it, optionally with MFA enabled for an added layer of security.