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 once every seven days.
Fields
| Field Name | Details |
|---|---|
| Description |
|
| SecretValue |
|
| SecretValueCertificate |
|
| SecretValueHash |
|
| Status |
|
| Type |
|
| Version |
|
Usage
Use this object to create or update an org-specific tenant secret. For example, you can build an automated tenant secret creation and activation solution similar to the following.
- Start by creating an Apex class to create the new 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= ‘SearchIndex’; 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.
- Create a certificate that is compatible with customer-supplied (BYOK) tenant secrets. See “Generate a BYOK-Compatible Certificate” in the Platform Encryption REST API Developer Guide.
- Then upload your matching tenant secret and tenant secret hash. Include the unique name of the compatible certificate. The tenant secret
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 tenant secret is uploaded.
Here’s an example of how to 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;You can also export a tenant secret by writing the secret.SecretValue to a file. Here’s an example that uses a tenant secret of the SearchIndex type.
1TenantSecret secret = [SELECT SecretValue FROM TenantSecret WHERE Type = ‘TenantSecret’ AND Version = 2];
2secret.SecretValue =...;
3update secret;Here’s an example of how to destroy a tenant secret of the Data type.
1TenantSecret secret = [SELECT Id FROM TenantSecret WHERE Type = ‘Data’ AND Version = 2];
2secret.SecretValue = NULL;
3update secret;