이 문서에서는 Service Connector를 사용하여 Azure Blob Storage에 앱을 연결하는 데 사용할 수 있는 지원되는 인증 방법, 클라이언트 및 샘플 코드에 대해 설명합니다. 이 문서에서는 서비스 연결을 만들 때 얻은 기본 환경 변수 이름, 값 및 구성도 찾을 수 있습니다.
지원되는 컴퓨팅 서비스
서비스 커넥터를 사용하여 다음 컴퓨팅 서비스를 Azure Blob Storage에 연결할 수 있습니다.
- Azure App Service
- Azure Container Apps
- Azure Functions
- AKS(Azure Kubernetes Service)
- Azure Spring Apps
지원되는 인증 유형 및 클라이언트 유형
아래 표에서는 서비스 커넥터를 사용하여 컴퓨팅 서비스를 Azure Blob Storage에 연결하는 데 지원되는 인증 방법과 클라이언트의 조합을 보여 줍니다. "예"는 조합이 지원됨을 나타내고 "아니오"는 지원되지 않음을 나타냅니다.
클라이언트 유형 |
시스템 할당 관리 ID |
사용자 할당 관리 ID |
비밀/연결 문자열 |
서비스 주체 |
.NET |
예 |
예 |
예 |
예 |
Java |
예 |
예 |
예 |
예 |
Java - Spring Boot |
예 |
예 |
예 |
예 |
Node.js |
예 |
예 |
예 |
예 |
Python |
예 |
예 |
예 |
예 |
Go |
예 |
예 |
예 |
예 |
None |
예 |
예 |
예 |
예 |
기본 환경 변수 이름 또는 애플리케이션 속성과 샘플 코드
연결의 인증 유형 및 클라이언트 유형에 따라 다음 표의 연결 세부 정보 및 샘플 코드를 참조하여 컴퓨팅 서비스를 Azure Blob Storage에 연결합니다. 서비스 커넥터 환경 변수 명명 규칙에 대해 자세히 알아볼 수 있습니다.
시스템 할당 관리 ID
SpringBoot 클라이언트
시스템이 할당한 관리 ID로 인증하는 기능은 Spring Cloud Azure 버전 4.0 이상에서만 사용할 수 있습니다.
기본 환경 변수 이름 |
설명 |
예제 값 |
spring.cloud.azure.storage.blob.credential.managed-identity-enabled |
관리 ID 사용 여부 |
True |
spring.cloud.azure.storage.blob.account-name |
스토리지 계정의 이름 |
storage-account-name |
spring.cloud.azure.storage.blob.endpoint |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
기타 클라이언트
기본 환경 변수 이름 |
설명 |
예제 값 |
AZURE_STORAGEBLOB_RESOURCEENDPOINT |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
예제 코드
시스템이 할당한 관리 ID를 사용하여 Azure Blob Storage에 연결하려면 아래 단계 및 코드를 참조하세요.
azure-identity
를 사용하여 관리 ID 또는 서비스 주체를 통해 인증할 수 있습니다. 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
종속성 설치
dotnet add package Azure.Identity
관리 ID 또는 서비스 주체를 사용하여 Blob Storage에 연결하는 샘플 코드는 다음과 같습니다.
using Azure.Identity;
using Azure.Storage.Blobs;
// get Blob endpoint
var blobEndpoint = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var blobServiceClient = new BlobServiceClient(
new Uri(blobEndpoint),
credential);
pom.xml 파일에서 다음 종속성을 추가합니다.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.5</version>
</dependency>
azure-identity
를 사용하여 인증하고 서비스 커넥터에서 추가한 환경 변수에서 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
String url = System.getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_STORAGEBLOB_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("<AZURE_STORAGEBLOB_CLIENTID>"))
// .clientSecret(System.getenv("<AZURE_STORAGEBLOB_CLIENTSECRET>"))
// .tenantId(System.getenv("<AZURE_STORAGEBLOB_TENANTID>"))
// .build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(url)
.credential(defaultCredential)
.buildClient();
종속성 설치
pip install azure-identity
pip install azure-storage-blob
azure-identity
라이브러리를 사용하여 인증하고 서비스 커넥터에서 추가한 환경 변수에서 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
from azure.storage.blob import BlobServiceClient
import os
account_url = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
# Uncomment the following lines corresponding to the authentication type you want to use.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
blob_service_client = BlobServiceClient(account_url, credential=cred)
종속성을 설치합니다.
pip install azure-identity
pip install django-storages[azure]
azure-identity
라이브러리를 통해 인증합니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
import os
# Uncomment the following lines corresponding to the authentication type you want to use.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
파일 설정에서 다음 줄을 추가합니다. 자세한 내용은 django-storages[azure]를 참조하세요.
# in your setting file, eg. settings.py
AZURE_CUSTOM_DOMAIN = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
AZURE_ACCOUNT_NAME = AZURE_CUSTOM_DOMAIN.split('.')[0].removeprefix('https://')
AZURE_TOKEN_CREDENTIAL = cred # this is the cred acquired from above step.
종속성을 설치합니다.
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
코드에서 azidentity
라이브러리를 통해 인증합니다. 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
account_endpoint = os.Getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT")
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// cred, err := azidentity.NewDefaultAzureCredential(nil)
// for user-assigned managed identity
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
// cred, err := azidentity.NewManagedIdentityCredential(options)
// for service principal
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// tenantid := os.Getenv("AZURE_STORAGEBLOB_TENANTID")
// clientsecret := os.Getenv("AZURE_STORAGEBLOB_CLIENTSECRET")
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
if err != nil {
// error handling
}
client, err := azblob.NewBlobServiceClient(account_endpoint, cred, nil)
}
종속성 설치
npm install --save @azure/identity
npm install @azure/storage-blob
서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. @azure/identity
라이브러리를 통해 인증합니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { BlobServiceClient } = require("@azure/storage-blob");
const account_url = process.env.AZURE_STORAGEBLOB_RESOURCEENDPOINT;
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system assigned managed identity
// const credential = new DefaultAzureCredential();
// for user assigned managed identity
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_STORAGEBLOB_TENANTID;
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const clientSecret = process.env.AZURE_STORAGEBLOB_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const blobServiceClient = new BlobServiceClient(account_url, credential);
다른 언어의 경우 Azure Blob Storage 계정 URL 및 서비스 커넥터가 환경 변수에 설정하는 기타 속성을 사용하여 Azure Blob Storage에 연결할 수 있습니다. 환경 변수에 대한 자세한 내용은 Azure Blob Storage와 서비스 커넥터 통합을 참조하세요.
사용자 할당 관리 ID
SpringBoot 클라이언트
사용자가 할당한 관리 ID로 인증하는 기능은 Spring Cloud Azure 버전 4.0 이상에서만 사용할 수 있습니다.
기본 환경 변수 이름 |
설명 |
예제 값 |
spring.cloud.azure.storage.blob.credential.managed-identity-enabled |
관리 ID 사용 여부 |
True |
spring.cloud.azure.storage.blob.account-name |
스토리지 계정의 이름 |
storage-account-name |
spring.cloud.azure.storage.blob.endpoint |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
spring.cloud.azure.storage.blob.credential.client-id |
사용자가 할당한 관리 ID의 클라이언트 ID |
00001111-aaaa-2222-bbbb-3333cccc4444 |
기타 클라이언트
기본 환경 변수 이름 |
설명 |
예제 값 |
AZURE_STORAGEBLOB_RESOURCEENDPOINT |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
AZURE_STORAGEBLOB_CLIENTID |
클라이언트 ID |
<client-ID> |
예제 코드
사용자가 할당한 관리 ID를 사용하여 Azure Blob Storage에 연결하려면 아래 단계 및 코드를 참조하세요.
azure-identity
를 사용하여 관리 ID 또는 서비스 주체를 통해 인증할 수 있습니다. 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
종속성 설치
dotnet add package Azure.Identity
관리 ID 또는 서비스 주체를 사용하여 Blob Storage에 연결하는 샘플 코드는 다음과 같습니다.
using Azure.Identity;
using Azure.Storage.Blobs;
// get Blob endpoint
var blobEndpoint = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var blobServiceClient = new BlobServiceClient(
new Uri(blobEndpoint),
credential);
pom.xml 파일에서 다음 종속성을 추가합니다.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.5</version>
</dependency>
azure-identity
를 사용하여 인증하고 서비스 커넥터에서 추가한 환경 변수에서 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
String url = System.getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_STORAGEBLOB_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("<AZURE_STORAGEBLOB_CLIENTID>"))
// .clientSecret(System.getenv("<AZURE_STORAGEBLOB_CLIENTSECRET>"))
// .tenantId(System.getenv("<AZURE_STORAGEBLOB_TENANTID>"))
// .build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(url)
.credential(defaultCredential)
.buildClient();
종속성 설치
pip install azure-identity
pip install azure-storage-blob
azure-identity
라이브러리를 사용하여 인증하고 서비스 커넥터에서 추가한 환경 변수에서 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
from azure.storage.blob import BlobServiceClient
import os
account_url = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
# Uncomment the following lines corresponding to the authentication type you want to use.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
blob_service_client = BlobServiceClient(account_url, credential=cred)
종속성을 설치합니다.
pip install azure-identity
pip install django-storages[azure]
azure-identity
라이브러리를 통해 인증합니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
import os
# Uncomment the following lines corresponding to the authentication type you want to use.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
파일 설정에서 다음 줄을 추가합니다. 자세한 내용은 django-storages[azure]를 참조하세요.
# in your setting file, eg. settings.py
AZURE_CUSTOM_DOMAIN = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
AZURE_ACCOUNT_NAME = AZURE_CUSTOM_DOMAIN.split('.')[0].removeprefix('https://')
AZURE_TOKEN_CREDENTIAL = cred # this is the cred acquired from above step.
종속성을 설치합니다.
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
코드에서 azidentity
라이브러리를 통해 인증합니다. 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
account_endpoint = os.Getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT")
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// cred, err := azidentity.NewDefaultAzureCredential(nil)
// for user-assigned managed identity
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
// cred, err := azidentity.NewManagedIdentityCredential(options)
// for service principal
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// tenantid := os.Getenv("AZURE_STORAGEBLOB_TENANTID")
// clientsecret := os.Getenv("AZURE_STORAGEBLOB_CLIENTSECRET")
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
if err != nil {
// error handling
}
client, err := azblob.NewBlobServiceClient(account_endpoint, cred, nil)
}
종속성 설치
npm install --save @azure/identity
npm install @azure/storage-blob
서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. @azure/identity
라이브러리를 통해 인증합니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { BlobServiceClient } = require("@azure/storage-blob");
const account_url = process.env.AZURE_STORAGEBLOB_RESOURCEENDPOINT;
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system assigned managed identity
// const credential = new DefaultAzureCredential();
// for user assigned managed identity
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_STORAGEBLOB_TENANTID;
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const clientSecret = process.env.AZURE_STORAGEBLOB_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const blobServiceClient = new BlobServiceClient(account_url, credential);
다른 언어의 경우 Azure Blob Storage 계정 URL 및 서비스 커넥터가 환경 변수에 설정하는 기타 속성을 사용하여 Azure Blob Storage에 연결할 수 있습니다. 환경 변수에 대한 자세한 내용은 Azure Blob Storage와 서비스 커넥터 통합을 참조하세요.
연결 문자열
Warning
Microsoft에서는 사용 가능한 가장 안전한 인증 흐름을 사용하는 것이 좋습니다. 이 절차에 설명된 인증 흐름은 애플리케이션에 대한 매우 높은 수준의 신뢰를 요구하며, 다른 흐름에는 존재하지 않는 위험을 수반합니다. 관리 ID와 같이 다른 보안 흐름이 실행 가능하지 않은 경우에만 이 흐름을 사용해야 합니다.
SpringBoot 클라이언트
애플리케이션 속성 |
설명 |
예제 값 |
azure.storage.account-name |
Blob 스토리지 계정 이름 |
<storage-account-name> |
azure.storage.account-key |
Blob 스토리지 계정 키 |
<account-key> |
azure.storage.blob-endpoint |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
spring.cloud.azure.storage.blob.account-name |
Spring Cloud Azure 버전 4.0 이상용 Blob Storage-account-name |
<storage-account-name> |
spring.cloud.azure.storage.blob.account-key |
Spring Cloud Azure 버전 4.0 이상용 Blob Storage 계정 키 |
<account-key> |
spring.cloud.azure.storage.blob.endpoint |
Spring Cloud Azure 버전 4.0 이상용 Blob Storage 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
기타 클라이언트
기본 환경 변수 이름 |
설명 |
예제 값 |
AZURE_STORAGEBLOB_CONNECTIONSTRING |
Blob 스토리지 연결 문자열 |
DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<account-key>;EndpointSuffix=core.windows.net |
예제 코드
연결 문자열을 사용하여 Azure Blob Storage에 연결하려면 아래 단계 및 코드를 참조하세요.
서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 연결 문자열을 가져옵니다.
종속성 설치
dotnet add package Azure.Storage.Blob
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using System;
// get Blob connection string
var connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CONNECTIONSTRING");
// Create a BlobServiceClient object
var blobServiceClient = new BlobServiceClient(connectionString);
pom.xml 파일에서 다음 종속성을 추가합니다.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
</dependency>
환경 변수에서 연결 문자열을 가져와 Azure Blob Storage에 연결합니다.
String connectionStr = System.getenv("AZURE_STORAGEBLOB_CONNECTIONSTRING");
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.connectionString(connectionStr)
.buildClient();
- 종속성 설치
pip install azure-storage-blob
- 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 연결 문자열을 가져옵니다.
from azure.storage.blob import BlobServiceClient
import os
connection_str = os.getenv('AZURE_STORAGEBLOB_CONNECTIONSTRING')
blob_service_client = BlobServiceClient.from_connection_string(connection_str)
종속성을 설치합니다.
pip install django-storages[azure]
Django 버전에 따라 Django 설정 파일에서 Azure Blob Storage 백 엔드를 구성하고 설정합니다. 자세한 내용은 django-storages[azure]를 참조하세요.
파일 설정에서 다음 줄을 추가합니다.
# in your setting file, eg. settings.py
AZURE_CONNECTION_STRING = os.getenv('AZURE_STORAGEBLOB_CONNECTIONSTRING')
- 종속성을 설치합니다.
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
- 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 연결 문자열을 가져옵니다.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
connection_str = os.LookupEnv("AZURE_STORAGEBLOB_CONNECTIONSTRING")
client, err := azblob.NewClientFromConnectionString(connection_str, nil);
}
- 종속성 설치
npm install @azure/storage-blob
- 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 연결 문자열을 가져옵니다.
const { BlobServiceClient } = require("@azure/storage-blob");
const connection_str = process.env.AZURE_STORAGEBLOB_CONNECTIONSTRING;
const blobServiceClient = BlobServiceClient.fromConnectionString(connection_str);
다른 언어의 경우 Azure Blob Storage 계정 URL 및 서비스 커넥터가 환경 변수에 설정하는 기타 속성을 사용하여 Azure Blob Storage에 연결할 수 있습니다. 환경 변수에 대한 자세한 내용은 Azure Blob Storage와 서비스 커넥터 통합을 참조하세요.
서비스 주체
SpringBoot 클라이언트
서비스 주체를 통한 인증은 Spring Cloud Azure 버전 4.0 이상에서만 사용할 수 있습니다.
기본 환경 변수 이름 |
설명 |
예제 값 |
spring.cloud.azure.storage.blob.account-name |
스토리지 계정의 이름 |
storage-account-name |
spring.cloud.azure.storage.blob.endpoint |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
spring.cloud.azure.storage.blob.credential.client-id |
서비스 주체의 클라이언트 ID |
00001111-aaaa-2222-bbbb-3333cccc4444 |
spring.cloud.azure.storage.blob.credential.client-secret |
서비스 주체 인증을 수행하기 위한 클라이언트 암호 |
Aa1Bb~2Cc3.-Dd4Ee5Ff6Gg7Hh8Ii9_Jj0Kk1Ll2 |
기타 클라이언트
기본 환경 변수 이름 |
설명 |
예제 값 |
AZURE_STORAGEBLOB_RESOURCEENDPOINT |
Blob 스토리지 엔드포인트 |
https://<storage-account-name>.blob.core.windows.net/ |
AZURE_STORAGEBLOB_CLIENTID |
클라이언트 ID |
<client-ID> |
AZURE_STORAGEBLOB_CLIENTSECRET |
클라이언트 암호 |
<client-secret> |
AZURE_STORAGEBLOB_TENANTID |
테넌트 ID |
<tenant-ID> |
예제 코드
서비스 주체를 사용하여 Azure Blob Storage에 연결하려면 아래 단계 및 코드를 참조하세요.
azure-identity
를 사용하여 관리 ID 또는 서비스 주체를 통해 인증할 수 있습니다. 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
종속성 설치
dotnet add package Azure.Identity
관리 ID 또는 서비스 주체를 사용하여 Blob Storage에 연결하는 샘플 코드는 다음과 같습니다.
using Azure.Identity;
using Azure.Storage.Blobs;
// get Blob endpoint
var blobEndpoint = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var blobServiceClient = new BlobServiceClient(
new Uri(blobEndpoint),
credential);
pom.xml 파일에서 다음 종속성을 추가합니다.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.5</version>
</dependency>
azure-identity
를 사용하여 인증하고 서비스 커넥터에서 추가한 환경 변수에서 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
String url = System.getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_STORAGEBLOB_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("<AZURE_STORAGEBLOB_CLIENTID>"))
// .clientSecret(System.getenv("<AZURE_STORAGEBLOB_CLIENTSECRET>"))
// .tenantId(System.getenv("<AZURE_STORAGEBLOB_TENANTID>"))
// .build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(url)
.credential(defaultCredential)
.buildClient();
종속성 설치
pip install azure-identity
pip install azure-storage-blob
azure-identity
라이브러리를 사용하여 인증하고 서비스 커넥터에서 추가한 환경 변수에서 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
from azure.storage.blob import BlobServiceClient
import os
account_url = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
# Uncomment the following lines corresponding to the authentication type you want to use.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
blob_service_client = BlobServiceClient(account_url, credential=cred)
종속성을 설치합니다.
pip install azure-identity
pip install django-storages[azure]
azure-identity
라이브러리를 통해 인증합니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
import os
# Uncomment the following lines corresponding to the authentication type you want to use.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
파일 설정에서 다음 줄을 추가합니다. 자세한 내용은 django-storages[azure]를 참조하세요.
# in your setting file, eg. settings.py
AZURE_CUSTOM_DOMAIN = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
AZURE_ACCOUNT_NAME = AZURE_CUSTOM_DOMAIN.split('.')[0].removeprefix('https://')
AZURE_TOKEN_CREDENTIAL = cred # this is the cred acquired from above step.
종속성을 설치합니다.
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
코드에서 azidentity
라이브러리를 통해 인증합니다. 서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
account_endpoint = os.Getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT")
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-assigned managed identity
// cred, err := azidentity.NewDefaultAzureCredential(nil)
// for user-assigned managed identity
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
// cred, err := azidentity.NewManagedIdentityCredential(options)
// for service principal
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// tenantid := os.Getenv("AZURE_STORAGEBLOB_TENANTID")
// clientsecret := os.Getenv("AZURE_STORAGEBLOB_CLIENTSECRET")
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
if err != nil {
// error handling
}
client, err := azblob.NewBlobServiceClient(account_endpoint, cred, nil)
}
종속성 설치
npm install --save @azure/identity
npm install @azure/storage-blob
서비스 커넥터에서 추가한 환경 변수에서 Azure Blob Storage 엔드포인트 URL을 가져옵니다. @azure/identity
라이브러리를 통해 인증합니다. 아래 코드를 사용하는 경우 사용하려는 인증 유형에 대한 코드 조각 부분의 주석 처리를 제거합니다.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { BlobServiceClient } = require("@azure/storage-blob");
const account_url = process.env.AZURE_STORAGEBLOB_RESOURCEENDPOINT;
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system assigned managed identity
// const credential = new DefaultAzureCredential();
// for user assigned managed identity
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_STORAGEBLOB_TENANTID;
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const clientSecret = process.env.AZURE_STORAGEBLOB_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const blobServiceClient = new BlobServiceClient(account_url, credential);
다른 언어의 경우 Azure Blob Storage 계정 URL 및 서비스 커넥터가 환경 변수에 설정하는 기타 속성을 사용하여 Azure Blob Storage에 연결할 수 있습니다. 환경 변수에 대한 자세한 내용은 Azure Blob Storage와 서비스 커넥터 통합을 참조하세요.
다음 단계
서비스 커넥터에 대해 자세히 알아보려면 자습서를 따르세요.