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

feat: add support for azure access token authorization #88

Merged
merged 3 commits into from
Sep 11, 2024
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/CloudTesting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ jobs:
run: |
python3 duckdb/scripts/run_tests_one_by_one.py ./build/release/test/unittest `pwd`/test/sql/cloud/*

- name: Test with Access Token in env vars
env:
AZURE_STORAGE_ACCOUNT: ${{secrets.AZURE_STORAGE_ACCOUNT}}
run: |
az login --service-principal -u ${{secrets.AZURE_CLIENT_ID}} -p ${{secrets.AZURE_CLIENT_SECRET}} --tenant ${{secrets.AZURE_TENANT_ID}}
export AZURE_ACCESS_TOKEN=`az account get-access-token --resource https://storage.azure.com --query accessToken --output tsv`
python3 duckdb/scripts/run_tests_one_by_one.py ./build/release/test/unittest `pwd`/test/sql/cloud/*

- name: Test with SPN logged in in azure-cli
env:
AZURE_STORAGE_ACCOUNT: ${{secrets.AZURE_STORAGE_ACCOUNT}}
Expand Down
11 changes: 9 additions & 2 deletions src/functions/delta_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,15 @@ static ffi::EngineBuilder* CreateBuilder(ClientContext &context, const string &p
secret_reader.TryGetSecretKey("chain", chain);

auto provider = kv_secret.GetProvider();

if (provider == "credential_chain") {
if (provider == "access_token") {
// Authentication option 0: https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html#variant.Token
string access_token;
secret_reader.TryGetSecretKey("access_token", access_token);
if (access_token.empty()) {
throw InvalidInputException("No access_token value not found in secret provider!");
}
ffi::set_builder_option(builder, KernelUtils::ToDeltaString("bearer_token"), KernelUtils::ToDeltaString(access_token));
} else if (provider == "credential_chain") {
// Authentication option 1a: using the cli authentication
if (chain.find("cli") != std::string::npos) {
ffi::set_builder_option(builder, KernelUtils::ToDeltaString("use_azure_cli"), KernelUtils::ToDeltaString("true"));
Expand Down
46 changes: 46 additions & 0 deletions test/sql/cloud/azure/access_token_auth.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# name: test/sql/cloud/azure/access_token_auth.test
# description: test access-token authentication
# group: [azure]

require azure

require parquet

require delta

require-env AZURE_ACCESS_TOKEN

require-env AZURE_STORAGE_ACCOUNT

statement ok
set allow_persistent_secrets=false

statement error
SELECT count(*) FROM delta_scan('azure://delta-testing-private/dat/all_primitive_types/delta');
----
IO Error

statement ok
CREATE OR REPLACE SECRET az1 (
TYPE AZURE,
PROVIDER ACCESS_TOKEN,
ACCOUNT_NAME '${AZURE_STORAGE_ACCOUNT}'
)

statement error
SELECT count(*) FROM delta_scan('azure://delta-testing-private/dat/all_primitive_types/delta');
----
Invalid Input Error: No access_token value not found in secret provider!

statement ok
CREATE OR REPLACE SECRET az1 (
TYPE AZURE,
PROVIDER ACCESS_TOKEN,
ACCESS_TOKEN '${AZURE_ACCESS_TOKEN}',
ACCOUNT_NAME '${AZURE_STORAGE_ACCOUNT}'
)

query I
SELECT count(*) FROM delta_scan('azure://delta-testing-private/dat/all_primitive_types/delta');
----
5
Loading