Azure ファイル共有の AD DS 認証を有効にする

このアーティクルでは、Azure ファイル共有に対する認証にオンプレミスの Active Directory (AD) 資格情報を使用するために、ストレージ アカウントで Active Directory Domain Services (AD DS) 認証を有効にするプロセスについて説明します。

重要

AD DS 認証を有効にする前に、サポートされているシナリオと要件を理解するために概要記事を参照し、必要な前提条件が満たされていることを確認してください。 Active Directory 環境が複数のフォレストに存在している場合は、「複数の Active Directory フォレストで Azure Files を使用する」を参照してください。

Azure ファイル共有に対する SMB 経由の AD DS 認証を有効にするには、Azure ストレージ アカウントをオンプレミスの AD DS に登録してから、ストレージ アカウントに必要なドメイン プロパティを設定する必要があります。 ストレージ アカウントを AD DS に登録するには、それを表すコンピューター アカウント (またはサービス ログオンア カウント) を AD DS 内に作成します。 このプロセスは、オンプレミスの Windows ファイル サーバーを表すアカウントを AD DS 内に作成するのと同じように考えます。 機能は、ストレージ アカウントで有効になると、アカウント内のすべての新規および既存のファイル共有に適用されます。

適用対象

ファイル共有の種類 SMB NFS
Standard ファイル共有 (GPv2)、LRS/ZRS Yes No
Standard ファイル共有 (GPv2)、GRS/GZRS Yes No
Premium ファイル共有 (FileStorage)、LRS/ZRS Yes No

AzFilesHybrid PowerShell モジュールには、Azure Files をデプロイおよび構成するためのコマンドレットが用意されています。 これには、ストレージ アカウントをオンプレミスの Active Directory にドメイン参加させ、DNS サーバーを構成するためのコマンドレットが含まれています。 このコマンドレットは、ユーザーの代わりに必要な変更を行い、機能を有効にします。 コマンドレットの一部はオンプレミスの AD DS とやり取りするため、ここではコマンドレットの動作について説明します。これにより、変更がコンプライアンス ポリシーとセキュリティ ポリシーに適合するかどうかを判断し、コマンドレットを実行するための適切なアクセス許可を持っていることを確認できます。 AzFilesHybrid モジュールを使用することをお勧めしますが、そうできない場合は、手動の手順を用意しています。

重要

AES-256 Kerberos 暗号化は、AzFilesHybrid モジュールでサポートされる唯一の暗号化方法になりました。 RC4 暗号化を使う場合は、「オプション 2: 有効化アクションを手動で実行する」を参照してください。 既定の暗号化方法として RC4 を使う古い AzFilesHybrid バージョン (v0.2.2 より前) でこの機能を以前に有効にしていて、AES-256 をサポートするように更新したい場合は、Azure Files SMB 認証のトラブルシューティングに関する記事を参照してください。

前提条件

  • .NET Framework 4.7.2 以降 がインストールされていない場合は、今すぐインストールします。 これは、AzFilesHybrid モジュールを正常にインポートするために必要です。
  • Azure PowerShell (Az モジュール) と Az.Storage がインストールされていることを確認します。 AzFilesHybrid を使用するには、少なくとも Az.PowerShell 2.8.0 以降と Az.Storage 4.3.0 以降が必要です。
  • Active Directory PowerShell モジュールをインストールします。

AzFilesHybrid モジュールをダウンロードする

AzFilesHybrid モジュールで最新バージョンをダウンロードして解凍します

Join-AzStorageAccount を実行する

Join-AzStorageAccount コマンドレットでは、指定されたストレージ アカウントに代わってオフライン ドメイン参加に相当することを行います。 次のスクリプトは、このコマンドレットを使って、AD ドメインにコンピューター アカウントを作成します。 何らかの理由でコンピューター アカウントを使用できない場合は、代わりにサービス ログオン アカウントを作成するようにスクリプトを変更できます。 サービス ログオン アカウントでの AES-256 暗号化の使用は、AzFilesHybrid バージョン 0.2.5 以降でサポートされています。

