# Create a credential

Launch stage: GA

`POST /api/2.1/unity-catalog/credentials`

Creates a new credential. The type of credential to be created is determined by the **purpose** field,
 which should be either **SERVICE** or **STORAGE**.

 The caller must be a metastore admin or have the metastore privilege **CREATE_STORAGE_CREDENTIAL** for storage
 credentials, or **CREATE_SERVICE_CREDENTIAL** for service credentials.

API scopes: unity-catalog

**AWS**

Creates a new credential. The type of credential to be created is determined by the **purpose** field,
which should be either **SERVICE** or **STORAGE**.

The caller must be a metastore admin or have the metastore privilege **CREATE_STORAGE_CREDENTIAL** for storage
credentials, or **CREATE_SERVICE_CREDENTIAL** for service credentials.

The request object must contain an **AwsIamRole** with the `arn` of the IAM role.
To prevent [the confused deputy problem](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html),
this role must specify an external ID in its trust policy.

To enable this credential, the external ID specified in the __external_id__ field of the response object must
be added to the IAM role's trust policy.

**Azure**

Creates a new credential. The type of credential to be created is determined by the **purpose** field,
which should be either **SERVICE** or **STORAGE**.

The caller must be a metastore admin or have the metastore privilege **CREATE_STORAGE_CREDENTIAL** for storage
credentials, or **CREATE_SERVICE_CREDENTIAL** for service credentials.

For service credentials, the request object must contain an **AzureManagedIdentity**. For
storage credentials, the request object must contain either an **AzureServicePrincipal** or
**AzureManagedIdentity**, depending on the credential type being registered.

Additionally, non-account admin users must have the azure contributor role over the access connector
for any **AzureManagedIdentity** credential they create.

**GCP**

Creates a new credential. The type of credential to be created is determined by the **purpose** field,
which should be either **SERVICE** or **STORAGE**.

The caller must be a metastore admin or have the metastore privilege **CREATE_STORAGE_CREDENTIAL** for storage
credentials, or **CREATE_SERVICE_CREDENTIAL** for service credentials.

The request object must contain a **DatabricksGcpServiceAccount**.

## Request body

- `skip_validation` (boolean, optional)
  Optional. Supplying true to this argument skips validation of the created
   set of credentials.
  Default: `false`
- `name` (string, optional)
  The credential name. The name must be unique among storage and service
   credentials within the metastore.
- `aws_iam_role` (object, optional)
  The AWS IAM role configuration.
  - `role_arn` (string, optional)
    The Amazon Resource Name (ARN) of the AWS IAM role used to vend temporary credentials.
- `azure_service_principal` (object, optional)
  The Azure service principal configuration.
  - `directory_id` (string, required)
    The directory ID corresponding to the Azure Active Directory (AAD) tenant of the application.
  - `application_id` (string, required)
    The application ID of the application registration within the referenced AAD tenant.
  - `client_secret` (string, required)
    The client secret generated for the above app ID in AAD.
- `gcp_service_account_key` (object, optional)
  The GCP service account key configuration.
  - `email` (string, optional)
    The email of the service account.
  - `private_key_id` (string, optional)
    The ID of the service account's private key.
  - `private_key` (string, optional)
    The service account's RSA private key.
- `azure_managed_identity` (object, optional)
  The Azure managed identity configuration.
  - `access_connector_id` (string, required)
    The Azure resource ID of the Azure Databricks Access Connector. Use the format
     `/subscriptions/{guid}/resourceGroups/{rg-name}/providers/Microsoft.Databricks/accessConnectors/{connector-name}`.
  - `managed_identity_id` (string, optional)
    The Azure resource ID of the managed identity. Use the format,
     `/subscriptions/{guid}/resourceGroups/{rg-name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identity-name}`
     This is only available for user-assgined identities. For system-assigned identities, the access_connector_id is used to identify the identity.
     If this field is not provided, then we assume the AzureManagedIdentity is using the system-assigned identity.
