Skip to main content
// 04 operate

Getting Resource Credentials

How to get the connection details for a resource your application requested, such as a Postgres database or a Valkey cache, and connect to it from your machine.

When your PlatformApplication requests a resource through spec.resourceRequirements, the platform creates its credentials for you. It stores them in a Kubernetes Secret in your application's namespace, and passes them to your app as environment variables. You only need them yourself to connect from your machine, for example with a database client.

Developers can't read Secrets, so there are two ways to get the credentials:

  • On Azure, read them from your application's resources Key Vault, if you have access to it. See Read them from Key Vault.
  • On any cloud, or if you don't have access to the vault, ask an owner of your organization. See Ask an owner.

This applies to every resource you request through spec.resourceRequirements, such as PostgresCluster, PostgresDatabase, PostgresFlexibleServer, and ValkeyCache.

What you get​

Each resource has a set of connection keys. The keys depend on the resource type:

ResourceKeys
PostgresCluster, PostgresDatabase, PostgresFlexibleServerhost, port, username, password, dbname
ValkeyCachehost, port, username, password

For the keys of any other resource, see its page under Application Resources.

Read them from Key Vault​

On Azure, the platform copies the connection keys of every resource your application requested to a Key Vault for your application. The vault is separate from the one behind your application's spec.secrets.

Who can read the vault​

The vault grants the Key Vault Administrator role to these Microsoft Entra ID users and groups:

  • The cluster's admin groups. Their members can read the resources vault of every application on the cluster, not only yours.
  • The users and groups whose object IDs are listed in the admins field of your application's spec.secrets entries.

If you can't open the vault, ask an owner to add your object ID or one of your groups to admins, or to add you to a cluster admin group. You can also ask an owner for the values instead.

Find your vault​

The vault name is generated, so find the vault by its tags:

  • app: your application name followed by -resources, such as orders-service-resources.
  • cluster: the cluster the application runs on, such as example-dev-eastus.

To find the vault in the Azure portal, go to the Key vaults page and filter by the tag app with the value APP_NAME-resources.

To find the vault with the Azure CLI, list the vaults with the matching tag:

az keyvault list \
--subscription SUBSCRIPTION \
--query "[?tags.app=='APP_NAME-resources'].{name:name, cluster:tags.cluster}" \
--output table

Replace the following:

  • SUBSCRIPTION: the name or ID of the cluster's Azure subscription.
  • APP_NAME: the name of your PlatformApplication, which by default matches your repository name.

If your application runs on more than one cluster in the subscription, use the cluster column to pick the environment you want.

Read a value​

Each connection key is a vault secret named PREFIX-KEY, in lowercase with hyphens, where PREFIX is the resource's resourceName, or its envPrefix if it sets one. The name matches the environment variable your app sees. For example, resourceName: orders-db gives orders-db-host, orders-db-password, and so on, for the variables ORDERS_DB_HOST and ORDERS_DB_PASSWORD.

To read a value in the Azure portal, open the vault, go to Objects > Secrets, select the secret, select its current version, and then click Show Secret Value.

To read a value with the Azure CLI, run the following command:

az keyvault secret show \
--vault-name VAULT_NAME \
--name SECRET_NAME \
--query value \
--output tsv

Replace the following:

  • VAULT_NAME: the vault name from the previous step.
  • SECRET_NAME: the secret name, such as orders-db-password.

The command prints a live credential to your terminal. Don't paste it into chat, email, a ticket, a pull request, or an AI tool.

When the values appear and change​

  • The values appear a few minutes after the resource is ready. On a new vault, the first copy can take longer while Azure applies the vault's access.
  • The platform copies the values again every hour, so a rotated credential reaches the vault within an hour.
  • When you remove a resource from spec.resourceRequirements, the platform deletes its values from the vault.
  • If two resources produce the same secret name, for example envPrefix: db on one and resourceName: db on another, the platform copies neither. Give them different prefixes.

Ask an owner​

1. Collect the details​

You need three things for the request. All of them are in your repository's .platform/kubernetes/ folder.

