Permalink
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (71 sloc) 3.82 KB
---
title: Managing Service Keys
owner: Core Services
---
<strong><%= modified_date %></strong>
This topic describes managing service instance credentials with service keys.
Service keys generate credentials for manually configuring consumers of marketplace services. Once you configure them for your service, local clients, apps in other spaces, or entities outside your deployment can access your service with these keys.
<p class='note'><strong>Note</strong>: Some service brokers do not support service keys. If you want to build a service broker that supports service keys, see <a href="../../services/index.html">Services</a>. If you want to use a service broker that does not support service keys, see <a href="./application-binding.html">Delivering Service Credentials to an Application</a>.</p>
## <a id='create'></a> Create a Service Key ##
To generate credentials for a service instance, use the `cf create-service-key` command:
<pre class="terminal">
$ cf create-service-key MY-SERVICE MY-KEY
Creating service key MY-KEY for service instance MY-SERVICE as me@example.com...
OK
</pre>
Use the `-c` flag to provide service-specific configuration parameters in a valid JSON object, either in-line or in a file.
To provide the JSON object in-line, use the following format:
<pre class="terminal">
$ cf create-service-key MY-SERVICE MY-KEY -c '{"permissions":"read-only"}'
Creating service key MY-KEY for service instance MY-SERVICE as me@example.com...
OK
</pre>
To provide the JSON object as a file, give the absolute or relative path to your JSON file:
<pre class="terminal">
$ cf create-service-key MY-SERVICE MY-KEY -c PATH-TO-JSON-FILE
Creating service key MY-KEY for service instance MY-SERVICE as me@example.com...
OK
</pre>
## <a id='list'></a> List Service Keys for a Service Instance ##
To list service keys for a service instance, use the `cf service-keys` command:
<pre class="terminal">
$ cf service-keys MY-SERVICE
Getting service keys for service instance MY-SERVICE as me@example.com...
name
mykey1
mykey2
</pre>
## <a id='detail'></a>Get Credentials for a Service Key ##
To retrieve credentials for a service key, use the `cf service-key` command:
<pre class="terminal">
$ cf service-key MY-SERVICE MY-KEY
Getting key MY-KEY for service instance MY-SERVICE as me@example.com...
{
uri: foo://user2:pass2@example.com/mydb,
servicename: mydb
}
</pre>
Use the `--guid` flag to display the API GUID for the service key:
<pre class="terminal">
$ cf service-key --guid MY-SERVICE MY-KEY
Getting key MY-KEY for service instance MY-SERVICE as me@example.com...
e3696fcb-7a8f-437f-8692-436558e45c7b
OK
</pre>
## <a id='configure'></a>Configure Credentials for a Service Key ##
Once these credentials are obtained, you can use a local CLI or utility to connect to the service instance, configure an application running outside the platform to connect to the service instance, or create a user-provided service instance so that applications in another space can connect to the service instance. How you configure these credentials will depend on what local client, app, or entity is used to access your service instance.
For more information on configuring credentials with a user-provided service instance, see [User-Provided Service Instances](http://docs.cloudfoundry.org/devguide/services/user-provided.html).
## <a id='delete'></a>Delete a Service Key ##
To delete a service key, use the `cf delete-service-key` command:
<pre class="terminal">
$ cf delete-service-key MY-SERVICE MY-KEY
Are you sure you want to delete the service key MY-KEY ? y
Deleting service key MY-KEY for service instance MY-SERVICE as me@example.com...
OK
</pre>
Add option `-f` to force deletion without confirmation.
<pre class="terminal">
$ cf delete-service-key -f MY-SERVICE MY-KEY
Deleting service key MY-KEY for service instance MY-SERVICE as me@example.com...
OK
</pre>