コマンドレットによって作成された AD DS アカウントは、ストレージ アカウントを表します。 AD DSアカウントが、パスワードの有効期限を適用する組織単位 (OU) の下で作成されている場合は、パスワードの有効期間の前にパスワードを更新する必要があります。 その日付の前までにアカウント パスワードが更新されない場合は、Azure ファイル共有にアクセスするときに認証エラーが発生します。 パスワードを更新する方法については、AD DS アカウント パスワードを更新する方法に関する記事を参照してください。

重要

Join-AzStorageAccount コマンドレットは、AD のストレージ アカウント (ファイル共有) を表す AD アカウントを作成します。 コンピューター アカウントまたはサービス ログオン アカウントのどちらとして登録するかを選択できます。詳細については、FAQ を参照してください。 AD ドメインまたは OU で既定のパスワード有効期限が設定されている場合、サービス ログオン アカウントのパスワードが AD で期限切れになることがあります。 コンピューター アカウントのパスワードの変更は AD ではなくクライアント コンピューターによって行われます。このため、クライアント コンピューターでは既定で 30 日ごとにパスワードが変更されますが、AD では期限切れになりません。 どちらのアカウントの種類でも、構成されているパスワードの有効期限を確認し、パスワードの有効期間が終了する前に、AD アカウントのストレージ アカウント ID のパスワードを更新するよう計画することをお勧めします。 AD で新しい AD 組織単位を作成し、それぞれコンピューター アカウントまたはサービス ログオン アカウントのパスワードの有効期限のポリシーを無効にすることを検討できます。

ターゲット AD でコンピューター アカウントまたはサービス ログオン アカウントを作成するアクセス許可がある オンプレミスの AD DS 資格情報 (ドメイン管理者など) を使って、オンプレミスの AD DS にドメイン参加しているデバイスに、PowerShell 5.1 で以下のスクリプトを実行する必要があります。 最小特権の原則に従うには、オンプレミスの AD DS 資格情報に次の Azure ロールが必要です。

  • ターゲット ストレージ アカウントが配置されているリソース グループの閲覧者
  • AD DS に参加するストレージ アカウントの共同作成者

AD DS のストレージ アカウントへの参加に使用されるアカウントが、ターゲット リソースが配置されている Azure サブスクリプションの所有者または共同作成者である場合、そのアカウントは既に参加を実行できるように設定されており、それ以上の割り当ては必要ありません。

AD DS の資格情報には、ターゲット AD でコンピューター アカウントまたはサービス ログオン アカウントを作成するためのアクセス許可も必要です。 スクリプトを実行する前に、プレースホルダーの値を独自の値に置き換えます。

# Change the execution policy to unblock importing AzFilesHybrid.psm1 module
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

# Navigate to where AzFilesHybrid is unzipped and stored and run to copy the files into your path
.\CopyToPSPath.ps1 

# Import AzFilesHybrid module
Import-Module -Name AzFilesHybrid

# Login to Azure using a credential that has either storage account owner or contributor Azure role 
# assignment. If you are logging into an Azure environment other than Public (ex. AzureUSGovernment) 
# you will need to specify that.
# See https://learn.microsoft.com/azure/azure-government/documentation-government-get-started-connect-with-ps
# for more information.
Connect-AzAccount

# Define parameters
# $StorageAccountName is the name of an existing storage account that you want to join to AD
# $SamAccountName is the name of the to-be-created AD object, which is used by AD as the logon name 
# for the object. It must be 15 characters or less and has certain character restrictions.
# Make sure that you provide the SamAccountName without the trailing '$' sign.
# See https://learn.microsoft.com/windows/win32/adschema/a-samaccountname for more information.
$SubscriptionId = "<your-subscription-id-here>"
$ResourceGroupName = "<resource-group-name-here>"
$StorageAccountName = "<storage-account-name-here>"
$SamAccountName = "<sam-account-name-here>"
$DomainAccountType = "<ComputerAccount|ServiceLogonAccount>" # Default is set as ComputerAccount
# If you don't provide the OU name as an input parameter, the AD identity that represents the 
# storage account is created under the root directory.
$OuDistinguishedName = "<ou-distinguishedname-here>"
# Encryption method is AES-256 Kerberos.