DetailWhere to find itExample
EnvironmentThe cluster you want to connect to: dev, stg, or prd.dev
NamespaceYour application's namespace. By default it matches your repository name.orders-service
Resource nameThe resourceName of the resource in your PlatformApplication's spec.resourceRequirements.orders-db
resourceRequirements:
- resourceType: postgresql
provider: cnpg
resourceName: orders-db # ← the resource name

2. Send the request to an owner​

Copy this message, fill in the three details, and send it to an owner of your organization:

Hi! Could you share the credentials for a resource my application uses?

Environment: dev
Namespace: orders-service
Resource name: orders-db

Please run:

kubectl get secret orders-db-connection -n orders-service \
-o go-template='{{range $k, $v := .data}}{{$k}}: {{$v | base64decode}}{{"\n"}}{{end}}'

and save the output to a 1Password item shared with me. Please don't
paste it into Slack, email, or a ticket.

Docs: https://developer.p6m.dev/docs/platform/application-infrastructure/resource-credentials

For owners​

Whether to share credentials, and for which environments, is your call.

  1. Switch to the cluster for the environment in the request.

  2. Run the kubectl command in the request. The Secret is named <resource name>-connection, in the application's namespace. The command prints each value on its own line. For a Postgres database, the output is similar to the following:

    dbname: orders
    host: orders-db-rw
    password: ••••••••
    port: 5432
    username: orders
  3. Save all the values in a new item in your password manager, and share it with the developer.

Don't send the values over chat, email, a ticket, or a pull request. They're a live login for the resource.

If kubectl returns NotFound, check the resource name and namespace. Then list the connection Secrets in the namespace:

kubectl get secrets -n orders-service | grep -- -connection

Connect from your machine​

How you connect depends on the resource type.

PostgresCluster (provider: cnpg)​

The database runs inside the cluster, so you reach it through a port-forward. host in the credentials is the in-cluster address <resource name>-rw, which only works from inside the cluster.

  1. Switch to the cluster for the environment you want. kubectl uses your current context, so on the wrong cluster the next step fails with NotFound, or connects you to the same database in another environment. Check where you are, and switch if needed:

    kubectl config current-context
    kubectl config use-context <context for dev>
  2. In one terminal, forward a local port to the database's read-write service:

    kubectl port-forward svc/orders-db-rw 5432:5432 -n orders-service

    If something on your machine already uses port 5432, pick another local port, such as 15432:5432, and use it in the next step.

  3. In a second terminal, connect with the dbname, username, and password you got:

    psql "host=localhost port=5432 dbname=orders user=orders"

    psql prompts for the password. Any Postgres client works the same way, with localhost as the host.

PostgresDatabase and PostgresFlexibleServer​

These databases run outside the cluster, and host is the server's own address. Whether you can reach it from your machine depends on your organization's network setup. If a direct connection with the credentials times out, ask the platform team how to reach that server.

ValkeyCache​

A Valkey cache runs inside the cluster in cluster mode, spread across several shards. A port-forward reaches only one node, and the cache sends requests for keys on other shards to node addresses that resolve only inside the cluster. To inspect a cache, ask the platform team.

Inside your application​

You don't need to fetch credentials for your app. The platform passes them to the first container of your workload as environment variables. By default they're named <RESOURCE_NAME>_<KEY>, in upper case with underscores. For orders-db they are:

  • ORDERS_DB_HOST
  • ORDERS_DB_PORT
  • ORDERS_DB_USERNAME
  • ORDERS_DB_PASSWORD
  • ORDERS_DB_DBNAME

If the resource sets envPrefix in spec.resourceRequirements, that value replaces <RESOURCE_NAME>. For example, envPrefix: DB gives DB_HOST, DB_PASSWORD, and so on. See envPrefix in the PlatformApplication reference.

Don't add the resource to spec.secrets. That field is for secret values you write yourself, such as API keys.

If the credentials stop working​

If a stored password is rejected, the resource's credentials have changed, for example because it was created again under a new resource name. On Azure, read the value from Key Vault again. Otherwise, ask an owner to run the command again and update the password manager item.