- `databricks_gcp_service_account` (object, optional)
  The Databricks managed GCP service account configuration.
- `comment` (string, optional)
  Comment associated with the credential.
- `read_only` (boolean, optional)
  Whether the credential is usable only for read operations. Only applicable
   when purpose is **STORAGE**.
- `owner` (string, optional)
  Username of current owner of credential.
- `id` (string, optional)
  The unique identifier of the credential.
- `metastore_id` (string, optional)
  Unique identifier of the parent metastore.
- `created_at` (int64, optional)
  Time at which this credential was created, in epoch milliseconds.
- `created_by` (string, optional)
  Username of credential creator.
- `updated_at` (int64, optional)
  Time at which this credential was last modified, in epoch milliseconds.
- `updated_by` (string, optional)
  Username of user who last modified the credential.
- `used_for_managed_storage` (boolean, optional)
  Whether this credential is the current metastore's root storage credential.
   Only applicable when purpose is **STORAGE**.
- `full_name` (string, optional)
  The full name of the credential.
- `isolation_mode` (string, optional)
  Whether the current securable is accessible from all workspaces or a
   specific set of workspaces.
  Possible values:
  - `ISOLATION_MODE_OPEN`
  - `ISOLATION_MODE_ISOLATED`

## Returns

- `name` (string, optional)
  The credential name. The name must be unique among storage and service
   credentials within the metastore.
- `aws_iam_role` (object, optional)
  The AWS IAM role configuration.
  - `role_arn` (string, optional)
    The Amazon Resource Name (ARN) of the AWS IAM role used to vend temporary credentials.
  - `unity_catalog_iam_arn` (string, optional, Output only)
    The Amazon Resource Name (ARN) of the AWS IAM user managed by Databricks.
     This is the identity that is going to assume the AWS IAM role.
  - `external_id` (string, optional, Output only)
    The external ID used in role assumption to prevent the confused deputy problem.
- `azure_service_principal` (object, optional)
  The Azure service principal configuration.
  - `directory_id` (string, required)
    The directory ID corresponding to the Azure Active Directory (AAD) tenant of the application.
  - `application_id` (string, required)
    The application ID of the application registration within the referenced AAD tenant.
  - `client_secret` (string, required)
    The client secret generated for the above app ID in AAD.
- `gcp_service_account_key` (object, optional)
  The GCP service account key configuration.
  - `email` (string, optional)
    The email of the service account.
  - `private_key_id` (string, optional)
    The ID of the service account's private key.
  - `private_key` (string, optional)
    The service account's RSA private key.
- `azure_managed_identity` (object, optional)
  The Azure managed identity configuration.
  - `access_connector_id` (string, required)
    The Azure resource ID of the Azure Databricks Access Connector. Use the format
     `/subscriptions/{guid}/resourceGroups/{rg-name}/providers/Microsoft.Databricks/accessConnectors/{connector-name}`.
  - `managed_identity_id` (string, optional)
    The Azure resource ID of the managed identity. Use the format,
     `/subscriptions/{guid}/resourceGroups/{rg-name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identity-name}`
     This is only available for user-assgined identities. For system-assigned identities, the access_connector_id is used to identify the identity.
     If this field is not provided, then we assume the AzureManagedIdentity is using the system-assigned identity.
  - `credential_id` (string, optional, Output only)
    The Databricks internal ID that represents this managed identity.
- `databricks_gcp_service_account` (object, optional)
  The Databricks managed GCP service account configuration.
  - `email` (string, optional, Output only)
    The email of the service account.
  - `private_key_id` (string, optional, Output only)
    The ID that represents the private key for this Service Account
  - `credential_id` (string, optional, Output only)
    The Databricks internal ID that represents this managed identity.
- `comment` (string, optional)
  Comment associated with the credential.
- `read_only` (boolean, optional)
  Whether the credential is usable only for read operations. Only applicable
   when purpose is **STORAGE**.
- `owner` (string, optional)
  Username of current owner of credential.
- `id` (string, optional)
  The unique identifier of the credential.