# Select the target subscription for the current session
Select-AzSubscription -SubscriptionId $SubscriptionId 

# Register the target storage account with your active directory environment under the target OU 
# (for example: specify the OU with Name as "UserAccounts" or DistinguishedName as 
# "OU=UserAccounts,DC=CONTOSO,DC=COM"). You can use this PowerShell cmdlet: Get-ADOrganizationalUnit 
# to find the Name and DistinguishedName of your target OU. If you are using the OU Name, specify it 
# with -OrganizationalUnitName as shown below. If you are using the OU DistinguishedName, you can set it 
# with -OrganizationalUnitDistinguishedName. You can choose to provide one of the two names to specify 
# the target OU. You can choose to create the identity that represents the storage account as either a 
# Service Logon Account or Computer Account (default parameter value), depending on your AD permissions 
# and preference. Run Get-Help Join-AzStorageAccountForAuth for more details on this cmdlet.

Join-AzStorageAccount `
        -ResourceGroupName $ResourceGroupName `
        -StorageAccountName $StorageAccountName `
        -SamAccountName $SamAccountName `
        -DomainAccountType $DomainAccountType `
        -OrganizationalUnitDistinguishedName $OuDistinguishedName

# You can run the Debug-AzStorageAccountAuth cmdlet to conduct a set of basic checks on your AD configuration 
# with the logged on AD user. This cmdlet is supported on AzFilesHybrid v0.1.2+ version. For more details on 
# the checks performed in this cmdlet, see Azure Files Windows troubleshooting guide.
Debug-AzStorageAccountAuth -StorageAccountName $StorageAccountName -ResourceGroupName $ResourceGroupName -Verbose

オプション 2:有効化アクションを手動で実行する

ほとんどのお客様は、上記のオプション 1 を選択し、AzFilesHybrid PowerShell モジュールを使用して、Azure Files による AD DS 認証を有効にする必要があります。 ただし、Active Directory PowerShell を使用してステップを手動で実行する場合は、こちらにステップの概要を示します。

重要

前述の Join-AzStorageAccount スクリプトを既に正常に実行している場合は、そのまま、セクション「機能が有効になっていることを確認する」に進んでください。 次の手動の手順を実行する必要はありません。

環境をチェックする

まず、環境の状態を確認します。

  • Active Directory PowerShell がインストールされているかどうかと、シェルが管理者特権で実行されているかどうかを確認します。
  • Az.Storage モジュールがインストールされていることを確認し、まだの場合はインストールします。 バージョン 2.0 以降が必要です。
  • これらの検査が完了したら、AD DS を調べて、コンピューター アカウント (既定値)、あるいは "cifs/ここはご利用のストレージ アカウントの名前.file.core.windows.net" などの SPN または UPN を使用して既に作成されているサービス ログオン アカウントがあるかどうかを確認します。 アカウントが存在しない場合は、次のセクションの説明に従って作成します。

重要

このセクションのWindows Server Active Directory PowerShell コマンドレットは、Windows PowerShell 5.1 で実行する必要があります。 このシナリオでは、PowerShell 7.x と Azure Cloud Shell は機能しません。

AD のストレージ アカウントを表す ID を手動で作成する

このアカウントを手動で作成するには、まずストレージ アカウントの新しい Kerberos キーを作成し、以下の PowerShell コマンドレットを使用してアクセス キーを取得します。 このキーは、セットアップ時にのみ使用されます。 ストレージ アカウントに対する制御やデータ プレーンの操作には使用できません。

# Create the Kerberos key on the storage account and get the Kerb1 key as the password for the AD identity 
# to represent the storage account
$ResourceGroupName = "<resource-group-name-here>"
$StorageAccountName = "<storage-account-name-here>"

New-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -KeyName kerb1
Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -ListKerbKey | where-object{$_.Keyname -contains "kerb1"}

コマンドレットからはキー値が返されます。 kerb1 キーを取得したら、AD の OU にコンピューター アカウントまたはサービス アカウントを作成し、そのキーを AD ID のパスワードとして使用します。

  1. SPN を cifs/your-storage-account-name-here.file.core.windows.net に設定します。AD GUI を使用するか、Windows コマンド ラインから管理者として Setspn コマンドを実行します (サンプル テキストを実際のストレージ アカウント名に、<ADAccountName> を AD アカウント名に置き換えてください)。

    Setspn -S cifs/your-storage-account-name-here.file.core.windows.net <ADAccountName>
    
  2. ユーザー アカウントを持っている場合は、AD オブジェクトの SPN と一致するように UPN を変更します (AD PowerShell コマンドレットをインストールし、昇格した特権で PowerShell 5.1 のコマンドレットを実行する必要があります)。

    Set-ADUser -Identity $UserSamAccountName -UserPrincipalName cifs/<StorageAccountName>.file.core.windows.net@<DNSRoot>
    
  3. AD アカウントのパスワードを kerb1 キーの値に設定します。

    Set-ADAccountPassword -Identity servername$ -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "kerb1_key_value_here" -Force)
    

OU でパスワードの有効期限が適用されている場合は、パスワードの有効期間の前にパスワードを更新し、Azure ファイル共有にアクセスするときの認証エラーを防ぐ必要があります。 詳細については、「AD のストレージ アカウント ID のパスワードを更新する」を参照してください。

新しく作成された ID の SID を保持します。これは次の手順で必要になります。 自分で作成した、ストレージ アカウントを表す ID を、Microsoft Entra ID に同期する必要はありません。

ストレージ アカウントで機能を有効にする

次のコマンドを変更して、ドメイン プロパティの構成の詳細を次のコマンドに含め、それを実行して機能を有効にします。 次のコマンドで必要なストレージ アカウント SID は、前のセクションの AD DS で作成した ID の SID です。 ActiveDirectorySamAccountName プロパティを、末尾の '$' 記号なしで指定してください。

# Set the feature flag on the target storage account and provide the required AD domain information
Set-AzStorageAccount `
        -ResourceGroupName "<your-resource-group-name>" `
        -Name "<your-storage-account-name>" `
        -EnableActiveDirectoryDomainServicesForFile $true `
        -ActiveDirectoryDomainName "<your-domain-dns-root>" `
        -ActiveDirectoryNetBiosDomainName "<your-domain-dns-root>" `
        -ActiveDirectoryForestName "<your-forest-name>" `
        -ActiveDirectoryDomainGuid "<your-guid>" `
        -ActiveDirectoryDomainsid "<your-domain-sid>" `
        -ActiveDirectoryAzureStorageSid "<your-storage-account-sid>" `
        -ActiveDirectorySamAccountName "<your-domain-object-sam-account-name>" `
        -ActiveDirectoryAccountType "<your-domain-object-account-type, the value could be 'Computer' or 'User'>"

