Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for COPY TO/FROM Azure Blob Storage #55

Merged
merged 8 commits into from
Jan 10, 2025

Conversation

aykut-bozkurt
Copy link
Collaborator

@aykut-bozkurt aykut-bozkurt commented Oct 23, 2024

Supports following Azure Blob uri forms:

  • az://{container}/key
  • azure://{container}/key
  • https://{account}.blob.core.windows.net/{container}

Configuration

The simplest way to configure object storage is by creating the standard ~/.azure/config file:

$ cat ~/.azure/config
[storage]
account = devstoreaccount1
key = Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

Alternatively, you can use the following environment variables when starting postgres to configure the Azure Blob Storage client:

  • AZURE_STORAGE_ACCOUNT: the storage account name of the Azure Blob
  • AZURE_STORAGE_KEY: the storage key of the Azure Blob
  • AZURE_CONNECTION_STRING: the connection string of the Azure Blob
  • AZURE_STORAGE_SAS_TOKEN: the storage SAS token for the Azure Blob
  • AZURE_TENANT_ID: the tenant id for client secret auth (only via environment variables)
  • AZURE_CLIENT_ID: the client id for client secret auth (only via environment variables)
  • AZURE_CLIENT_SECRET: the client secret for client secret auth (only via environment variables)
  • AZURE_STORAGE_ENDPOINT: the endpoint (only via environment variables)
  • AZURE_ALLOW_HTTP: allows http endpoints (only via environment variables)
  • AZURE_CONFIG_FILE: an alternative location for the config file (only via environment variables)

Bonus
Additionally, PR adds support to the following S3 uri forms:

  • https://s3.amazonaws.com/{bucket}/key
  • https://{bucket}.s3.amazonaws.com/key

Closes #50

@aykut-bozkurt aykut-bozkurt marked this pull request as draft October 23, 2024 17:53
@aykut-bozkurt aykut-bozkurt marked this pull request as ready for review October 23, 2024 17:55
@aykut-bozkurt aykut-bozkurt marked this pull request as draft October 23, 2024 17:55
@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from fe03728 to 4dc228c Compare October 23, 2024 17:56
@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch 3 times, most recently from b9114cf to 2feb683 Compare October 26, 2024 00:47
@aykut-bozkurt aykut-bozkurt marked this pull request as ready for review October 26, 2024 00:48
@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch 3 times, most recently from afb3c71 to 2a3061f Compare November 9, 2024 23:27
@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from 2a3061f to 0a3281f Compare November 28, 2024 15:38
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 99.54407% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.54%. Comparing base (2c1a62d) to head (d5f5ef2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/object_store/aws.rs 97.67% 2 Missing ⚠️
src/object_store/azure.rs 99.34% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
+ Coverage   92.11%   92.54%   +0.42%     
==========================================
  Files          71       75       +4     
  Lines        9109     9621     +512     
==========================================
+ Hits         8391     8904     +513     
+ Misses        718      717       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from 0a3281f to 80e449f Compare November 28, 2024 21:41
Supports following Azure Blob uri forms:
- `az://{container}/key`
- `azure://{container}/key`
- `https://{account}.blob.core.windows.net/{container}`

**Configuration**

The simplest way to configure object storage is by creating the standard [`~/.azure/config`](https://learn.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) file:

```bash
$ cat ~/.azure/config
[storage]
account = devstoreaccount1
key = Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
```

Alternatively, you can use the following environment variables when starting postgres to configure the Azure Blob Storage client:
- `AZURE_STORAGE_ACCOUNT`: the storage account name of the Azure Blob
- `AZURE_STORAGE_KEY`: the storage key of the Azure Blob
- `AZURE_STORAGE_SAS_TOKEN`: the storage SAS token for the Azure Blob
- `AZURE_CONFIG_FILE`: an alternative location for the config file

**Bonus**
Additionally, PR supports following S3 uri forms:
- `s3://{bucket}/key`
- `s3a://{bucket}/key`
- `https://s3.amazonaws.com/{bucket}/key`
- `https://{bucket}.s3.amazonaws.com/key`

Closes #50
@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from 80e449f to 8553677 Compare December 3, 2024 12:04
done

# create container
az storage container create -n $AZURE_TEST_CONTAINER_NAME --connection-string $AZURE_STORAGE_CONNECTION_STRING
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot easily create azurite test container via a docker entrypoint script (as we do for minio) since azurite image does not include az cli.

@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from 24ff523 to e0df256 Compare January 6, 2025 16:57
@@ -20,6 +24,15 @@ pgrx::pg_module_magic!();

extension_sql_file!("../sql/bootstrap.sql", name = "role_setup", bootstrap);

// PG_BACKEND_TOKIO_RUNTIME creates a tokio runtime that uses the current thread
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved from uri_utils to a more common file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved object store logic from uri_utils to this module with a submodule per object store

@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from e0df256 to e9d0cdd Compare January 6, 2025 17:09

// first tries environment variables and then the config files
let sdk_config = PG_BACKEND_TOKIO_RUNTIME.block_on(async {
aws_config::defaults(BehaviorVersion::v2024_03_28())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this also does the STS dance then, right?

Copy link
Collaborator Author

@aykut-bozkurt aykut-bozkurt Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct via provide_credentials()

- get rid of aws-sts dep in test as aws_config already supports it
@aykut-bozkurt aykut-bozkurt force-pushed the aykut/azure-blob-storage branch from 5d0b80f to d5f5ef2 Compare January 10, 2025 12:19
@aykut-bozkurt aykut-bozkurt merged commit fcb5036 into main Jan 10, 2025
6 checks passed
@aykut-bozkurt aykut-bozkurt deleted the aykut/azure-blob-storage branch January 10, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

What would be needed to use Azure Blob Storage?
2 participants