Connecting a bucket as a disk in Windows
In this tutorial, you will use rclone
Note
This section describes how to connect a bucket in Windows. When connecting with other OSs, see this rclone guide
To mount your bucket as a disk:
- Get your cloud ready.
- Set up the runtime environment.
- Create a service account.
- Create a static access key.
- Create a bucket.
- Set up a connection to Object Storage.
- Mount your bucket.
- Set up automatic mounting.
If you no longer need the resources you created, delete them.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
Required paid resources
The cost for bucket support includes:
- Fee for storing data in a bucket (see Object Storage pricing).
- Fee for data operations (see Object Storage pricing).
Set up the runtime environment
-
Download and install the winfsp distribution
from thewinfspwebsite. -
Download the sysinternals suite utilities archive
from the Microsoft website and unpack it to your local working folder. -
Download the Windows Service Wrapper (WinSW) executable
depending on your OS configuration and save it to a dedicated folder. -
Download the rclone utility archive
from therclonewebsite and unpack it to your local working folder. -
Add the folders containing the utilities and the distribution to the
PATHvariable. Proceed as follows:- Click Start and type Change system environment variables in the Windows search bar.
- Click Environment Variables... at the bottom right.
- In the window that opens, find the
PATHparameter and click Edit. - Add your folder path to the list.
- Click OK.
Create a service account
- In the management console
, select the folder where you want to create a service account. - In the list of services, select Identity and Access Management.
- Click Create service account.
- In the Name field, specify
sa-win-disk-connect. - Click
Add role and select thestorage.editorrole. - Click Create service account.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
- Create a service account named
sa-win-disk-connect:
yc iam service-account create --name sa-win-disk-connect
The naming requirements are as follows:
- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
For more information about the yc iam service-account create command, see the CLI reference.
- Assign the
storage.editorrole to the service account:
yc resource-manager folder add-access-binding <folder_ID> \
--role storage.editor \
--subject serviceAccount:<service_account_ID>
For more information about the yc resource-manager folder add-access-binding command, see the CLI reference.
-
To create a service account, use the create method for the ServiceAccount resource.
-
Assign the
storage.editorrole to the service account.
To work with objects in an encrypted bucket, a user or service account must have the following roles for the encryption key in addition to the storage.configurer role:
kms.keys.encrypter: To read the key, encrypt and upload objects.kms.keys.decrypter: To read the key, decrypt and download objects.kms.keys.encrypterDecrypter: This role includes thekms.keys.encrypterandkms.keys.decrypterpermissions.
For more information, see Key Management Service service roles.
Create a static access key
- In the management console
, navigate to the folder the service account belongs to. - From the list of services, select Identity and Access Management.
- In the left-hand panel, select
Service accounts. - In the list that opens, select
sa-win-disk-connect. - In the top panel, click
Create new key. - Select Create static access key.
- Specify the key description and click Create.
- Save the ID and secret key. After you close this dialog, the key value will no longer be available.
-
Create an access key for the
sa-win-disk-connectservice account:yc iam access-key create --service-account-name sa-win-disk-connectResult:
access_key: id: aje6t3vsbj8l******** service_account_id: ajepg0mjt06s******** created_at: "2022-07-18T14:37:51Z" key_id: 0n8X6WY6S24N7Oj***** secret: JyTRFdqw8t1kh2-OJNz4JX5ZTz9Dj1rI9hx*****For more information about the
yc iam access-key createcommand, see the CLI reference. -
Save
key_idandsecret. You will not be able to get the secret key again.
As a result, you will get the static access key data. To authenticate in Object Storage, you will need the following:
key_id: Static access key IDsecret: Secret key
Save key_id and secret: you will not be able to get the key value again.
Create a bucket
- In the management console
, select the folder where you want to create a bucket. - In the list of services, select Object Storage.
- At the top right, click Create bucket.
- In the ** Name** field, enter a name for the bucket consistent with the naming requirements.
- In the Read objects, Read object list, and Read settings fields, select With authorization.
- Click Create bucket.
-
If you do not have the AWS CLI yet, install and configure it.
-
Create a bucket by entering its name following the naming requirements:
aws --endpoint-url https://storage.yandexcloud.net \ s3 mb s3://<bucket_name>Result:
make_bucket: <bucket_name>
Note
Terraform uses a service account to interact with Object Storage. Assign to the service account the required role, e.g., storage.admin, for the folder where you are going to create resources.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Describe the properties for creating a service account and access key in the configuration file:
... // Creating a service account resource "yandex_iam_service_account" "sa" { name = "<service_account_name>" } // Assigning a role to a service account resource "yandex_resourcemanager_folder_iam_member" "sa-admin" { folder_id = "<folder_ID>" role = "storage.admin" member = "serviceAccount:${yandex_iam_service_account.sa.id}" } // Creating a static access key resource "yandex_iam_service_account_static_access_key" "sa-static-key" { service_account_id = yandex_iam_service_account.sa.id description = "static access key for object storage" } -
Add a section with bucket properties to the configuration file and enter the bucket name following the naming requirements:
resource "yandex_storage_bucket" "<bucket_name>" { access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key bucket = "<bucket_name>" }For more information about the
yandex_storage_bucketresource, see this Terraform provider guide. -
Make sure the configuration files are correct.
-
In the command line, navigate to the directory where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration description is correct, the terminal will display a list of the resources being created and their settings. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply -
Confirm creating the resources: type
yesin the terminal and press Enter.
-
Use the create REST API method for the Bucket resource, the BucketService/Create gRPC API call, or the create S3 API method.
Set up a connection to Object Storage
-
Launch the PowerShell command line, navigate to the folder with the
rcloneutility and run its configuration session:./rclone.exe config -
Follow the prompts to create a new connection profile:
- Start creating a new profile by entering
nin the terminal. - Enter the connection name:
s3-connect. - Select the storage type by entering
4in the terminal. - Select the provider by entering
1in the terminal. - Select manual entry of credentials by entering
1in the terminal. - In the terminal, enter the secret key ID you got previously.
- In the terminal, enter the secret key value you got previously.
- Specify the region by entering
ru-central1in the terminal. - Specify the endpoint by entering
storage.yandexcloud.netin the terminal. - You can leave all other settings at their defaults by pressing Enter to skip them.
- Start creating a new profile by entering
Note
You can perform advanced connection setup if required. To do this, type y at the Edit advanced config? step. For more information about advanced settings, see the rclone documentation
Mount a bucket
-
Check your connection to the bucket. In the same command line window you used to configure the connection, run the following command with the bucket name specified:
./rclone.exe ls s3-connect:<bucket_name>If your configuration is correct, you will see a list of objects in the bucket.
-
Mount your bucket to the file system specifying the bucket name and an available drive letter in the file system:
./rclone.exe mount s3-connect:<bucket_name> <disk_letter>: --vfs-cache-mode full --file-perms 0777 --dir-perms 0777You will see a new disk with the objects from the bucket in Windows Explorer.
-
To unmount the bucket, press Ctrl + C.
Set up automatic mounting
For the bucket to mount automatically when the user logs in, create a VBScript
-
In the working folder on your local PC, create a file named
bucket_mount.vbsand paste the following code into it:Set WshShell = CreateObject("WScript.Shell") command = "<path_to_rclone_folder>\rclone.exe mount s3-connect:<bucket_name> <drive_letter>: --vfs-cache-mode full --file-perms 0777 --dir-perms 0777" WshShell.Run command, 0, FalseIn the file, specify the bucket name, drive letter, and full path to
rclone.exe. For example,C:\bucket-mounter\rclone\rclone.exe. -
Open your system registry editor,
regedit.exe, and proceed as follows in the window that opens:- Go to the
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Runbranch and create a string parameter namedbucket-mounterin it. - Change the
bucket-mounterparameter value to full path to the VBS script file created earlier. For example:C:\bucket-mounter\bucket_mount.vbs
- Go to the
From now on, your bucket will automatically mount into the OS each time the user logs on to the PC.
How to delete the resources you created
To stop paying for the resources you created:
- Delete the objects from the bucket.
- Delete the bucket.