AES-256 暗号化を有効にするには、このセクションの手順に従ってください。 RC4 暗号化を使用する予定の場合は、このセクションを省略します。

重要

AES-256 暗号化を有効にするには、ストレージ アカウントを表すドメイン オブジェクトが、オンプレミス AD ドメインのコンピューター アカウント (既定値) またはサービス ログオン アカウントである必要があります。 ドメイン オブジェクトがこの要件を満たしていない場合は、削除して、要件を満たす新しいドメイン オブジェクトを作成します。 また、オブジェクトの msDS-SupportedEncryptionTypes 属性に対する書き込みアクセス権も必要です。

AES-256 のサポートを構成するために実行するコマンドレットは、ストレージ アカウントを表すドメイン オブジェクトがコンピューター アカウントかサービス ログオン アカウント (ユーザー アカウント) かによって異なります。 どちらの場合も、AD PowerShell コマンドレットをインストールし、昇格された特権を使用して PowerShell 5.1 でコマンドレットを実行する必要があります。

コンピューター アカウントで AES-256 暗号化を有効にするには、次のコマンドを実行します。 <domain-object-identity><domain-name> を独自の値に置き換えます。

Set-ADComputer -Identity <domain-object-identity> -Server <domain-name> -KerberosEncryptionType "AES256"

