Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add private information to OpenShift environment variables?

Authentication information such as database connection strings or passwords should almost never be stored in version control systems.

It looks like the only method of specifying environment variables for an app hosted on OpenShift is to commit them to the Git repository. There is a discussion about this on the OpenShift forums, but no useful suggested workarounds for the problem.

Is there another approach I can use to add authentication information to my app without having to commit it to the repository?

like image 822
drzax Avatar asked Nov 27 '12 10:11

drzax


People also ask

Are environment variables private?

Simple answer is YES, . env is used to store keys and secrets. It is not pushed to your repo i.e. github or bitbucket or anywhere you store your code. In that way it is not exposed.

How do you add variables to an environment?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.

Which command can be used to list a pod's environmental variables?

OpenShift Container Platform provides the oc set env command to set or unset environment variables for objects that have a pod template, such as replication controllers or deployment configurations. It can also list environment variables in pods or any object that has a pod template.

How do I add an environment variable to a pod?

When you create a Pod, you can set environment variables for the containers that run in the Pod. To set environment variables, include the env or envFrom field in the configuration file. In your shell, run the printenv command to list the environment variables. To exit the shell, enter exit .

How do I set environment variables in OpenShift?

Setting and Unsetting Environment Variables OpenShift Container Platform provides the oc set env command to set or unset environment variables for objects that have a pod template, such as replication controllers or deployment configurations. It can also list environment variables in pods or any object that has a pod template.

How do I set the OpenShift Container Platform core components to private?

After you install an OpenShift Container Platform version 4.5 cluster, you can set some of its core components to be private. You can configure this change for only clusters that use infrastructure that you provision to a cloud provider. By default, OpenShift Container Platform is provisioned using publicly-accessible DNS and endpoints.

How do I set up OpenShift enterprise?

In order to set up enterprise OpenShift, one needs to have an active Red Hat account. As OpenShift works on Kubernetes master and node architecture, we need to set up both of them on separate machines, wherein one machine acts as a master and other works on the node.

What is a secret in OpenShift?

This topic discusses important properties of secrets and provides an overview on how developers can use them. The Secret object type provides a mechanism to hold sensitive information such as passwords, OpenShift Container Platform client configuration files, dockercfg files, private source repository credentials, and so on.


2 Answers

SSH into you application and navigate to your data directory

cd app-root/data

in this directory create a file with your variables (e.g. ".myenv") with content like

export MY_VAR="something"

and then in your repository in ".openshift/action_hooks/pre_start" add this line

source ${OPENSHIFT_DATA_DIR}/.myenv
like image 91
Marek Jelen Avatar answered Sep 20 '22 08:09

Marek Jelen


Openshift supports now setting environment vaiables with the rhc commandline tool like this:

rhc set-env HEROKU_POSTGRESQL_DB_URL='jdbc:postgresql://myurl' -a myapp

I think thats way easier than all the other answers...

See: https://blog.openshift.com/taking-advantage-of-environment-variables-in-openshift-php-apps/

like image 28
jbandi Avatar answered Sep 19 '22 08:09

jbandi