Auth0 Deploy CLI

repository·master·Indexed 43 days ago

https://github.com/auth0/auth0-deploy-cli

A command line tool for managing and deploying Auth0 tenant configurations. It allows developers to export and import resources such as clients, connections, and actions across multiple environments using YAML or structured directory formats. Version 8.45.0 supports environment-specific variable injection via AUTH0_KEYWORD_REPLACE_MAPPINGS and integrates with the Auth0 Management API using Machine to Machine (M2M) applications.

Tokens
35.1K
Snippets
97
Records
134
Agent score
50%

What's inside Auth0 Deploy CLI

  1. Understand Token Vault Privileged Access visibility

    master

    The token_vault_privileged_access property allows you to harden a privileged Token Vault worker by restricting caller IPs, connections, and scopes.

    Important: This field is Export-only.

    While the Deploy CLI exports this property for visibility (showing ip_allowlist and grants), it will not deploy these settings. The property is stripped from all create/update payloads during deployment because the underlying Management API requires specific tenant-resident credential IDs that are not portable across tenants.

    To manage token_vault_privileged_access, you must use the Auth0 Management API or the Auth0 Dashboard directly.

    # Exported shape (visible in CLI export, but not deployable)
    clients:
      - name: My Token Vault Privileged App
        app_type: non_interactive
        token_vault_privileged_access:
          ip_allowlist:
            - '192.168.1.0/24'
          grants:
            - connection: google-oauth2
              scopes:
                - 'https://www.googleapis.com/auth/calendar.readonly'
  2. Configure Universal Login Prompts

    master

    The prompts resource allows you to customize Universal Login pages. You can configure custom multilingual text, inject custom HTML via partials, and set specific rendering settings for prompt-screen combinations.

    Custom Text

    Translations follow a hierarchy: language code → prompt ID → screen ID → text ID.

    Partials

    Custom HTML injected at specific insertion points. In Directory Mode, you must provide a partials.json manifest that maps insertion points to .liquid files (paths relative to the prompts/ directory).

    Screen Renderers

    Used to configure rendering settings for specific prompt-screen combinations (e.g., setting rendering_mode to advanced or adding head_tags).

    // Example partials.json manifest in Directory Mode
    {
      "login": [
        {
          "login": [
            {
              "name": "form-content-start",
              "template": "partials/login/login/form-content-start.liquid"
            }
          ]
        }
      ]
    }
  3. Choose between YAML and Directory (JSON) configuration formats

    master

    The Auth0 Deploy CLI supports two configuration formats for expressing Auth0 resource state. You are prompted to choose between these formats when running the export command. While both formats achieve the same goal, they differ in structure and management style:

    YAML

    • Structure: Primarily a single, flat tenant.yaml file, supplemented by individual code files for specific resources like Actions or Email Templates.
    • Best for: Version control tracking. A single file makes it easier to see changes over time in a git history and avoids ambiguity regarding directory/file naming conventions.

    Directory (JSON)

    • Structure: Separates resource types into distinct directories, where every individual resource is stored in its own dedicated .json file.
    • Best for: Conceptual separation. This format mirrors the data shapes used in the Auth0 Management API, making it easier to map CLI configurations to API documentation.

    Note: This choice is not permanent. You can switch between YAML and Directory formats using the import command.

  4. Filter connections using AUTH0_INCLUDED_CONNECTIONS

    master

    To manage only a specific subset of connections (e.g., to avoid touching third-party SSO or self-service connections), use AUTH0_INCLUDED_CONNECTIONS. When this is set, all other connections in the tenant are ignored during both export and import operations.

    Note: This cannot be used simultaneously with AUTH0_EXCLUDED_CONNECTIONS.

    {
      "AUTH0_INCLUDED_CONNECTIONS": ["github", "google-oauth2"]
    }
  5. Exclude resource types using AUTH0_EXCLUDED

    master

    Use AUTH0_EXCLUDED to prevent the Deploy CLI from managing specific resource types (e.g., actions, organizations, logStreams). This applies to both import and export operations.

    Note: This cannot be used simultaneously with AUTH0_INCLUDED_ONLY.

    {
      "AUTH0_EXCLUDED": ["organizations", "connections", "hooks"]
    }
  6. Choosing between Deploy CLI and Auth0 Terraform Provider

    master

    Auth0 provides two primary tools for managing tenant configurations: the Deploy CLI and the Auth0 Terraform Provider. Choosing between them depends on your existing infrastructure and management goals.

    Use the Auth0 Terraform Provider if:

    • Your development workflows already leverage Terraform.
    • Your tenant management needs are granular or focus on a few specific resources.

    Use the Deploy CLI if:

    • Your development workflow does not use Terraform (to avoid extra setup).
    • Your primary goal is managing your tenant resources in bulk.
    • Your tenant already has many existing resources (the Terraform Provider may require significant effort to "import" existing resources into state).
  7. Use Dry Run mode to preview changes

    master

    Dry run mode allows you to preview all potential changes to your Auth0 tenant without actually applying them. It performs schema, business rule, and configuration validation (including keyword replacements) to ensure your deployment is safe. If validation errors occur, the CLI reports them and exits without making any changes.

    a0deploy import --config_file=config.json --input_file=./tenant.yaml --dry-run
  8. Use keyword replacement for multi-tenant workflows

    master

    The Deploy CLI supports dynamic keyword replacement to allow sharing the same resource configuration files across multiple tenants while injecting environment-specific values.

    To enable this, define your mappings in the AUTH0_KEYWORD_REPLACE_MAPPINGS configuration property. You can then inject these values into your resource configuration files (YAML or JSON) using two different syntaxes depending on how you want the value to be treated:

    • @@EXAMPLE_KEY@@: Performs a JSON.stringify on the value before replacement. Use this for strings (adds quotes), arrays, or objects (adds braces).
    • ##EXAMPLE_KEY##: Performs a literal replacement without adding quotes or braces. Use this for raw text or when you need to manually control the formatting.

    Environment variables are automatically added to the replacement mappings, so you can reference them using the same syntax.

    {
      "AUTH0_KEYWORD_REPLACE_MAPPINGS": {
        "ENVIRONMENT": "dev",
        "ALLOWED_LOGOUT_URLS": ["https://dev-test-site.com/logout", "localhost:3000/logout"],
        "ALLOWED_ORIGINS": ["https://dev-test-site.com", "localhost:3000"]
      }
    }
  9. Understand the difference between Omission, Exclusion, and Empty states

    master

    When managing Auth0 resources with the Deploy CLI, it is critical to distinguish between these three states:

    1. Exclusion

    Forcefully ignores configurations bi-directionally (both export and import) using properties like AUTH0_EXCLUDED. The CLI will not read from or write to these resources.

    2. Omission

    Resource configuration that is absent from your configuration files.

    • Import: Omitted resources are skipped and will not be altered in the remote tenant.
    • Export: All tenant configurations are written to files unless explicitly excluded.

    3. Empty

    Explicitly defining a resource as an empty set (e.g., [] or {}).

    • Set-based resources (e.g., hooks, organizations, actions): Setting these to an empty set signals an intentional deletion of those resources (requires AUTH0_ALLOW_DELETE to be enabled).
    • Non-set-based resources: Behavior depends on the resource. tenant, branding, attackProtection, and guardianPhoneFactorSelectedProvider cannot be deleted, while emailProvider can be deleted via an empty configuration.
    # Omission: This resource is managed, but other missing keys are skipped
    roles: 
      - name: Admin
    
    # Empty: Signals intentional deletion (if AUTH0_ALLOW_DELETE is enabled)
    connections: [] 
    
    # Empty: Effectively a no-op for non-deletable resources
    tenant: {}
    
    # Empty: Will delete the email provider
    emailProvider: {}
  10. Understand Dry Run output and interactive options

    master

    The dry run output provides a table summarizing proposed changes with the following statuses:

    • CREATE: New resources to be added.
    • UPDATE: Existing resources to be modified.
    • DELETE*: Resources to be removed (requires AUTH0_ALLOW_DELETE to be enabled).

    When running in interactive mode (using --interactive in CLI or AUTH0_DRY_RUN_INTERACTIVE: true in Node), you can choose from:

    • Apply changes: Proceed to apply all changes shown.
    • Export changes in a file: Save the diff to dry-run-diff-log.json without applying them.
    • Exit: Cancel the operation.
  11. Use AUTH0_KEYWORD_REPLACE_MAPPINGS for environment-specific deployments

    master

    To deploy the same configuration across multiple environments (dev, staging, prod), use keyword mappings to inject environment-specific values like callback URLs or timeouts.

    Values can be defined in your terminal environment variables or within config.json. Terminal variables take priority over config.json. You can disable this merging behavior using the --no-env flag.

    There are two syntax types for injection in your configuration files:

    1. @@key@@: Injects the full, literal value regardless of type (string, number, object, or array).
    2. ##key##: Used for string interpolation.

    Example Usage:

    Client.json:

    {
      "callbacks": [ "##ENVIRONMENT_URL##/auth/callback" ],
      "jwt_configuration": {
        "lifetime_in_seconds": @@JWT_TIMEOUT@@
      }
    }

    Dev Config.json:

    {
      "AUTH0_KEYWORD_REPLACE_MAPPINGS": {
        "ENVIRONMENT_URL": "http://dev.fabrikam.com",
        "JWT_TIMEOUT": 120
      }
    }
  12. Use the Directory Option for Auth0 Deploy CLI

    master

    The Directory Option allows you to export and import your Auth0 tenant configuration into a structured directory format rather than a single JSON file. This is ideal for version control (e.g., GitHub) and managing complex configurations like Actions, Triggers, and Database Connections that require multiple files (e.g., code.js, current_version.js).

    Common directory components include:

    • clients/: Client configurations.
    • connections/: Connection settings.
    • database-connections/: Database settings including create.js and login.js scripts.
    • actions/: Auth0 Actions with code.js and current_version.js.
    • triggers/: Trigger configurations.
    • emails/: Email templates and provider settings.