- `metastore_id` (string, optional)
  Unique identifier of the parent metastore.
- `created_at` (int64, optional)
  Time at which this credential was created, in epoch milliseconds.
- `created_by` (string, optional)
  Username of credential creator.
- `updated_at` (int64, optional)
  Time at which this credential was last modified, in epoch milliseconds.
- `updated_by` (string, optional)
  Username of user who last modified the credential.
- `used_for_managed_storage` (boolean, optional)
  Whether this credential is the current metastore's root storage credential.
   Only applicable when purpose is **STORAGE**.
- `full_name` (string, optional)
  The full name of the credential.
- `isolation_mode` (string, optional)
  Whether the current securable is accessible from all workspaces or a
   specific set of workspaces.
  Possible values:
  - `ISOLATION_MODE_OPEN`
  - `ISOLATION_MODE_ISOLATED`

## Response

### AWS

```json
{
  "name": "sales_s3_credential",
  "aws_iam_role": {
    "role_arn": "arn:aws:iam::123456789012:role/unity-catalog-sales-access",
    "unity_catalog_iam_arn": "arn:aws:iam::210987654321:role/unity-catalog-prod-UCMasterRole-1A2B3C4D5E6F7",
    "external_id": "12a345b6-7890-1cd2-3456-e789f0a12b34"
  },
  "comment": "IAM role for the sales S3 buckets",
  "read_only": false,
  "owner": "jane.doe@example.com",
  "id": "7e9a1f3c-2b4d-4e8f-9a0b-1c2d3e4f5a6b",
  "metastore_id": "b7c1d2e3-f4a5-4b6c-8d7e-9f0a1b2c3d4e",
  "created_at": 1718035200000,
  "created_by": "jane.doe@example.com",
  "updated_at": 1718035200000,
  "updated_by": "jane.doe@example.com",
  "used_for_managed_storage": false,
  "full_name": "sales_s3_credential",
  "isolation_mode": "ISOLATION_MODE_OPEN"
}
```

### Azure

```json
{
  "name": "sales_adls_credential",
  "azure_managed_identity": {
    "access_connector_id": "/subscriptions/12f34567-8ab9-4cde-f012-3456789abcde/resourceGroups/sales-rg/providers/Microsoft.Databricks/accessConnectors/sales-access-connector",
    "credential_id": "3f8c2a1e-6d4b-4c9a-8e7f-0a1b2c3d4e5f"
  },
  "comment": "Access connector for the sales ADLS storage account",
  "read_only": false,
  "owner": "jane.doe@example.com",
  "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "metastore_id": "b7c1d2e3-f4a5-4b6c-8d7e-9f0a1b2c3d4e",
  "created_at": 1718035200000,
  "created_by": "jane.doe@example.com",
  "updated_at": 1718035200000,
  "updated_by": "jane.doe@example.com",
  "used_for_managed_storage": false,
  "full_name": "sales_adls_credential",
  "isolation_mode": "ISOLATION_MODE_OPEN"
}
```

### GCP

```json
{
  "name": "sales_gcs_credential",
  "databricks_gcp_service_account": {
    "email": "sales-gcs-credential@example.iam.gserviceaccount.com",
    "credential_id": "9c4e7b2a-1f3d-4a6b-8c5e-2d1f0e9a8b7c"
  },
  "comment": "Databricks-created service account for the sales GCS buckets",
  "read_only": false,
  "owner": "jane.doe@example.com",
  "id": "c0d1e2f3-a4b5-4c6d-8e7f-9a0b1c2d3e4f",
  "metastore_id": "b7c1d2e3-f4a5-4b6c-8d7e-9f0a1b2c3d4e",
  "created_at": 1718035200000,
  "created_by": "jane.doe@example.com",
  "updated_at": 1718035200000,
  "updated_by": "jane.doe@example.com",
  "used_for_managed_storage": false,
  "full_name": "sales_gcs_credential",
  "isolation_mode": "ISOLATION_MODE_OPEN"
}
```

