Skip to content
ricochet

Environment Variables

Environment variables are key-value pairs that change how your content behaves at runtime. You set them in the ricochet UI or through the REST API.

During development you may keep secrets in a .Renviron or .env file. These files should not be deployed with your content item, and the ricochet CLI leaves them out of a deployment. Ricochet encrypts environment variables at rest and decrypts them only before it starts a process.

Any change to an environment variable stops all running instances, so future requests use the new value.

To read a value from HashiCorp Vault, OpenBao or Azure Key Vault instead of storing it in ricochet, see Integrations.

Open your content item and select the “Environment Variables” tab. Here you can add or remove environment variables.

The Key is the name of the environment variable. Value is its value.

Press ”+ Add Variable” to save the environment variable.

New processes get the new environment variables.

No value is ever sent in plain text. You must encrypt both the names and the values before you send them to the API. To do this, fetch the server’s public key, RSA encrypt each name and value with it, and put the results in the JSON body.

Terminal window
# fetch the server's public key
curl -s https://try.ricochet.rs/api/v0/public-key -o ricochet.pub
# encrypt one name or value
encrypt() {
printf '%s' "$1" | openssl pkeyutl -encrypt -pubin -inkey ricochet.pub \
-pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 | openssl base64 -A
}
# add or update ENV_NAME and leave the other variables in place
curl -X PATCH \
'https://try.ricochet.rs/api/v0/content/01JSZAXZ3TSTAYXP56ARDVFJCJ/env-vars' \
-H 'Authorization: Key rico_xxxxx' \
-H 'Content-Type: application/json' \
-d "{\"$(encrypt ENV_NAME)\": \"$(encrypt ENV_VALUE)\"}"

The encrypt function above handles names and values up to 190 bytes. For a longer value, such as a service account key, use one of these functions. Each returns the encrypted name and value to send in the JSON body.

encrypt <- function(key, value, host = "https://try.ricochet.rs") {
pub_key <- httr2::request(host) |>
httr2::req_url_path_append("/api/v0/public-key") |>
httr2::req_perform() |>
httr2::resp_body_string() |>
openssl::read_pubkey()
# encrypt the key
key_encrypted <- b64::encode(
openssl::rsa_encrypt(
charToRaw(key),
pub_key
)
)
# encrypt the value
key <- openssl::rand_bytes(32)
nonce <- openssl::rand_bytes(12)
sealed <- c(nonce, openssl::aes_gcm_encrypt(charToRaw(value), key, nonce))
wrapped <- openssl::rsa_encrypt(key, pub_key)
value <- sprintf(
"v2:%s:%s",
openssl::base64_encode(wrapped),
openssl::base64_encode(sealed)
)
list(key = key_encrypted, value = value)
}
encrypt("key", "value")

Every endpoint expects encrypted environment variables.

MethodPathEffect
GET/api/v0/content/{id}/env-varsList the names
PATCH/api/v0/content/{id}/env-varsAdd or update the variables sent and keep the rest
PUT/api/v0/content/{id}/env-varsReplace the whole set and delete anything not sent
DELETE/api/v0/content/{id}/env-vars/{name}Remove one variable

You cannot read the raw values through the API. The GET endpoint returns only the names of the keys.

A name may be at most 190 bytes and a value at most 64 KiB.

Keys may only consist of ASCII letters, numbers, and underscores.

To read an environment variable in R, use Sys.getenv("KEY_NAME"). In Julia, use the built-in dictionary ENV["KEY_NAME"].