サービス ログオン アカウントで AES-256 暗号化を有効にするには、次のコマンドを実行します。 <domain-object-identity><domain-name> を独自の値に置き換えます。

Set-ADUser -Identity <domain-object-identity> -Server <domain-name> -KerberosEncryptionType "AES256"

上記のコマンドレットを実行した後、次のスクリプトの <domain-object-identity> を実際の値に置き換えてから、スクリプトを実行してドメイン オブジェクトのパスワードを更新します。

$KeyName = "kerb1" # Could be either the first or second kerberos key, this script assumes we're refreshing the first
$KerbKeys = New-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -KeyName $KeyName
$KerbKey = $KerbKeys.keys | Where-Object {$_.KeyName -eq $KeyName} | Select-Object -ExpandProperty Value
$NewPassword = ConvertTo-SecureString -String $KerbKey -AsPlainText -Force

Set-ADAccountPassword -Identity <domain-object-identity> -Reset -NewPassword $NewPassword

重要

以前に RC4 暗号化を使用していて、AES-256 を使用するようにストレージ アカウントを更新する場合は、クライアントで klist purge を実行してからファイル共有を再マウントして、AES-256 を使用した新しい Kerberos チケットを取得する必要があります。

デバッグ

必要に応じて、Debug-AzStorageAccountAuth コマンドレットを実行し、ログオンした AD ユーザーで AD の構成に対する一連の基本的なチェックを実施できます。 このコマンドレットは、AzFilesHybrid バージョン 0.1.2 以降でサポートされています。 このコマンドレットは、AD DS 認証にのみ適用できます。 Microsoft Entra Domain Services または Microsoft Entra Kerberos 対応ストレージ アカウントでは機能しません。 このコマンドレットで実行される検査の詳細については、「AD 資格情報を使用して Azure ファイル共有をマウントできない」を参照してください。

Debug-AzStorageAccountAuth -StorageAccountName $StorageAccountName -ResourceGroupName $ResourceGroupName -Verbose

機能が有効になっていることを確認する

次のスクリプトを使用して、ストレージ アカウントで Active Directory が有効になっているかどうかを確認することができます。

# Get the target storage account
$storageaccount = Get-AzStorageAccount `
        -ResourceGroupName "<your-resource-group-name-here>" `
        -Name "<your-storage-account-name-here>"

# List the directory service of the selected service account
$storageAccount.AzureFilesIdentityBasedAuth.DirectoryServiceOptions

# List the directory domain information if the storage account has enabled AD DS authentication for file shares
$storageAccount.AzureFilesIdentityBasedAuth.ActiveDirectoryProperties

正常に終了した場合、出力は次のようになります。

DomainName:<yourDomainHere>
NetBiosDomainName:<yourNetBiosDomainNameHere>
ForestName:<yourForestNameHere>
DomainGuid:<yourGUIDHere>
DomainSid:<yourSIDHere>
AzureStorageID:<yourStorageSIDHere>

次のステップ

これで、ストレージ アカウントで AD DS が正常に有効になりました。 この機能を使用するには、共有レベルのアクセス許可を割り当てる必要があります。