Supported versions
You can select the major and minor version. Patch versions are applied periodically for bug fixes and the like. When you deploy your app, you always get the latest available patches.Relationship reference
For each service defined via a relationship to your application, Upsun automatically generates corresponding environment variables within your application container, in the$<RELATIONSHIP-NAME>_<SERVICE-PROPERTY> format.
Here is example information available through the service environment variables themselves,
or through the PLATFORM_RELATIONSHIPS environment variable.
- Service environment variables
- `PLATFORM_RELATIONSHIPS` environment variable
You can obtain the complete list of available service environment variables in your app container by running
upsun ssh env.Note that the information about the relationship can change when an app is redeployed or restarted or the relationship is changed. So your apps should only rely on the service environment variables directly rather than hard coding any values.Usage example
1. Configure the service
To define the service, use thevault-kms type:
Note that changing the name of the service replaces it with a brand new service and all existing data is lost.
Back up your data before changing the service.
-
SERVICE_NAMEis the name you choose to identify the service. -
VERSIONis a supported version of the service. -
ENDPOINT_IDis an identifier you choose for the endpoint. -
KEY_NAMEis the name of the key to be stored in the Vault KMS. -
POLICYis one of the available policies based on what you want to accomplish. -
The
typeis one of:sign: for signing payloads, with the typeecdsa-p256encrypt(for encryptchacha20-poly1305).
typecan’t be changed after creation.
2. Define the relationship
To define the relationship, use the following configuration: You can defineSERVICE_NAME as you like, so long as it’s unique between all defined services
and matches in both the application and services configuration.
The example above leverages default endpoint configuration for relationships.
That is, it uses default endpoints behind the scenes, providing a relationship
(the network address a service is accessible from) that is identical to the name of that service.
Depending on your needs, instead of default endpoint configuration,
you can use explicit endpoint configuration.
With the above definition, the application container (APP_NAME) now has access to the service via the relationship <RELATIONSHIP_NAME> and its corresponding service environment variables.
If you split the service into multiple endpoints, define multiple relationships.
Example configuration
.upsun/config.yaml
Multiple endpoints example
.upsun/config.yaml
Use Vault KMS
To connect your app to the Vault KMS, use a token that’s defined in the service environment variables. With this token for authentication, you can use any of the policies you defined in your.upsun/config.yaml file.
You can obtain the complete list of available service environment variables in your app container by running upsun ssh env.
Note that the information about the relationship can change when an app is redeployed or restarted or the relationship is changed. So your apps should only rely on the service environment variables directly rather than hard coding any values.
The following examples use cURL as an example, which you could do in a hook or after accessing your app with SSH.
Adapt the examples for your app’s language.
Get the token
To make any calls to the Vault KMS, you need your token. Get it from the service environment variables:RELATIONSHIP_NAME is the relationship name you defined in your .upsun/config.yaml file.
You can also store this as a variable:
Get the right URL
The service environment variable also contains the information you need to construct a URL for contacting the Vault KMS: thehost and port.
Assign it to a variable as follows:
RELATIONSHIP_NAME is the name you defined in your .upsun/config.yaml file.
Manage your keys
Your key names are defined in your.upsun/config.yaml file. You can manage them if you’ve set an admin policy for them.
To get information on a key, such as its expiration date, run the following command:
$KEY_NAME is the name in your .upsun/config.yaml file.
To rotate the version of your key, run the following command:
Sign and verify payloads
If you’ve set sign and verify policies, you can use your keys to sign and verify various payloads, such as a JSON Web Token (JWT) for authentication in your app. Note that all payloads (all plaintext data) must be base64-encoded. To sign a specific payload, run the following command:data.signature to sign things such as a JWT.
To verify a payload, run the following command:
true value means the signature matches and a false value means it doesn’t.
Encrypt and decrypt data
If you’ve set encrypt and decrypt policies, you can use your keys to encrypt and decrypt any data you want. Note that all of plaintext data you work with must be base64-encoded. To sign a specific payload, run the following command:| jq -r ".data.plaintext" | base64 -d to the end of the curl command.
Rewrap encrypted data
If you have already encrypted data and you have changed your key version, you can rewrap the encrypted data with the new key. Assuming$CIPHERTEXT stores your encrypted data (vault:v1:LEtOWSwh3N...), run the following command:
ciphertext is different (and now includes the new key version as a prefix) as is the key_version:
Policies
| Policy | Endpoint | Capabilities | Purpose |
|---|---|---|---|
admin | transit/keys/${KEY} | read | Access to key properties and various functions performed on keys such as rotation and deletion |
transit/keys/${KEY}/* | read, create, update, delete | ||
sign | transit/sign/${KEY}/${HASH_ALGORITHM} | read, update | Signing payloads with an existing key |
verify | transit/verify/${KEY}/${HASH_ALGORITHM} | read, update | Verifying already signed payloads |
encrypt | transit/encrypt/${KEY} | read, update | Encrypting data with an existing key |
decrypt | transit/decrypt/${KEY} | read, update | Decrypting data with an existing key |
rewrap | transit/rewrap/${KEY} | read, update | Re-encrypting data with a new key version without revealing the secret |