0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure Functions と Web Apps で実現する、マネージドID + サービスエンドポイントの使い方

Posted at

こんにちは!🌱 新緑の香りが漂う季節、クラウドエンジニアの皆さん。今日は、Azure のセキュアな接続の最前線についてお話ししますよと。

🚀 統合アーキテクチャの全貌

ネットワーク統合のアーキテクチャ

セキュリティ統合の詳細フロー

リソース間の相互作用モデル

📋 統合パターン詳細

1. Azure Functions での実装

Blob Storageへの接続

public class SecureBlobFunction
{
    private readonly BlobServiceClient _blobServiceClient;

    public SecureBlobFunction(
        [Microsoft.Azure.WebJobs.Inject] 
        TokenCredential credential)
    {
        _blobServiceClient = new BlobServiceClient(
            new Uri("https://mystorageaccount.blob.core.windows.net"),
            credential
        );
    }

    [FunctionName("ProcessBlob")]
    public async Task Run(
        [BlobTrigger("mycontainer/{name}")] Stream myBlob, 
        string name)
    {
        // 安全なBlobストレージ操作
        var containerClient = _blobServiceClient
            .GetBlobContainerClient("mycontainer");
        
        // 追加のセキュアな処理
    }
}

Cosmos DBへの接続

public class SecureCosmosFunction
{
    private readonly CosmosClient _cosmosClient;

    public SecureCosmosFunction(
        [Microsoft.Azure.WebJobs.Inject] 
        TokenCredential credential)
    {
        _cosmosClient = new CosmosClient(
            "https://mycosmosaccount.documents.azure.net",
            credential,
            new CosmosClientOptions 
            { 
                ConnectionMode = ConnectionMode.Gateway 
            }
        );
    }

    [FunctionName("ProcessData")]
    public async Task Run(
        [CosmosDBTrigger(
            databaseName: "MyDatabase",
            collectionName: "MyCollection"
        )] IReadOnlyList<dynamic> documents)
    {
        // 安全なCosmos DB操作
        var database = _cosmosClient.GetDatabase("MyDatabase");
        // 追加の処理
    }
}

2. Web Apps での実装

統合サービス

public class IntegratedStorageService
{
    private readonly BlobServiceClient _blobServiceClient;
    private readonly CosmosClient _cosmosClient;

    public IntegratedStorageService(DefaultAzureCredential credential)
    {
        // Blob Storageへの安全な接続
        _blobServiceClient = new BlobServiceClient(
            new Uri("https://mystorageaccount.blob.core.windows.net"),
            credential
        );

        // Cosmos DBへの安全な接続
        _cosmosClient = new CosmosClient(
            "https://mycosmosaccount.documents.azure.net",
            credential,
            new CosmosClientOptions 
            { 
                ConnectionMode = ConnectionMode.Gateway 
            }
        );
    }

    public async Task ProcessDataAsync()
    {
        // 統合された安全な操作
        var containerClient = _blobServiceClient
            .GetBlobContainerClient("mycontainer");
        var database = _cosmosClient.GetDatabase("MyDatabase");
    }
}

🛠️ Azure CLI による設定手順

サービスエンドポイントの有効化

# VNetの作成
az network vnet create \
    --name MyVNet \
    --resource-group MyResourceGroup \
    --address-prefix 10.0.0.0/16 \
    --subnet-name MySubnet \
    --subnet-prefix 10.0.1.0/24

# サービスエンドポイントの有効化
az network vnet subnet update \
    --vnet-name MyVNet \
    --name MySubnet \
    --resource-group MyResourceGroup \
    --service-endpoints "Microsoft.Storage" "Microsoft.AzureCosmosDB"

# ストレージアカウントの設定
az storage account network-rule add \
    --resource-group MyResourceGroup \
    --account-name MyStorageAccount \
    --vnet-name MyVNet \
    --subnet MySubnet

# Cosmos DBの設定
az cosmosdb update \
    --name MyCosmosAccount \
    --resource-group MyResourceGroup \
    --enable-virtual-network true \
    --virtual-network-rules "/subscriptions/{sub-id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{subnet}"

🔒 サービスエンドポイントの詳細メカニズム

エンドポイント接続の仕組み

ネットワークセキュリティの多層防御

🔒 セキュリティ設定のチェックリスト

マネージドID設定

  • Functionsアプリでシステム割り当てマネージドIDを有効化
  • Web Appsでシステム割り当てマネージドIDを有効化
  • 最小権限のロール割り当て

ネットワーク設定

  • サービスエンドポイントの有効化
  • ファイアウォールルールの厳密な設定
  • パブリックネットワークアクセスの制限

💡 推奨プラクティス

  1. 常にマネージドIDを使用
  2. サービスエンドポイントで通信を制御
  3. Azure Key Vaultで追加の保護
  4. 定期的なセキュリティ監査

🌟 最終アドバイス

クラウドセキュリティは、まるで春の庭園のように、継続的なケアと注意が必要です。完璧を求めるのではなく、常に改善し続けることが大切です。

セキュリティ豆知識

  • マネージドIDは自動的に資格情報を管理
  • サービスエンドポイントは追加コストなし
  • 定期的な権限の見直しが重要

Happy & Secure Coding! 🛡️🚀

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?