How to change credentials for a given service in Cloud Foundry












0















I would like to know how (and if it's possible) to change the URI credentials from a service in Cloud Foundry. More specifically, mLab service (free plan) from Pivotal Cloud Foundry.





Background



I created and pushed a nodejs app to Pivotal Cloud Foundry.



This app is bound to a mLab service using free plan.



When the mLab service was created using Pivotal website, it created a database with an user and password automatically.



Opening app settings inside Pivotal website, I can see the following environment variables. Please notice the mongo uri inside credentials and name inside mLab.



{
"staging_env_json": {},
"running_env_json": {},
"system_env_json": {
"VCAP_SERVICES": {
"mlab": [
{
"label": "mlab",
"provider": null,
"plan": "sandbox",
"name": "users",
"instance_name": "users",
"binding_name": null,
"credentials": {
"uri": "mongodb://CloudFoundry_someusergenerated:apasswordgeneratedautomatically@somehost.mlab.com:someport/CloudFoundry_database_name"
}
}
]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
"cf_api": "https://donotuseapi.run.pivotal.io",
"application_name": "website",
"application_uris": [
"xxx.cfapps.io"
],
"name": "website",
"space_name": "space1",
"uris": [
"xxx.cfapps.io"
]
}
}
}


The connection with the database works fine with this default user and password. In order to get the mongodb uri from the environment variables, I am using npm package cfenv



const appEnv = require('cfenv').getAppEnv();
const env = process.env;
keys = {
mongodb: {
dbURI: appEnv.getServiceURL(env.MONGO_SERVICE_NAME)
}
};


In my manifest.yaml file I have this MONGO_SERVICE_NAME specified accordingly with the service name inside the environment variables.



---
applications:
- name: website
memory: 128M
disk_quota: 256M
random-route: true
buildpack: nodejs_buildpack
health-check-type: port
env:
MONGO_SERVICE_NAME: 'users'


Again, the db connection works fine.



===



Then I opened mLab website for this particular database and created a new database user.



Now I want to update the credentials.uri from VCAP_SERVICES (environment variables) for this particular service to use the new user and password.



As far as I coould see, cf update-service CLI command is not meant by that so I am wondering if this is a limitation from Cloud Foundry, Pivotal or mLab. I could bet that this limitation is due to the fact I am using Pivotal trial account and mLab free plan, however my question still the same if I upgrade plans.



Thanks,










share|improve this question























  • Just unbind and rebind it, I would expect that to generate a new set of credentials.

    – jonrsharpe
    Nov 16 '18 at 9:31











  • I would like to use the credentials manually created inside mLab website

    – fabiopagoti
    Nov 16 '18 at 9:32






  • 1





    Why? The whole point of binding services is that you don't have to worry about that.

    – jonrsharpe
    Nov 16 '18 at 9:32






  • 1





    What "fine control" are you looking for? And no, it doesn't change VCAP_SERVICES, because the point of that env var is to reflect the actual bound services.

    – jonrsharpe
    Nov 16 '18 at 9:45








  • 1





    Some services accept parameters when bound, see e.g. cli.cloudfoundry.org/en-US/cf/bind-service.html. I don't know if MLab does, but as far as I'm aware that's the only configuration you can provide that might alter the binding credentials.

    – jonrsharpe
    Nov 16 '18 at 9:56
















0















I would like to know how (and if it's possible) to change the URI credentials from a service in Cloud Foundry. More specifically, mLab service (free plan) from Pivotal Cloud Foundry.





Background



I created and pushed a nodejs app to Pivotal Cloud Foundry.



This app is bound to a mLab service using free plan.



When the mLab service was created using Pivotal website, it created a database with an user and password automatically.



Opening app settings inside Pivotal website, I can see the following environment variables. Please notice the mongo uri inside credentials and name inside mLab.



{
"staging_env_json": {},
"running_env_json": {},
"system_env_json": {
"VCAP_SERVICES": {
"mlab": [
{
"label": "mlab",
"provider": null,
"plan": "sandbox",
"name": "users",
"instance_name": "users",
"binding_name": null,
"credentials": {
"uri": "mongodb://CloudFoundry_someusergenerated:apasswordgeneratedautomatically@somehost.mlab.com:someport/CloudFoundry_database_name"
}
}
]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
"cf_api": "https://donotuseapi.run.pivotal.io",
"application_name": "website",
"application_uris": [
"xxx.cfapps.io"
],
"name": "website",
"space_name": "space1",
"uris": [
"xxx.cfapps.io"
]
}
}
}


The connection with the database works fine with this default user and password. In order to get the mongodb uri from the environment variables, I am using npm package cfenv



const appEnv = require('cfenv').getAppEnv();
const env = process.env;
keys = {
mongodb: {
dbURI: appEnv.getServiceURL(env.MONGO_SERVICE_NAME)
}
};


In my manifest.yaml file I have this MONGO_SERVICE_NAME specified accordingly with the service name inside the environment variables.



---
applications:
- name: website
memory: 128M
disk_quota: 256M
random-route: true
buildpack: nodejs_buildpack
health-check-type: port
env:
MONGO_SERVICE_NAME: 'users'


Again, the db connection works fine.



===



Then I opened mLab website for this particular database and created a new database user.



Now I want to update the credentials.uri from VCAP_SERVICES (environment variables) for this particular service to use the new user and password.



As far as I coould see, cf update-service CLI command is not meant by that so I am wondering if this is a limitation from Cloud Foundry, Pivotal or mLab. I could bet that this limitation is due to the fact I am using Pivotal trial account and mLab free plan, however my question still the same if I upgrade plans.



Thanks,










share|improve this question























  • Just unbind and rebind it, I would expect that to generate a new set of credentials.

    – jonrsharpe
    Nov 16 '18 at 9:31











  • I would like to use the credentials manually created inside mLab website

    – fabiopagoti
    Nov 16 '18 at 9:32






  • 1





    Why? The whole point of binding services is that you don't have to worry about that.

    – jonrsharpe
    Nov 16 '18 at 9:32






  • 1





    What "fine control" are you looking for? And no, it doesn't change VCAP_SERVICES, because the point of that env var is to reflect the actual bound services.

    – jonrsharpe
    Nov 16 '18 at 9:45








  • 1





    Some services accept parameters when bound, see e.g. cli.cloudfoundry.org/en-US/cf/bind-service.html. I don't know if MLab does, but as far as I'm aware that's the only configuration you can provide that might alter the binding credentials.

    – jonrsharpe
    Nov 16 '18 at 9:56














0












0








0








I would like to know how (and if it's possible) to change the URI credentials from a service in Cloud Foundry. More specifically, mLab service (free plan) from Pivotal Cloud Foundry.





Background



I created and pushed a nodejs app to Pivotal Cloud Foundry.



This app is bound to a mLab service using free plan.



When the mLab service was created using Pivotal website, it created a database with an user and password automatically.



Opening app settings inside Pivotal website, I can see the following environment variables. Please notice the mongo uri inside credentials and name inside mLab.



{
"staging_env_json": {},
"running_env_json": {},
"system_env_json": {
"VCAP_SERVICES": {
"mlab": [
{
"label": "mlab",
"provider": null,
"plan": "sandbox",
"name": "users",
"instance_name": "users",
"binding_name": null,
"credentials": {
"uri": "mongodb://CloudFoundry_someusergenerated:apasswordgeneratedautomatically@somehost.mlab.com:someport/CloudFoundry_database_name"
}
}
]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
"cf_api": "https://donotuseapi.run.pivotal.io",
"application_name": "website",
"application_uris": [
"xxx.cfapps.io"
],
"name": "website",
"space_name": "space1",
"uris": [
"xxx.cfapps.io"
]
}
}
}


The connection with the database works fine with this default user and password. In order to get the mongodb uri from the environment variables, I am using npm package cfenv



const appEnv = require('cfenv').getAppEnv();
const env = process.env;
keys = {
mongodb: {
dbURI: appEnv.getServiceURL(env.MONGO_SERVICE_NAME)
}
};


In my manifest.yaml file I have this MONGO_SERVICE_NAME specified accordingly with the service name inside the environment variables.



---
applications:
- name: website
memory: 128M
disk_quota: 256M
random-route: true
buildpack: nodejs_buildpack
health-check-type: port
env:
MONGO_SERVICE_NAME: 'users'


Again, the db connection works fine.



===



Then I opened mLab website for this particular database and created a new database user.



Now I want to update the credentials.uri from VCAP_SERVICES (environment variables) for this particular service to use the new user and password.



As far as I coould see, cf update-service CLI command is not meant by that so I am wondering if this is a limitation from Cloud Foundry, Pivotal or mLab. I could bet that this limitation is due to the fact I am using Pivotal trial account and mLab free plan, however my question still the same if I upgrade plans.



Thanks,










share|improve this question














I would like to know how (and if it's possible) to change the URI credentials from a service in Cloud Foundry. More specifically, mLab service (free plan) from Pivotal Cloud Foundry.





Background



I created and pushed a nodejs app to Pivotal Cloud Foundry.



This app is bound to a mLab service using free plan.



When the mLab service was created using Pivotal website, it created a database with an user and password automatically.



Opening app settings inside Pivotal website, I can see the following environment variables. Please notice the mongo uri inside credentials and name inside mLab.



{
"staging_env_json": {},
"running_env_json": {},
"system_env_json": {
"VCAP_SERVICES": {
"mlab": [
{
"label": "mlab",
"provider": null,
"plan": "sandbox",
"name": "users",
"instance_name": "users",
"binding_name": null,
"credentials": {
"uri": "mongodb://CloudFoundry_someusergenerated:apasswordgeneratedautomatically@somehost.mlab.com:someport/CloudFoundry_database_name"
}
}
]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
"cf_api": "https://donotuseapi.run.pivotal.io",
"application_name": "website",
"application_uris": [
"xxx.cfapps.io"
],
"name": "website",
"space_name": "space1",
"uris": [
"xxx.cfapps.io"
]
}
}
}


The connection with the database works fine with this default user and password. In order to get the mongodb uri from the environment variables, I am using npm package cfenv



const appEnv = require('cfenv').getAppEnv();
const env = process.env;
keys = {
mongodb: {
dbURI: appEnv.getServiceURL(env.MONGO_SERVICE_NAME)
}
};


In my manifest.yaml file I have this MONGO_SERVICE_NAME specified accordingly with the service name inside the environment variables.



---
applications:
- name: website
memory: 128M
disk_quota: 256M
random-route: true
buildpack: nodejs_buildpack
health-check-type: port
env:
MONGO_SERVICE_NAME: 'users'


Again, the db connection works fine.



===



Then I opened mLab website for this particular database and created a new database user.



Now I want to update the credentials.uri from VCAP_SERVICES (environment variables) for this particular service to use the new user and password.



As far as I coould see, cf update-service CLI command is not meant by that so I am wondering if this is a limitation from Cloud Foundry, Pivotal or mLab. I could bet that this limitation is due to the fact I am using Pivotal trial account and mLab free plan, however my question still the same if I upgrade plans.



Thanks,







cloudfoundry mlab pivotal-cloud-foundry






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 9:30









fabiopagotifabiopagoti

879927




879927













  • Just unbind and rebind it, I would expect that to generate a new set of credentials.

    – jonrsharpe
    Nov 16 '18 at 9:31











  • I would like to use the credentials manually created inside mLab website

    – fabiopagoti
    Nov 16 '18 at 9:32






  • 1





    Why? The whole point of binding services is that you don't have to worry about that.

    – jonrsharpe
    Nov 16 '18 at 9:32






  • 1





    What "fine control" are you looking for? And no, it doesn't change VCAP_SERVICES, because the point of that env var is to reflect the actual bound services.

    – jonrsharpe
    Nov 16 '18 at 9:45








  • 1





    Some services accept parameters when bound, see e.g. cli.cloudfoundry.org/en-US/cf/bind-service.html. I don't know if MLab does, but as far as I'm aware that's the only configuration you can provide that might alter the binding credentials.

    – jonrsharpe
    Nov 16 '18 at 9:56



















  • Just unbind and rebind it, I would expect that to generate a new set of credentials.

    – jonrsharpe
    Nov 16 '18 at 9:31











  • I would like to use the credentials manually created inside mLab website

    – fabiopagoti
    Nov 16 '18 at 9:32






  • 1





    Why? The whole point of binding services is that you don't have to worry about that.

    – jonrsharpe
    Nov 16 '18 at 9:32






  • 1





    What "fine control" are you looking for? And no, it doesn't change VCAP_SERVICES, because the point of that env var is to reflect the actual bound services.

    – jonrsharpe
    Nov 16 '18 at 9:45








  • 1





    Some services accept parameters when bound, see e.g. cli.cloudfoundry.org/en-US/cf/bind-service.html. I don't know if MLab does, but as far as I'm aware that's the only configuration you can provide that might alter the binding credentials.

    – jonrsharpe
    Nov 16 '18 at 9:56

















Just unbind and rebind it, I would expect that to generate a new set of credentials.

– jonrsharpe
Nov 16 '18 at 9:31





Just unbind and rebind it, I would expect that to generate a new set of credentials.

– jonrsharpe
Nov 16 '18 at 9:31













I would like to use the credentials manually created inside mLab website

– fabiopagoti
Nov 16 '18 at 9:32





I would like to use the credentials manually created inside mLab website

– fabiopagoti
Nov 16 '18 at 9:32




1




1





Why? The whole point of binding services is that you don't have to worry about that.

– jonrsharpe
Nov 16 '18 at 9:32





Why? The whole point of binding services is that you don't have to worry about that.

– jonrsharpe
Nov 16 '18 at 9:32




1




1





What "fine control" are you looking for? And no, it doesn't change VCAP_SERVICES, because the point of that env var is to reflect the actual bound services.

– jonrsharpe
Nov 16 '18 at 9:45







What "fine control" are you looking for? And no, it doesn't change VCAP_SERVICES, because the point of that env var is to reflect the actual bound services.

– jonrsharpe
Nov 16 '18 at 9:45






1




1





Some services accept parameters when bound, see e.g. cli.cloudfoundry.org/en-US/cf/bind-service.html. I don't know if MLab does, but as far as I'm aware that's the only configuration you can provide that might alter the binding credentials.

– jonrsharpe
Nov 16 '18 at 9:56





Some services accept parameters when bound, see e.g. cli.cloudfoundry.org/en-US/cf/bind-service.html. I don't know if MLab does, but as far as I'm aware that's the only configuration you can provide that might alter the binding credentials.

– jonrsharpe
Nov 16 '18 at 9:56












1 Answer
1






active

oldest

votes


















0














As a user, it's not possible for you to change VCAP_SERVICES entries that are generated by a service brokers. These are fixed and not possible to change.



If you cf create-service'd a service, then it was created by a service broker and you get exactly what the service provider gives you. As was mentioned in the comments, depending on the service broker you may be able to pass arguments to the broker with cf create-service -c. Check the documentation of your service provider to see if there is an option to influence the credentials generated in the way that you would like.



If your service provider does not provide options to do what you want, you can create a service key instead of binding your service to an app. This will give you a set of credentials to your service that will last for the duration of the service key. The service key credentials are not automatically passed into an app, but you can feed them into your app in a variety of ways.




  1. You can pass them in through environment variables.

  2. You can create a user provided service (cf cups).

  3. You can pass them through in application config or through a config server.


With all of these options, you are passing the credentials through to the app so you could in theory adjust or alter them before they get to your app.



Hope that helps!






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334932%2fhow-to-change-credentials-for-a-given-service-in-cloud-foundry%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As a user, it's not possible for you to change VCAP_SERVICES entries that are generated by a service brokers. These are fixed and not possible to change.



    If you cf create-service'd a service, then it was created by a service broker and you get exactly what the service provider gives you. As was mentioned in the comments, depending on the service broker you may be able to pass arguments to the broker with cf create-service -c. Check the documentation of your service provider to see if there is an option to influence the credentials generated in the way that you would like.



    If your service provider does not provide options to do what you want, you can create a service key instead of binding your service to an app. This will give you a set of credentials to your service that will last for the duration of the service key. The service key credentials are not automatically passed into an app, but you can feed them into your app in a variety of ways.




    1. You can pass them in through environment variables.

    2. You can create a user provided service (cf cups).

    3. You can pass them through in application config or through a config server.


    With all of these options, you are passing the credentials through to the app so you could in theory adjust or alter them before they get to your app.



    Hope that helps!






    share|improve this answer




























      0














      As a user, it's not possible for you to change VCAP_SERVICES entries that are generated by a service brokers. These are fixed and not possible to change.



      If you cf create-service'd a service, then it was created by a service broker and you get exactly what the service provider gives you. As was mentioned in the comments, depending on the service broker you may be able to pass arguments to the broker with cf create-service -c. Check the documentation of your service provider to see if there is an option to influence the credentials generated in the way that you would like.



      If your service provider does not provide options to do what you want, you can create a service key instead of binding your service to an app. This will give you a set of credentials to your service that will last for the duration of the service key. The service key credentials are not automatically passed into an app, but you can feed them into your app in a variety of ways.




      1. You can pass them in through environment variables.

      2. You can create a user provided service (cf cups).

      3. You can pass them through in application config or through a config server.


      With all of these options, you are passing the credentials through to the app so you could in theory adjust or alter them before they get to your app.



      Hope that helps!






      share|improve this answer


























        0












        0








        0







        As a user, it's not possible for you to change VCAP_SERVICES entries that are generated by a service brokers. These are fixed and not possible to change.



        If you cf create-service'd a service, then it was created by a service broker and you get exactly what the service provider gives you. As was mentioned in the comments, depending on the service broker you may be able to pass arguments to the broker with cf create-service -c. Check the documentation of your service provider to see if there is an option to influence the credentials generated in the way that you would like.



        If your service provider does not provide options to do what you want, you can create a service key instead of binding your service to an app. This will give you a set of credentials to your service that will last for the duration of the service key. The service key credentials are not automatically passed into an app, but you can feed them into your app in a variety of ways.




        1. You can pass them in through environment variables.

        2. You can create a user provided service (cf cups).

        3. You can pass them through in application config or through a config server.


        With all of these options, you are passing the credentials through to the app so you could in theory adjust or alter them before they get to your app.



        Hope that helps!






        share|improve this answer













        As a user, it's not possible for you to change VCAP_SERVICES entries that are generated by a service brokers. These are fixed and not possible to change.



        If you cf create-service'd a service, then it was created by a service broker and you get exactly what the service provider gives you. As was mentioned in the comments, depending on the service broker you may be able to pass arguments to the broker with cf create-service -c. Check the documentation of your service provider to see if there is an option to influence the credentials generated in the way that you would like.



        If your service provider does not provide options to do what you want, you can create a service key instead of binding your service to an app. This will give you a set of credentials to your service that will last for the duration of the service key. The service key credentials are not automatically passed into an app, but you can feed them into your app in a variety of ways.




        1. You can pass them in through environment variables.

        2. You can create a user provided service (cf cups).

        3. You can pass them through in application config or through a config server.


        With all of these options, you are passing the credentials through to the app so you could in theory adjust or alter them before they get to your app.



        Hope that helps!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 3:54









        Daniel MikusaDaniel Mikusa

        6,19511015




        6,19511015
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334932%2fhow-to-change-credentials-for-a-given-service-in-cloud-foundry%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine