Zum Inhalt springen

Manage environment variables and secrets

Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen

In this Topic you will learn how to handle environment variables and secrets in your Cloud Foundry Space. Environment Variables are the way on which you and the Platform can communicate with your application. Cloud Foundry or you can set environment variables that are then read by the application in the staging process and can therefore be used within the application.

Once you are logged in to your space with the CF CLI, you can easily read out the environment variables of your application via the command:

Terminal window
cf env

This command will then output all the environment variables that consist out of the 3 following types:

  • VCAP_APPLICATION - a list of system set environment variables around your application
  • VCAP_SERVICES - a list of system set environment variables around your bound dataservices
  • user-provided variables set by users in at least the space-developer role

Additionally there might be some platform-specific Environment Variables set by the STACKIT Cloud Foundry Platform Operators in so called environment variable groups. You can learn more about system variables in Cloud Foundry’s official documentation.

Set and unset environment variables via CF CLI

Section titled “Set and unset environment variables via CF CLI”

Once you are logged in to your space with the CF CLI, you can easily set environment variables of your application via the command:

Terminal window
cf set-env <APP_NAME> <ENV_VAR_NAME> <ENV_VAR_VALUE>

After setting new environment variables you have to restage your application in order for it to read out the new variables. You can simply restage your application with:

Terminal window
cf restage <APP_NAME>

You can unset your environment variables again with the following command:

Terminal window
cf unset-env <APP_NAME> <ENV_VAR_NAME> <ENV_VAR_VALUE>

Afterwards you have to restage your application again.

Set environment variables via the manifest-file

Section titled “Set environment variables via the manifest-file”

You can also set environment variables via the manifest-file when pushing your application to the Cloud Foundry.

Just add it to to an env-Block in the manifest.yml, like in the following example:

---
...
env:
RAILS_ENV: production
RACK_ENV: production

The Cloud Foundry stores the configuration for an app in an encrypted database table. This configuration data includes user-specified environment variables and service credentials for any services bound to the app.

All apps are running inside a secure container. For more information, see the Cloud Foundry documentation about container security.

So your environment variables are secured. This secure state of all of your environment variables is also the reason, why Cloud Foundry stores the connection credentials to your bound dataservices in those environment variables aswell.