blackstork-io / fabric

An open-source command-line tool for cybersecurity reporting automation and a configuration language for reusable templates. Reporting-as-Code
https://blackstork.io/fabric/
Apache License 2.0
12 stars 0 forks source link

Expose env variables in the context in a controllable way #202

Closed traut closed 1 week ago

traut commented 1 week ago

Background

It is already possible to use the values of environment variables through env var in HCL. This has a limited use, though, since env var values exist outside the evaluation context and can not be easily filtered/mutated.

Design

Env variables should be available in the evaluation context under .env root key.

To minimize the risk of exposing all environment variables to potentially malicious plugins, we introduce a global configuration argument expose_env_vars_with_prefix.

If expose_env_vars_with_prefix is set, only the env vars that have the prefix in their name are available in the context under .env key.

If expose_env_vars_with_prefix is null, use the default value. If expose_env_vars_with_prefix is an empty string, all env variables are exposed in the context

Example:

fabric {
    expose_env_vars_with_prefix = "FABRIC_"  # default value
}

document "test" {
  content text {
    value = "All env vars in the context: {{ .env | toPrettyJson }}" 
  }
}