Run a Script with the Private Action Runner

This product is not supported for your selected Datadog site. ().
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Overview

This page explains how to use the private action runner (PAR), which allows you to run custom scripts and Linux binaries within your Datadog workflows and apps. Unlike standard private actions that call specific APIs or services, the script action gives you the flexibility to execute arbitrary commands, shell scripts, and command-line tools directly from the private action runner in your private network.

Security Notice: The PAR script action runs within a containerized environment using a dedicated Linux user named scriptuser for enhanced security. Datadog enforces container sandboxing and only accepts signed tasks, but you decide which binaries and scripts are allowed. Always review every command you add to the script action allow-list, especially ones that take dynamic user input. Ensure that your actions are configured with the least privileged commands, and carefully review the permissions you share through connections. For more information, see connection security considerations.

Use cases

The following table outlines supported and unsupported use cases for the script action:

Use CaseSupportedNotes
Running Linux binaries (ls, rm, find, curl)YesIn order to run native Linux binaries, the relevant files must be accessible to the container.
Running CLIs (aws, terraform, kubectl)YesThe CLI and your CLI credentials must be added to your custom image.
Running scripts (bash, python)YesScripts can be mounted inside the container. Interpreters such as Python must be installed on your custom image.
Running privileged commands (systemctl restart)NoBecause the PAR runs inside a container, it does not have high privilege permissions on the host.
Windows tools (PowerShell)NoBecause the PAR runs inside a Linux container, native Windows tools are not supported.

Prerequisites

To use the script action, you need:

Set up a PAR script

Create a script connection

  1. After setting up a PAR, navigate to Connections.
  2. Click New Connection.
  3. Select Script.
  4. Enter a Connection Name.
  5. In the Private Action Runner dropdown, select your PAR.
  6. Copy and paste the credential file template into your PAR’s configuration directory with the commands you want to run.
  7. In Path to file, ensure the file path matches the path on your runner’s filesystem (the default should be sufficient in most use cases).
  8. Click Next, Confirm Access.
  9. After configuring permissions, click Create.
  10. Select this new connection when using the script action in your workflows or apps.

Configuration

Configure script actions through your runner’s config.yaml file and the script connection (credentials/script.yaml by default). If you create a new runner and select the script bundle, you get a default configuration.

# Add the script action to the allowlist (`config.yaml`)
actionsAllowlist:
  - com.datadoghq.script.runPredefinedScript
# Configure your script connection (`credentials/script.yaml`)
schemaId: script-credentials-v1
runPredefinedScript:
  # use "echo" as the "Script name" in the action configuration
  echo:
    # use an array to specify the command
    command: ["echo", "Hello world"]

  # another script
  echo-parametrized:
    # you can use workflow syntax (https://docs.datadoghq.com/actions/workflows/variables/) to retrieve values from the parameters object
    command: [ "echo", "{{ parameters.echoValue }}" ]
    # you can use JSON schema (https://json-schema.org/) to validate the parameters
    parameterSchema:
      properties:
        echoValue:
          type: string
          const: "world"
      required:
        - echoValue

Using the configured scripts

In your workflow or app, configure the action to use the runPredefinedScript with the script name you defined (for example, echo or echo-parametrized).

Note: There are two levels of variable resolution: one at the workflow level and one at the action level inside the runner.

The two levels of variables inside the runner.

Advanced usage with custom images

For binaries not available in the base runner image, create a custom image:

# Dockerfile example
FROM gcr.io/datadoghq/private-action-runner:v1.9.0
USER root
RUN apt update && apt install -y python3
USER dog

You can mount complex scripts inside the runner:

# docker-compose example
services:
  runner:
    image: gcr.io/datadoghq/private-action-runner:v1.9.0
    # build: . # if you are using a custom Dockerfile
    volumes:
      - "./config:/etc/dd-action-runner/config"
# credentials/script.yaml
schemaId: script-credentials-v1
runPredefinedScript:
  python:
    command: ["python3", "/etc/dd-action-runner-script/scripts/script.py"]
  shell:
    command: [ "bash", "/etc/dd-action-runner-script/scripts/script.sh" ]
# scripts/script.sh
echo "Hello from the shell script!"
# scripts/script.py
print("Hello from Python script!")