how to save cloud foundry username and password?

1.3k Views Asked by At

I can login to cloud-foundy/bluemix using:

cf login -u my_cf_username -p my_cf_password

I can set up environment variables to store these values (e.g. by setting them in .bashrc or .profile):

export cf_user=my_cf_username
export cf_pass=my_cf_password
cf login -u $cf_user -p $cf_pass

However, ideally I would like the Cloud Foundry username and password to be retrieved from a properties file, e.g. $HOME/.cf - is this possible?

2

There are 2 best solutions below

0
On BEST ANSWER

This isn't possible with the current CF CLI client. It should be possible to write a custom CF CLI Plugin to handle this behaviour.

0
On

If you simply want to avoid the login step, wouldn't a bash script suffice (as suggested in Reading username and password from file and others)?

To the larger question of how to secure credentials beyond logging into the CLI, I recommend Pat Mueller's blog entry How your cloud application should access credentials and other private data: Use a Cloud Foundry user-provided service and bind key/value to it with locally-defined VCAP. He recommends using the cfenv package as shown below:

cfenv = require("cfenv")
var localVCAP = require("./local-vcap.json")
var appEnv = cfenv.getAppEnv({vcap: localVCAP})
var creds  = appEnv.getServiceCreds(/session-secret/) || {}
console.log("session secret is:", creds.secret)

You then create a user-provided service with the cf cups command (cups = create-user-provided-service). To get access to the credentials from a given service, bind the cups to it. He notes several advantages of this approach; I especially like that values are only visible to users who have the appropriate access to the cups service. For more details, see the source article cited above.