Configuration

This page defines the format of OPA configuration files. Fields marked as required must be specified if the parent is defined. For example, when the configuration contains a status key, the status.service field must be defined.

The configuration file path is specified with the -c or --config-file command line argument:

  1. opa run -s -c config.yaml

The file can be either JSON or YAML format.

Example

  1. services:
  2. acmecorp:
  3. url: https://example.com/control-plane-api/v1
  4. credentials:
  5. bearer:
  6. token: "bGFza2RqZmxha3NkamZsa2Fqc2Rsa2ZqYWtsc2RqZmtramRmYWxkc2tm"
  7. labels:
  8. app: myapp
  9. region: west
  10. environment: production
  11. bundles:
  12. authz:
  13. service: acmecorp
  14. resource: bundles/http/example/authz.tar.gz
  15. polling:
  16. min_delay_seconds: 60
  17. max_delay_seconds: 120
  18. decision_logs:
  19. service: acmecorp
  20. reporting:
  21. min_delay_seconds: 300
  22. max_delay_seconds: 600
  23. status:
  24. service: acmecorp
  25. default_decision: /http/example/authz/allow

Environment Variable Substitution

Only supported with the OPA runtime (opa run).

Environment variables referenced with the ${...} notation within the configuration will be replaced with the value of the environment variable.

Example using BASE_URL and BEARER_TOKEN environment variables:

  1. services:
  2. acmecorp:
  3. url: ${BASE_URL}
  4. credentials:
  5. bearer:
  6. token: "${BEARER_TOKEN}"
  7. discovery:
  8. name: /example/discovery
  9. prefix: configuration

The environment variables BASE_URL and BEARER_TOKEN will be substituted in when the config file is loaded by the OPA runtime.

If the variable is undefined then an empty string ("") is substituted. It will not raise an error.

CLI Runtime Overrides

Only supported with the OPA runtime (opa run).

Using opa run there are CLI options to explicitly set config values. These will override any values set in the config file.

There are two options to use: --set and --set-file

Both options take in a key=value format where the key is a selector for the yaml config structure, for example: decision_logs.reporting.min_delay_seconds=300 is equivalent to JSON {"decision_logs: {"reporting": {"min_delay_seconds: 300}}}. Multiple values can be specified with comma separators (key1=value,key2=value2,..). Or with additional --set parameters.

Example using several different options:

  1. opa run \
  2. --set "default_decision=/http/example/authz/allow" \
  3. --set "services.acmecorp.url=https://test-env/control-plane-api/v1" \
  4. --set "services.acmecorp.credentials.bearer.token=\${TOKEN}"
  5. --set "labels.app=myapp,labels.region=west"

This is equivalent to a YAML config file that looks like:

  1. services:
  2. acmecorp:
  3. url: https://test-env/control-plane-api/v1
  4. credentials:
  5. bearer:
  6. token: ${TOKEN}
  7. labels:
  8. app: myapp
  9. region: west
  10. default_decision: /http/example/authz/allow

The --set-file option is expecting a file path for the value. This allows keeping secrets in files and loading them into the config at run time. For Example:

With a file /var/run/secrets/bearer_token.txt that has contents:

  1. bGFza2RqZmxha3NkamZsa2Fqc2Rsa2ZqYWtsc2RqZmtramRmYWxkc2tm

Then using the --set-file flag for OPA

  1. opa run --set-file "services.acmecorp.credentials.bearer.token=/var/run/secrets/bearer_token.txt"

It will read the contents of the file and set the config value with the token.

Override Limitations
# Lists If using arrays/lists in the configuration the --set and --set-file overrides will not be able to patch sub-objects of the list. They will overwrite the entire index with the new object.

For example, a config.yaml file with contents:

  1. services:
  2. - name: acmecorp
  3. url: https://test-env/control-plane-api/v1
  4. credentials:
  5. bearer:
  6. token: ""

Used with overrides:

  1. opa run \
  2. --config-file config.yaml
  3. --set-file "services[0].credentials.bearer.token=/var/run/secrets/bearer_token.txt"

