Azure Cloud Shell でファイルを永続化する
初めて Cloud Shell を起動すると、ストレージ オプションを選択するようにダイアログが表示されます。 Cloud Shell を使用するたびに使用できるストア ファイルが必要な場合は、新規に作成するか、既存のストレージ リソースを選択する必要があります。 Cloud Shell では Microsoft Azure Files 共有を使用してセッション間でファイルを維持します。
- 新しいストレージ リソースを作成するには、「永続的なストレージを使った Azure Cloud Shell の概要」を参照してください。
- 既存のストレージ リソースを使用するには、既存のストレージを使った Azure Cloud Shell の概要に関する記事を参照してください。
Cloud Shell のストレージのしくみ
Cloud Shell は、次の両方の方法を使用してファイルを永続化します。
$HOME
ディレクトリの内容を格納するディスク イメージを作成します。 ディスク イメージはhttps://storageaccountname.file.core.windows.net/filesharename/.cloudconsole/acc_user.img
に保存されます。 Cloud Shell によって、このディスク イメージへの変更が自動的に同期されます。- ファイル共有を
$HOME
ディレクトリにclouddrive
としてマウントします。/home/<User>/clouddrive
パスはstorageaccountname.file.core.windows.net/filesharename
にマッピングされます。
Note
SSH キーなど、$HOME
ディレクトリ内のすべてのファイルが、マウントされたファイル共有に格納されたユーザー ディスク イメージに永続化されます。 ベスト プラクティスを使用して、$HOME
ディレクトリおよびマウントされたファイル共有の情報をセキュリティで保護してください。
ストレージ アクセスのセキュリティ保護
セキュリティのために、各ユーザーが自分のストレージ アカウントを作成する必要があります。 Azure ロールベースのアクセス制御 (RBAC) では、ユーザーはストレージ アカウント レベルで共同作成者以上のアクセス権を持つ必要があります。
Cloud Shell では、指定されたサブスクリプション内のストレージ アカウントで Azure ファイル共有が使用されます。 アクセス許可が継承されるため、サブスクリプションで十分なアクセス権を持つユーザーは、サブスクリプションに含まれるストレージ アカウントとファイル共有にアクセスできます。
ユーザーは、ストレージ アカウントまたはサブスクリプション レベルでアクセス許可を設定することによって、各自のファイルへのアクセスをロックダウンする必要があります。
Cloud Shell のストレージ アカウントには、Cloud Shell のユーザーがホーム ディレクトリで作成したファイルが格納され、これにはアクセス トークンや資格情報などの機密情報が含まれる場合があります。
Azure リソース ポリシーによるリソース作成の制限
Cloud Shell で作成したストレージ アカウントは ms-resource-usage:azure-cloud-shell
でタグ付けされます。
ユーザーが Cloud Shell でストレージ アカウントを作成するのを禁止する必要がある場合は、この特定のタグによってトリガーされる Azure リソース ポリシーを作成します。
Cloud Shell ストレージの管理
clouddrive
コマンドを使用する
Cloud Shell には、Cloud Shell 内にある Azure Files 共有を変更できるコマンドライン ツールが含まれています。 使用可能なコマンドを表示するには、clouddrive
を実行します。
Group
clouddrive :Manage storage settings for Azure Cloud Shell.
Commands
mount :Mount a file share to Cloud Shell.
unmount :Unmount a file share from Cloud Shell.
新しい clouddrive のマウント
clouddrive mount
コマンドを使用して、Cloud Shell で使用される共有を変更します。
Note
新しい共有をマウントすると、新しいユーザー イメージが $HOME
ディレクトリ用に作成されます。 前回の $HOME
イメージは、前のファイル共有に保持されます。
次のパラメーターを指定して clouddrive mount
コマンドを実行します。
clouddrive mount -s mySubscription -g myRG -n storageAccountName -f fileShareName
詳細を確認するには、clouddrive mount -h
を実行してください。
Command
clouddrive mount :Mount an Azure file share to Cloud Shell.
Mount enables mounting and associating an Azure file share to Cloud Shell.
Cloud Shell will automatically attach this file share on each session start-up.
Note: This command does not mount storage if the session is Ephemeral.
Cloud Shell persists files with both methods below:
1. Create a disk image of your $HOME directory to persist files within $HOME.
This disk image is saved in your specified file share as 'acc_sean.img'' at
'//<storageaccount>.file.storage.windows.net/<fileshare>/.cloudconsole/acc_sean.img'
2. Mount specified file share as 'clouddrive' in $HOME for file sharing.
'/home/sean/clouddrive' maps to '//<storageaccount>.file.storage.windows.net/<fileshare>'
Arguments
-s | --subscription id [Required]:Subscription ID or name.
-g | --resource-group group [Required]:Resource group name.
-n | --storage-account name [Required]:Storage account name.
-f | --file-share name [Required]:File share name.
-d | --disk-size size :Disk size in GB. (default 5)
-F | --force :Skip warning prompts.
-? | -h | --help :Shows this usage text.
clouddrive のマウント解除
Cloud Shell ファイル共有はいつでもマウント解除できます。 Cloud Shell ではマウントされたファイル共有を使う必要があるため、次回のセッション時に、Cloud Shell により別のファイル共有を作成してマウントするように求められます。
clouddrive unmount
を実行します。- プロンプトに同意して確定します。
マウントされていないファイル共有は、手動で削除するまで存在し続けます。 マウントを解除すると、Cloud Shell では後続のセッションでこのファイル共有を検索しなくなります。 詳細については、clouddrive unmount -h
を実行してください。
Command
clouddrive unmount: Unmount an Azure file share from Cloud Shell.
Unmount enables unmounting and disassociating a file share from Cloud Shell.
All current sessions will be terminated. Machine state and non-persisted files will be lost.
You will be prompted to create and mount a new file share on your next session.
Your previously mounted file share will continue to exist.
Note: This command does not unmount storage if the session is Ephemeral.
Arguments
None
警告
このコマンドを実行してもリソースは削除されませんが、Cloud Shell にマップされているリソース グループ、ストレージ アカウント、またはファイル共有を手動で削除すると、ファイル共有内にある $HOME
ディレクトリ ディスク イメージとすべてのファイルは削除されます。 この削除操作は元に戻すことができません。
PowerShell コマンドを使う
現在のファイル共有に関する情報を得る
PowerShell の Get-CloudDrive
コマンドを使用して、ファイル共有をバッキングするリソースに関する情報を取得します。
PS /home/user> Get-CloudDrive
FileShareName : cs-user-microsoft-com-xxxxxxxxxxxxxxx
FileSharePath : //cs7xxxxxxxxxxxxxxx.file.core.windows.net/cs-user-microsoft-com-xxxxxxxxxxxxxxx
MountPoint : /home/user/clouddrive
Name : cs7xxxxxxxxxxxxxxx
ResourceGroupName : cloud-shell-storage-southcentralus
StorageAccountName : cs7xxxxxxxxxxxxxxx
SubscriptionId : 78a66d97-7204-4a0d-903f-43d3d4170e5b
ファイル共有のマウント解除
Dismount-CloudDrive
コマンドレットを使用すると、Cloud Shell ファイル共有はいつでもマウント解除できます。
clouddrive
をマウント解除すると、現在のセッションが終了します。
Dismount-CloudDrive
Do you want to continue
Dismounting clouddrive will terminate your current session. You will be prompted to create and
mount a new file share on your next session
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):