Newer Version Available
TenantSecret
You can rotate tenant secrets of the Data type once every four hours in a sandbox org or every 24 hours in production orgs. You can rotate tenant secrets of the SearchIndex type one time every seven days.
Supported Calls
create(), query(), retrieve(), update()
Fields
| Field Name | Details |
|---|---|
| Description |
|
| KeyDerivationMode |
|
| RemoteKeyCertificate |
|
| RemoteKeyIdentifier |
|
| RemoteKeyServiceID |
|
| SecretValue |
|
| SecretValueCertificate |
|
| SecretValueHash |
|
| Source |
|
| Status |
You can update the Status field through the API in versions 44.0 or later. |
| Type |
|
| Version |
|
Usage
Use this object to create or update an org-specific tenant secret or customer-supplied key material.
Use your preferred developer environment to run the examples. Use the Salesforce developer Introduction to REST API for basic information on making REST calls into Salesforce. Also, the video How To Use Salesforce APIs Collection With Postman by Sudipta Deb provides step by step instructions on getting started using REST with Salesforce.
Example 1:
Build an automated tenant secret creation and activation solution similar to the following.
- Start by creating an Apex class to create the tenant secret. Specify the value of
the tenant secret to encrypt data of a particular
type.
1global class CreateNewSecret implements Schedulable { 2 global void execute(SchedulableContext SC) { 3 TenantSecret secret = new TenantSecret (); 4 secret.description = 'Created new secret from scheduled job'; 5 secret.type= 'Database'; 6 insert secret; 7 } 8} - Schedule the Apex class to run at the specified interval.
This Apex code only needs to be run a single time to schedule the job. This code runs the job every 90 days.
1CreateNewSecret secret = new CreateNewSecret(); 2String schedule = '0 0 0 1 JAN,APR,JUL,OCT ?'; 3String jobID = system.schedule('Automated secret creation and activation', schedule, secret); - Validate that the job is scheduled.
- Validate that tenant secrets are created after the job is run.
Example 2
Upload a customer-supplied tenant secret.
- Create a certificate that’s compatible with customer-supplied key material. See Generate a BYOK-Compatible Certificate in Salesforce Help.
- Then upload your matching key material and key material hash. Include the unique
name of the compatible certificate. The key material is uploaded in encrypted form.
1TenantSecret secret = new TenantSecret (); 2 secret.description = 'New uploaded secret'; 3 secret.type= 'Data'; 4 secret.SecretValue = ... 5 EncodingUtil.base64Decode('...');; 6 secret.SecretValueCertificate = ...; 7 secret.SecretValueHash = ... 8 EncodingUtil.base64Decode('...'); 9 insert secret;You can use this script to generate a customer-supplied tenant secret and tenant secret hash.
- Validate that the key material is uploaded.
Example 3
Opt out of key derivation on a key-by-key basis when you upload key material. When you upload your key material, specify 'Source':Uploaded and 'KeyDerivationMode':'NONE', and set non-null values for the SecretValueCertificate, SecretValue, and SecretValueHash.
Example 4
Import a tenant secret of the Data type.
1TenantSecret secret = [SELECT Id FROM TenantSecret WHERE Type = 'Data' AND Version = 2];
2secret.SecretValue = "<previously_exported_secret_as_a_String>";
3update secret;Example 5
Export a tenant secret by writing the secret.SecretValue to a file. Here’s an example that uses a tenant secret of the Data type.
1TenantSecret secret = [SELECT SecretValue FROM TenantSecret WHERE Type = 'Data' AND Version = 2];
2secret.SecretValue =...;
3update secret;Example 6
Destroy a tenant secret of the Data type.
1TenantSecret secret = [SELECT Id FROM TenantSecret WHERE Type = 'Data' AND Version = 2];
2secret.SecretValue = NULL;
3secret.Status = Destroyed;
4update secret;Example 7
1TenantSecret secret = [SELECT Id FROM TenantSecret WHERE Type = 'Data' AND Version = 2];
2secret.Status = Destroyed;
3update secret;Example 8
Create a callout connection that fetches a cache-only key tenant secret from a key service outside of Salesforce.
- Make sure that your org has at least one active Data in Salesforce key, either Salesforce-generated or customer-supplied. Then turn on Allow Cache-Only Keys with BYOK from the Advanced Settings page in Setup.
- Create a certificate that’s compatible with customer-supplied key material. See Generate a BYOK-Compatible Certificate in Salesforce Help.
- Create and assemble your key material.
- Create a named credential to serve as your authenticated callout mechanism. You can define your named credential through Setup or directly with Apex. Specify a BYOK-compatible certificate and an HTTPS endpoint.
- Configure the connection to your remote key service. This
connection uses a named credential and its associated certificate to fetch a
specified cache-only key tenant
secret.
1remote_params = { 'Source': 'Remote', 2'RemoteKeyIdentifier': ..., 3'RemoteKeyServiceId': ..., 4'RemoteKeyCertificate': ...} 5 6sf.TenantSecret.create(remote_params)