Will result in configuration like:

  1. services:
  2. - credentials:
  3. bearer:
  4. token: bGFza2RqZmxha3NkamZsa2Fqc2Rsa2ZqYWtsc2RqZmtramRmYWxkc2tm

Because the entire 0 index was overwritten.

It is highly recommended to use objects/maps instead of lists for configuration for this reason.

# Empty objects If you need to set an empty object with the CLI overrides, for example with plugin configuration like:
  1. decision_logger:
  2. plugin: my_plugin
  3. plugins:
  4. my_plugin:
  5. # empty

You can do this by setting the value with null. For example:

  1. opa run --set "decision_logger.plugin=my_plugin" --set "plugins.my_plugin=null"
# Keys with Special Characters

If you have a key which contains a special character (., =, etc), like opa.example.com, and want to use the --set or --set-file options you will need to escape the character with a backslash (\).

For example a config section like:

  1. services:
  2. opa.example.com:
  3. url: https://opa.example.com

Could be specified with something like:

--set services.opa\.example\.com.url=https://opa.example.com

Note that when using it in a shell you may need to put it in quotes or escape the \ character too. For example:

--set services."opa\.example\.com".url=https://opa.example.com

or

--set services.opa\\.example\\.com.url=https://opa.example.com

Where the end result passed into OPA still has the \. preserved.

Services

Services represent endpoints that implement one or more control plane APIs such as the Bundle or Status APIs. OPA configuration files may contain multiple services.

FieldTypeRequiredDescription
services[].namestringYesUnique name for the service. Referred to by plugins.
services[].urlstringYesBase URL to contact the service with.
services[].headersobjectNoHTTP headers to include in requests to the service.
services[].allow_insecure_tlsboolNoAllow insecure TLS.

Each service may optionally specify a credential mechanism by which OPA will authenticate itself to the service.

Bearer token

OPA will authenticate using the specified bearer token and schema; to enable bearer token authentication, the token must be specified. The schema is optional and will default to Bearer if unspecified.

FieldTypeRequiredDescription
services[].credentials.bearer.tokenstringYesEnables token-based authentication and supplies the bearer token to authenticate with.
services[].credentials.bearer.schemestringNoBearer token scheme to specify.

Client TLS certificate

OPA will present the specified TLS certificate to authenticate. The paths to the client certificate and the private key are required; the passphrase for the private key is only required if the private key is encrypted.

FieldTypeRequiredDescription
services[].credentials.client_tls.certstringYesThe path to the client certificate to authenticate with.
services[].credentials.clienttls.private_keystringYesThe path to the private key of the client certificate.
services[].credentials.client_tls.private_key_passphrasestringNoThe passphrase to use for the private key.

AWS signature

OPA will authenticate with an AWS4 HMAC signature. Two methods of obtaining the necessary credentials are available; exactly one must be specified to use the AWS signature authentication method.

If specifying environment_credentials, OPA will expect to find environment variables for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION, in accordance with the convention used by the AWS CLI.

FieldTypeRequiredDescription
services[_].credentials.s3_signing.environment_credentials{}YesEnables AWS signing using environment variables to source the configuration and credentials

If specifying metadata_credentials, OPA will use the AWS metadata services for EC2 or ECS to obtain the necessary credentials when running within a supported virtual machine/container.

To use the EC2 metadata service, the IAM role to use and the AWS region for the resource must both be specified as iam_role and aws_region respectively.

To use the ECS metadata service, specify only the AWS region for the resource as aws_region. ECS containers have at most one associated IAM role.

N.B. Providing a value for iam_role will cause OPA to use the EC2 metadata service even if running inside an ECS container. This may result in unexpected problems if, for example, there is no route to the EC2 metadata service from inside the container or if the IAM role is only available within the container and not from the hosting EC2 instance.

