Secrets
When you make calls to the Unstructured Workflow Endpoint, you might need to include a secret as part of the request. This secret is typically something such as the contents of a private key file that a third-party service requires for programmatic authentication. These secrets are typically required when creating source connectors or destination connectors that work with specific third-party services.
Instead of programmatically sending a secret to Unstructured in plain text, which presents a security risk, you must instead follow Unstructured’s process for more securely sending the secret as follows:
- Call Unstructured to get the Privacy Enhanced Mail (PEM) version of the public key for your Unstructured user account.
- Use this PEM to encrypt your plain-text secret locally.
- Register the encrypted version of the secret with your Unstructured account. Unstructured returns a unique ID for the registered secret, along with the type of encryption that was used.
- Specify the registered secret’s ID and encryption type in the call to the Unstructured Workflow Endpoint as needed.
The source and destination connectors that require you to follow this process currently include the following:
Unstructured plans to add this requirement to other source and destination connectors in the future.
The following sections describe how to complete the preceding process.
Requirements
While you can use a REST API client such as curl
or Postman to complete most of the following steps, you can only use Python to
complete the step of encrypting the plain-text secret locally. Otherwise, both approaches are shown for the other steps.
To complete the following steps, you must have the following:
-
Python installed on your local development machine.
-
The
unstructured-client
package installed into your Python virtual environment. -
Optionally, a REST API client such as
curl
or Postman installed on your local development machine. -
An Unstructured account, including a valid Unstructured API key for that account. To get your API key, do the following:
-
Sign in to your Unstructured account:
- If you do not already have an Unstructured account, go to https://unstructured.io/contact and fill out the online form to indicate your interest.
- If you already have an Unstructured account, sign in by using the URL of the sign in page that Unstructured provided to you when your Unstructured account was created. After you sign in, the Unstructured user interface (UI) then appears, and you can start using it right away. If you do not have this URL, contact Unstructured Sales at sales@unstructured.io.
-
Get your Unstructured API key:
a. In the Unstructured UI, click API Keys on the sidebar.
b. Click Generate API Key.
c. Follow the on-screen instructions to finish generating the key.
d. Click the Copy icon next to your new key to add the key to your system’s clipboard. If you lose this key, simply return and click the Copy icon again.
-
-
Some of the following steps also require you to specify the Unstructured Workflow Endpoint API URL for your Unstructured user account. This URL was provided to you when your Unstructured account was created. If you do not have this URL, contact Unstructured Sales at sales@unstructured.io.
The default URL for the Unstructured Worfklow Endpoint is
https://platform.unstructuredapp.io/api/v1
. However, you should always use the URL that was provided to you when your Unstructured account was created. -
The following steps assume that you have the following two environment variables set locally:
UNSTRUCTURED_API_URL
, set to the Workflow Endpoint API URL for your Unstructured user account.UNSTRUCTURED_API_KEY
, set to the API key for your Unstructured user account.
Step 1: Get the PEM version of the public key
In this step, you call the Unstructured Workflow Endpoint to get the PEM version of the public key for your
Unstructured user account. The result is a string that begins with -----BEGIN PUBLIC KEY-----
and ends with
-----END PUBLIC KEY-----
.
Python
Python
The output looks similar to the following:
curl
curl
The output looks similar to the following. Line breaks and whitespace have been added to the output for readability:
Copy only the contents of the pem_key
field from the output. Ignore the tenant_id
and user_id
fields.
Postman
Postman
-
In the method drop-down list, select POST.
-
In the address box, enter the following URL:
-
On the Headers tab, enter the following headers:
- Key:
unstructured-api-key
, Value:{{UNSTRUCTURED_API_KEY}}
- Key:
accept
, Value:application/json
- Key:
-
Click Send.
The response body looks similar to the following:
-
Copy only the contents of the
pem_key
field from the response body. Ignore thetenant_id
anduser_id
fields.
Step 2: Encrypt the secret
In this step, you use the PEM version of the public key for your Unstructured user account that you got from
the previous step to encrypt the target plain-text secret. The result is a JSON-formatted object that contains
keys named encrypted_aes_key
, aes_iv
, encrypted_value
, and type
. All of the keys’ values except the one for type
are
Base64-encoded.
This step can be completed only by using Python on your local development machine.
Python
Python
The following code requires you to install the cryptography
package into your
Python virtual environment.
The following envelope_encrypt
function encrypts the target plain-text string by using envelope encryption. You must supply the function with the
PEM version of the public key for your Unstructured user account that you got from the previous step, and the plain-text version
of the secret that you want to encrypt.
You could call the preceding envelope_encrypt
function with code similar to the following. This code gets
the plain-text contents of the specified service account key file for
a Google Cloud service account. The code then encrypts the plain-text contents
by using the PEM version of the public key file for the user in the Unstructured account.
The output looks similar to the following:
Step 3: Register the encrypted secret
In this step, you call the Unstructured Workflow Endpoint again, this time to register the encrypted secret that you got from
the previous step. The result is a JSON-formatted object that contains keys named id
and type
.
Python
Python
The output looks similar to the following:
curl
curl
The output looks similar to the following. Line breaks and whitespace have been added to the output for readability:
Postman
Postman
-
In the method drop-down list, select POST.
-
In the address box, enter the following URL:
-
On the Headers tab, enter the following headers:
- Key:
unstructured-api-key
, Value:{{UNSTRUCTURED_API_KEY}}
- Key:
accept
, Value:application/json
- Key:
Content-Type
, Value:application/json
- Key:
-
On the Body tab, select raw and JSON, and specify the encrypted secret, for example:
-
Click Send.
The response body looks similar to the following:
Step 4: Use the registered secret’s ID and encryption type
In this step, you use the registered secret’s ID and encryption type to specify the secret when you call the Unstructured Workflow Endpoint. This step shows how to specify the registered secret’s ID and encryption type when you create a new Google Drive source connector.
Python
Python
The output looks similar to the following:
curl
curl
The output looks similar to the following:
Postman
Postman
-
In the method drop-down list, select POST.
-
In the address box, enter the following URL:
-
On the Headers tab, enter the following headers:
- Key:
unstructured-api-key
, Value:{{UNSTRUCTURED_API_KEY}}
- Key:
accept
, Value:application/json
- Key:
content-Type
, Value:application/json
- Key:
-
On the Body tab, select raw and JSON, and specify the connector settings, for example:
-
Click Send.
The response body looks similar to the following: