# Is there a way to use Service Principal to connect to Azure blob storage instead of access key and SAS token in great expectations?

**URL:** <https://discourse.greatexpectations.io/t/is-there-a-way-to-use-service-principal-to-connect-to-azure-blob-storage-instead-of-access-key-and-sas-token-in-great-expectations/1811>\
**Category:** GX Core Support\
**Created:** [July 22, 2024, 6:42am UTC](https://discourse.greatexpectations.io/t/is-there-a-way-to-use-service-principal-to-connect-to-azure-blob-storage-instead-of-access-key-and-sas-token-in-great-expectations/1811 "2024-07-22T06:42:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dinesh](https://discourse.greatexpectations.io/u/Dinesh)\
**Post date:** [July 22, 2024, 6:42am UTC](https://discourse.greatexpectations.io/t/is-there-a-way-to-use-service-principal-to-connect-to-azure-blob-storage-instead-of-access-key-and-sas-token-in-great-expectations/1811/1 "2024-07-22T06:42:01Z")

</div>

Hi Team,

Is there a way to connect to azure blob storage or ADLS using Service principal instead of access key or SAS token. PFB the code snippet I am using to connect to ADLS using Access key or SAS token.

```auto
context = gx.get_context(context_root_dir=contextDirecotry)

#using SAS token
storageAccountURL = f"https://{storageAccountName}.blob.core.windows.net/?{storage_account_sas_token}"
azure_options_sas = {"account_url": storageAccountURL}
datasource_sas = context.sources.add_or_update_spark_abs(name=datasource_name, azure_options=azure_options_sas)

#using storage account access key
storageAccountConnectionString = f"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName={storageAccountName};AccountKey={storage_account_access_key}"
azure_options_account_key = {"conn_str": storageAccountConnectionString}
datasource_account_key = context.sources.add_or_update_spark_abs(name=datasource_name, azure_options=azure_options_account_key)

```

Is there any other way to connect to blob storage using Service principal authentication (client id, tenant id, client secret)

Thanks,  
Dinesh

---

<div class="post-metadata">

**Author:** ![slack\_user](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/slack_user/32/202_2.png) [@slack\_user](https://discourse.greatexpectations.io/u/slack_user)\
**Post date:** [July 24, 2024, 6:49am UTC](https://discourse.greatexpectations.io/t/is-there-a-way-to-use-service-principal-to-connect-to-azure-blob-storage-instead-of-access-key-and-sas-token-in-great-expectations/1811/2 "2024-07-24T06:49:56Z")

</div>

i have a same query, i was working on the proof of value in my project and spent a lot of time setting up everything in databricks. Now i am having trouble in setting up the data docs as i need to pass in the access key and token of s3 bucket where i am hosting the data docs which i can’t as my organization uses i am roles  
Note: `@rodger67` originally [posted this reply in Slack](https://greatexpectationstalk.slack.com/archives/CUTCNHN82/p1721803766984389?thread_ts=1721630543.346749&cid=CUTCNHN82). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![slack\_user](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/slack_user/32/202_2.png) [@slack\_user](https://discourse.greatexpectations.io/u/slack_user)\
**Post date:** [July 24, 2024, 7:08am UTC](https://discourse.greatexpectations.io/t/is-there-a-way-to-use-service-principal-to-connect-to-azure-blob-storage-instead-of-access-key-and-sas-token-in-great-expectations/1811/3 "2024-07-24T07:08:33Z")

</div>

\<@U06TC1ZMX1A\> I am able to use access key and token in Azure using great expectations but not service principal.  
For AWS S3 bucket you can refer this \<[https://docs.greatexpectations.io/docs/oss/deployment\_patterns/how\_to\_use\_gx\_with\_aws/how\_to\_use\_gx\_with\_aws\_using\_s3\_and\_spark/|Use](https://docs.greatexpectations.io/docs/oss/deployment_patterns/how_to_use_gx_with_aws/how_to_use_gx_with_aws_using_s3_and_spark/%7CUse) Great Expectations with Amazon Web Services using S3 and Spark\>.  
Note: `@Dinesh Baratam` originally [posted this reply in Slack](https://greatexpectationstalk.slack.com/archives/CUTCNHN82/p1721804904676519?thread_ts=1721630543.346749&cid=CUTCNHN82). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![slack\_user](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/slack_user/32/202_2.png) [@slack\_user](https://discourse.greatexpectations.io/u/slack_user)\
**Post date:** [July 24, 2024, 8:36am UTC](https://discourse.greatexpectations.io/t/is-there-a-way-to-use-service-principal-to-connect-to-azure-blob-storage-instead-of-access-key-and-sas-token-in-great-expectations/1811/4 "2024-07-24T08:36:32Z")

</div>

Thanks for the reply \<@U075BU5FKT4\> but my issue is slightly different. I can’t use access key as my organization does not use it for access to the s3 bucket instead use i am roles due to which i cant write the data docs directly from my code as gx expects these keys  
Note: `@rodger67` originally [posted this reply in Slack](https://greatexpectationstalk.slack.com/archives/CUTCNHN82/p1721810151364159?thread_ts=1721630543.346749&cid=CUTCNHN82). It might not have transferred perfectly.