FieldTypeRequiredDescription
services[].credentials.s3_signing.metadata_credentials.aws_regionstringYesThe AWS region to use for the AWS signing service credential method
services[].credentials.s3_signing.metadata_credentials.iam_rolestringNoThe IAM role to use for the AWS signing service credential method

Services can be defined as an array or object. When defined as an object, the object keys override the services[_].name fields. For example:

  1. services:
  2. s1:
  3. url: https://s1/example/
  4. s2:
  5. url: https://s2/

Is equivalent to

  1. services:
  2. - name: s1
  3. url: https://s1/example/
  4. - name: s2
  5. url: https://s2/

Miscellaneous

FieldTypeRequiredDescription
labelsobjectYesSet of key-value pairs that uniquely identify the OPA instance. Labels are included when OPA uploads decision logs and status information.
default_decisionstringNo (default: /system/main)Set path of default policy decision used to serve queries against OPA’s base URL.
default_authorization_decisionstringNo (default: /system/authz/allow)Set path of default authorization decision for OPA’s API.
pluginsobjectNo (default: {})Location for custom plugin configuration. See Plugins for details.

Bundles

Bundles are defined with a key that is the name of the bundle. This name is used in the status API, decision logs, server provenance, etc.

FieldTypeRequiredDescription
bundles[].resourcestringNo (default: bundles/<name>)Resource path to use to download bundle from configured service.
bundles[].servicestringYesName of service to use to contact remote server.
bundles[].polling.min_delay_secondsint64No (default: 60)Minimum amount of time to wait between bundle downloads.
bundles[].polling.max_delay_secondsint64No (default: 120)Maximum amount of time to wait between bundle downloads.

Bundle (Deprecated)

Deprecated in favor of bundles (see above).

FieldTypeRequiredDescription
bundle.namestringYesName of the bundle to download.
bundle.prefixstringNo (default: bundles)Path prefix to use to download bundle from remote server.
bundle.servicestringYesName of service to use to contact remote server.
bundle.polling.min_delay_secondsint64No (default: 60)Minimum amount of time to wait between bundle downloads.
bundle.polling.max_delay_secondsint64No (default: 120)Maximum amount of time to wait between bundle downloads.

Status

FieldTypeRequiredDescription
status.servicestringYesName of service to use to contact remote server.
status.partition_namestringNoPath segment to include in status updates.

Decision Logs

FieldTypeRequiredDescription
decision_logs.servicestringNoName of the service to use to contact remote server. If no plugin is specified, and console logging is disabled, this will default to the first service name defined in the Services configuration.
decision_logs.partition_namestringNoPath segment to include in status updates.
decision_logs.reporting.buffer_size_limit_bytesint64NoDecision log buffer size limit in bytes. OPA will drop old events from the log if this limit is exceeded. By default, no limit is set.
decision_logs.reporting.upload_size_limit_bytesint64No (default: 32768)Decision log upload size limit in bytes. OPA will chunk uploads to cap message body to this limit.
decision_logs.reporting.min_delay_secondsint64No (default: 300)Minimum amount of time to wait between uploads.
decision_logs.reporting.max_delay_secondsint64No (default: 600)Maximum amount of time to wait between uploads.
decision_logs.mask_decisionstringNo (default: system/log/mask)Set path of masking decision.
decision_logs.pluginstringNoUse the named plugin for decision logging. If this field exists, the other configuration fields are not required.
decision_logs.consolebooleanNo (default: false)Log the decisions locally at info level to the console. When enabled alongside a remote decision logging API the service must be configured, the default service selection will be disabled.

Discovery

FieldTypeRequiredDescription
discovery.namestringYesName of the discovery configuration to download.
discovery.prefixstringNo (default: bundles)Path prefix to use to download configuration from remote server.
discovery.decisionstringNo (default: value of discovery.name configuration field)Name of the OPA query that will be used to calculate the configuration
discovery.polling.min_delay_secondsint64No (default: 60)Minimum amount of time to wait between configuration downloads.
discovery.polling.max_delay_secondsint64No (default: 120)Maximum amount of time to wait between configuration downloads.