Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/Models/AzureServicePrincipalRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AzureServicePrincipalRequest
## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
| **directory\_id** | **String** | The directory (tenant) ID of the Microsoft Entra ID tenant that holds the application. | [default to null] |
| **application\_id** | **String** | The application (client) ID of the service principal. | [default to null] |
| **client\_secret** | **String** | The client secret of the service principal. The server never returns it. | [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

10 changes: 10 additions & 0 deletions api/Models/AzureServicePrincipalResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# AzureServicePrincipalResponse
## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
| **directory\_id** | **String** | The directory (tenant) ID of the Microsoft Entra ID tenant that holds the application. | [default to null] |
| **application\_id** | **String** | The application (client) ID of the service principal. | [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

2 changes: 2 additions & 0 deletions api/Models/CreateCredentialRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
| **name** | **String** | The credential name. The name must be unique within the metastore. | [default to null] |
| **comment** | **String** | Comment associated with the credential. | [optional] [default to null] |
| **aws\_iam\_role** | [**AwsIamRoleRequest**](AwsIamRoleRequest.md) | | [optional] [default to null] |
| **azure\_service\_principal** | [**AzureServicePrincipalRequest**](AzureServicePrincipalRequest.md) | | [optional] [default to null] |
| **gcp\_service\_account\_key** | [**GcpServiceAccountKeyRequest**](GcpServiceAccountKeyRequest.md) | | [optional] [default to null] |
| **purpose** | [**CredentialPurpose**](CredentialPurpose.md) | | [optional] [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
2 changes: 2 additions & 0 deletions api/Models/CredentialInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
|------------ | ------------- | ------------- | -------------|
| **name** | **String** | The credential name. The name must be unique within the metastore. | [optional] [default to null] |
| **aws\_iam\_role** | [**AwsIamRoleResponse**](AwsIamRoleResponse.md) | | [optional] [default to null] |
| **azure\_service\_principal** | [**AzureServicePrincipalResponse**](AzureServicePrincipalResponse.md) | | [optional] [default to null] |
| **gcp\_service\_account\_key** | [**GcpServiceAccountKeyResponse**](GcpServiceAccountKeyResponse.md) | | [optional] [default to null] |
| **comment** | **String** | Comment associated with the credential. | [optional] [default to null] |
| **owner** | **String** | Username of current owner of credential. | [optional] [default to null] |
| **full\_name** | **String** | The full name of the credential. | [optional] [default to null] |
Expand Down
11 changes: 11 additions & 0 deletions api/Models/GcpServiceAccountKeyRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GcpServiceAccountKeyRequest
## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
| **email** | **String** | The email of the service account. | [default to null] |
| **private\_key\_id** | **String** | The ID of the private key. | [default to null] |
| **private\_key** | **String** | The private key in PEM (PKCS#8) format. The server never returns it. | [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

10 changes: 10 additions & 0 deletions api/Models/GcpServiceAccountKeyResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GcpServiceAccountKeyResponse
## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
| **email** | **String** | The email of the service account. | [default to null] |
| **private\_key\_id** | **String** | The ID of the private key. | [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

2 changes: 2 additions & 0 deletions api/Models/UpdateCredentialRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
| **comment** | **String** | Comment associated with the credential. | [optional] [default to null] |
| **owner** | **String** | Username of current owner of credential. | [optional] [default to null] |
| **aws\_iam\_role** | [**AwsIamRoleRequest**](AwsIamRoleRequest.md) | | [optional] [default to null] |
| **azure\_service\_principal** | [**AzureServicePrincipalRequest**](AzureServicePrincipalRequest.md) | | [optional] [default to null] |
| **gcp\_service\_account\_key** | [**GcpServiceAccountKeyRequest**](GcpServiceAccountKeyRequest.md) | | [optional] [default to null] |
| **new\_name** | **String** | New name for the credential. | [optional] [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
4 changes: 4 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ All URIs are relative to *http://localhost:8080/api/2.1/unity-catalog*
- [AwsCredentials](./Models/AwsCredentials.md)
- [AwsIamRoleRequest](./Models/AwsIamRoleRequest.md)
- [AwsIamRoleResponse](./Models/AwsIamRoleResponse.md)
- [AzureServicePrincipalRequest](./Models/AzureServicePrincipalRequest.md)
- [AzureServicePrincipalResponse](./Models/AzureServicePrincipalResponse.md)
- [AzureUserDelegationSAS](./Models/AzureUserDelegationSAS.md)
- [CatalogInfo](./Models/CatalogInfo.md)
- [ColumnInfo](./Models/ColumnInfo.md)
Expand Down Expand Up @@ -107,6 +109,8 @@ All URIs are relative to *http://localhost:8080/api/2.1/unity-catalog*
- [FunctionParameterMode](./Models/FunctionParameterMode.md)
- [FunctionParameterType](./Models/FunctionParameterType.md)
- [GcpOauthToken](./Models/GcpOauthToken.md)
- [GcpServiceAccountKeyRequest](./Models/GcpServiceAccountKeyRequest.md)
- [GcpServiceAccountKeyResponse](./Models/GcpServiceAccountKeyResponse.md)
- [GenerateTemporaryModelVersionCredential](./Models/GenerateTemporaryModelVersionCredential.md)
- [GenerateTemporaryPathCredential](./Models/GenerateTemporaryPathCredential.md)
- [GenerateTemporaryTableCredential](./Models/GenerateTemporaryTableCredential.md)
Expand Down
81 changes: 81 additions & 0 deletions api/all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,10 @@ components:
type: string
aws_iam_role:
$ref: '#/components/schemas/AwsIamRoleResponse'
azure_service_principal:
$ref: '#/components/schemas/AzureServicePrincipalResponse'
gcp_service_account_key:
$ref: '#/components/schemas/GcpServiceAccountKeyResponse'
comment:
description: Comment associated with the credential.
type: string
Expand Down Expand Up @@ -2906,6 +2910,9 @@ components:
purpose:
$ref: "#/components/schemas/CredentialPurpose"
CreateCredentialRequest:
description: |
Exactly one of __aws_iam_role__, __azure_service_principal__ or __gcp_service_account_key__ must be set.
It determines the cloud of the credential, which cannot be changed afterwards.
type: object
required:
- name
Expand All @@ -2918,9 +2925,16 @@ components:
type: string
aws_iam_role:
$ref: '#/components/schemas/AwsIamRoleRequest'
azure_service_principal:
$ref: '#/components/schemas/AzureServicePrincipalRequest'
gcp_service_account_key:
$ref: '#/components/schemas/GcpServiceAccountKeyRequest'
purpose:
$ref: "#/components/schemas/CredentialPurpose"
UpdateCredentialRequest:
description: |
At most one of __aws_iam_role__, __azure_service_principal__ or __gcp_service_account_key__ may be set,
and it must match the cloud the credential was created with.
type: object
properties:
comment:
Expand All @@ -2931,6 +2945,10 @@ components:
type: string
aws_iam_role:
$ref: '#/components/schemas/AwsIamRoleRequest'
azure_service_principal:
$ref: '#/components/schemas/AzureServicePrincipalRequest'
gcp_service_account_key:
$ref: '#/components/schemas/GcpServiceAccountKeyRequest'
new_name:
description: New name for the credential.
type: string
Expand All @@ -2957,6 +2975,69 @@ components:
external_id:
description: The external ID used in role assumption to prevent confused deputy problem.
type: string
AzureServicePrincipalRequest:
description: |
A Microsoft Entra ID service principal that has access to the storage account. The server signs in as this
principal to issue user delegation SAS tokens scoped to the requested path.
type: object
required:
- directory_id
- application_id
- client_secret
properties:
directory_id:
description: The directory (tenant) ID of the Microsoft Entra ID tenant that holds the application.
type: string
application_id:
description: The application (client) ID of the service principal.
type: string
client_secret:
description: The client secret of the service principal. The server never returns it.
type: string
AzureServicePrincipalResponse:
type: object
required:
- directory_id
- application_id
properties:
directory_id:
description: The directory (tenant) ID of the Microsoft Entra ID tenant that holds the application.
type: string
application_id:
description: The application (client) ID of the service principal.
type: string
GcpServiceAccountKeyRequest:
description: |
A key of a GCP service account that has access to the bucket. The server signs in as this service account to
issue OAuth tokens downscoped to the requested path. The fields match __client_email__, __private_key_id__
and __private_key__ of the service account key JSON file.
type: object
required:
- email
- private_key_id
- private_key
properties:
email:
description: The email of the service account.
type: string
private_key_id:
description: The ID of the private key.
type: string
private_key:
description: The private key in PEM (PKCS#8) format. The server never returns it.
type: string
GcpServiceAccountKeyResponse:
type: object
required:
- email
- private_key_id
properties:
email:
description: The email of the service account.
type: string
private_key_id:
description: The ID of the private key.
type: string
ListCredentialsResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
import static io.unitycatalog.cli.utils.CliUtils.postProcessAndPrintOutput;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import io.unitycatalog.cli.utils.CliException;
import io.unitycatalog.cli.utils.CliParams;
import io.unitycatalog.cli.utils.CliUtils;
import io.unitycatalog.client.ApiClient;
import io.unitycatalog.client.ApiException;
import io.unitycatalog.client.api.CredentialsApi;
import io.unitycatalog.client.model.AwsIamRoleRequest;
import io.unitycatalog.client.model.AzureServicePrincipalRequest;
import io.unitycatalog.client.model.CreateCredentialRequest;
import io.unitycatalog.client.model.CredentialInfo;
import io.unitycatalog.client.model.CredentialPurpose;
import io.unitycatalog.client.model.GcpServiceAccountKeyRequest;
import io.unitycatalog.client.model.ListCredentialsResponse;
import io.unitycatalog.client.model.UpdateCredentialRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import org.apache.commons.cli.CommandLine;
Expand Down Expand Up @@ -63,14 +70,67 @@ private static Optional<AwsIamRoleRequest> extractAwsIamRole(JSONObject json) {
}
}

private static Optional<AzureServicePrincipalRequest> extractAzureServicePrincipal(
JSONObject json) {
List<CliParams> params =
List.of(
CliParams.AZURE_DIRECTORY_ID,
CliParams.AZURE_APPLICATION_ID,
CliParams.AZURE_CLIENT_SECRET);
if (params.stream().noneMatch(param -> json.has(param.getServerParam()))) {
return Optional.empty();
}
if (!params.stream().allMatch(param -> json.has(param.getServerParam()))) {
throw new CliException(
"--azure_directory_id, --azure_application_id and --azure_client_secret must be set"
+ " together.");
}
return Optional.of(
new AzureServicePrincipalRequest()
.directoryId(json.getString(CliParams.AZURE_DIRECTORY_ID.getServerParam()))
.applicationId(json.getString(CliParams.AZURE_APPLICATION_ID.getServerParam()))
.clientSecret(json.getString(CliParams.AZURE_CLIENT_SECRET.getServerParam())));
}

/** Reads the key out of a service account key JSON file, as downloaded from the GCP console. */
private static Optional<GcpServiceAccountKeyRequest> extractGcpServiceAccountKey(
JSONObject json) {
if (!json.has(CliParams.GCP_SERVICE_ACCOUNT_KEY_FILE.getServerParam())) {
return Optional.empty();
}
String path = json.getString(CliParams.GCP_SERVICE_ACCOUNT_KEY_FILE.getServerParam());
JsonNode keyFile;
try {
keyFile = new ObjectMapper().readTree(new File(path));
} catch (IOException e) {
throw new CliException("Cannot read the service account key file " + path, e);
}
return Optional.of(
new GcpServiceAccountKeyRequest()
.email(requiredKeyField(keyFile, "client_email", path))
.privateKeyId(requiredKeyField(keyFile, "private_key_id", path))
.privateKey(requiredKeyField(keyFile, "private_key", path)));
}

private static String requiredKeyField(JsonNode keyFile, String field, String path) {
JsonNode value = keyFile.get(field);
if (value == null || !value.isTextual()) {
throw new CliException(
String.format("%s is not a service account key file: it has no %s.", path, field));
}
return value.asText();
}

private static String createCredential(CredentialsApi credentialsApi, JSONObject json)
throws JsonProcessingException, ApiException {
CreateCredentialRequest createCredentialRequest =
new CreateCredentialRequest()
.name(json.getString(CliParams.NAME.getServerParam()))
.comment(json.optString(CliParams.COMMENT.getServerParam(), null))
.purpose(CredentialPurpose.STORAGE)
.awsIamRole(extractAwsIamRole(json).orElse(null));
.awsIamRole(extractAwsIamRole(json).orElse(null))
.azureServicePrincipal(extractAzureServicePrincipal(json).orElse(null))
.gcpServiceAccountKey(extractGcpServiceAccountKey(json).orElse(null));
CredentialInfo credentialInfo = credentialsApi.createCredential(createCredentialRequest);
return objectWriter.writeValueAsString(credentialInfo);
}
Expand Down Expand Up @@ -101,7 +161,9 @@ private static String updateCredential(CredentialsApi credentialsApi, JSONObject
new UpdateCredentialRequest()
.newName(json.optString(CliParams.NEW_NAME.getServerParam(), null))
.comment(json.optString(CliParams.COMMENT.getServerParam(), null))
.awsIamRole(extractAwsIamRole(json).orElse(null));
.awsIamRole(extractAwsIamRole(json).orElse(null))
.azureServicePrincipal(extractAzureServicePrincipal(json).orElse(null))
.gcpServiceAccountKey(extractGcpServiceAccountKey(json).orElse(null));
CredentialInfo credentialInfo = credentialsApi.updateCredential(name, updateCredentialRequest);
return objectWriter.writeValueAsString(credentialInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ public enum CliParams {
CREDENTIAL_NAME("credential_name", "The name of the storage credential", "credential_name"),
AWS_IAM_ROLE_ARN(
"aws_iam_role_arn", "The ARN of the AWS IAM role for credential", "aws_iam_role_arn"),
AZURE_DIRECTORY_ID(
"azure_directory_id",
"The directory (tenant) ID of the Azure service principal for credential",
"azure_directory_id"),
AZURE_APPLICATION_ID(
"azure_application_id",
"The application (client) ID of the Azure service principal for credential",
"azure_application_id"),
AZURE_CLIENT_SECRET(
"azure_client_secret",
"The client secret of the Azure service principal for credential",
"azure_client_secret"),
GCP_SERVICE_ACCOUNT_KEY_FILE(
"gcp_service_account_key_file",
"The path of the JSON key file of the GCP service account for credential",
"gcp_service_account_key_file"),
STORAGE_ROOT(
"storage_root",
"The storage root URL for managed tables/volumes within the catalog or schema.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,13 @@ public List<CliParams> getOptionalParams() {
CREATE,
new CliOptions(
List.of(CliParams.NAME),
List.of(CliParams.COMMENT, CliParams.AWS_IAM_ROLE_ARN)));
List.of(
CliParams.COMMENT,
CliParams.AWS_IAM_ROLE_ARN,
CliParams.AZURE_DIRECTORY_ID,
CliParams.AZURE_APPLICATION_ID,
CliParams.AZURE_CLIENT_SECRET,
CliParams.GCP_SERVICE_ACCOUNT_KEY_FILE)));
put(
LIST,
new CliOptions(
Expand All @@ -367,7 +373,13 @@ public List<CliParams> getOptionalParams() {
new CliOptions(
List.of(CliParams.NAME),
List.of(
CliParams.NEW_NAME, CliParams.COMMENT, CliParams.AWS_IAM_ROLE_ARN)));
CliParams.NEW_NAME,
CliParams.COMMENT,
CliParams.AWS_IAM_ROLE_ARN,
CliParams.AZURE_DIRECTORY_ID,
CliParams.AZURE_APPLICATION_ID,
CliParams.AZURE_CLIENT_SECRET,
CliParams.GCP_SERVICE_ACCOUNT_KEY_FILE)));
put(DELETE, new CliOptions(List.of(CliParams.NAME), List.of(CliParams.FORCE)));
}
});
Expand Down
Loading
Loading