Managing device passwords
For devices and registries to begin exchanging data and commands, you need to log in. This section describes how to manage device passwords for the appropriate authorization method.
Note
When using an X.509 certificate along with a password, the password has higher priority.
Adding a password to a device
You can add a password to an already created device or set it when creating a device using the --password
parameter.
Note
You can also set a password from the input stream. To do this, use the --read-password
flag instead of the --password
parameter.
Adding a password to an existing device
To add a password to an existing device:
- In the management console
, select the folder where you want to add a password for an existing device. - Select IoT Core.
- Select the registry with the required device from the list.
- On the left side of the window, select the Devices section.
- Select the device from the list.
- Under Passwords, click Add password.
- In the Password field, enter the password you will use to access the device.
To create a password, you can use the password generator .
Make sure to save your password, as you will need it later. - Click Add.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
To add a password:
-
Get a list of devices in the registry:
yc iot device --registry-name my-registry list
Result:
+----------------------+--------+ | ID | NAME | +----------------------+--------+ | arenak5ciqss******** | second | | areqjd6un3af******** | first | +----------------------+--------+
-
Add a password to the device:
yc iot device password add --device-name first --password Passw0rdForDevice
Result:
device_id: areqjd6un3af******** id: areqjd6un3af******** created_at: "2019-12-16T15:11:36.892167Z"
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To add a password to a device created using Terraform:
-
In the configuration file, describe the parameters of the resource to create:
yandex_iot_core_registry
: Device properties:registry_id
: ID of the registry where the device was created.name
: Device name.description
: Device description.passwords
: List of passwords for authorization with login and password.
Here is an example of the resource structure in the configuration file:
resource "yandex_iot_core_device" "my_device" { registry_id = "<registry_ID>" name = "<device_name>" description = "test device for terraform provider documentation" ... passwords = [ "<password>", ] ... }
For more information about the
yandex_iot_core_device
resource parameters in Terraform, see the relevant provider documentation . -
In the command line, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can verify device passwords in the management console
or using the following CLI command:yc iot device password list --device-name <device_name>
To add a password to a device, use the addPassword REST API method for the Device resource or the DeviceService/AddPassword gRPC API call.
Setting a password for a device when creating it
For information about how to set a password for a device when creating it, see Creating a device.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To set a password when creating a device:
-
Get a list of registries in the folder:
yc iot registry list
Result:
+----------------------+-------------------+ | ID | NAME | +----------------------+-------------------+ | arenou2oj4ct******** | my-registry | +----------------------+-------------------+
-
Create a device with a password:
yc iot device create --registry-name my-registry --name device-with-pass --password Passw0rdForDevice
Result:
id: arepomfambsg******** registry_id: arenou2oj4ct******** created_at: "2019-12-16T15:18:39.358922Z" name: device-with-pass
For information about how to set a password for a device when creating it, see Creating a device.
To set a password for a device when creating it, use the create REST API method for the Device resource or the DeviceService/Create gRPC API call.
Getting a list of device passwords
To view the list of device passwords:
- In the management console
, select the folder to get the list of device passwords for. - Select IoT Core.
- Select the registry with the required device from the list.
- On the left side of the window, select the Devices section.
- Select the device from the list.
- On the Overview page, go to the Passwords section.
The list of device passwords will be displayed in the Passwords section.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of passwords:
-
Get a list of devices in the registry:
yc iot device --registry-name my-registry list
Result:
+----------------------+------------------+ | ID | NAME | +----------------------+------------------+ | arenak5ciqss******** | second | | arepomfambsg******** | device-with-pass | | areqjd6un3af******** | first | +----------------------+------------------+
-
Get a list of device passwords:
yc iot device password list --device-name device-with-pass
Result:
+----------------------+---------------------+ | ID | CREATED AT | +----------------------+---------------------+ | areuin5t7pnd******** | 2019-12-16 15:18:39 | +----------------------+---------------------+
To get a list of device passwords, use the listPasswords REST API method for the Device resource or the DeviceService/ListPasswords gRPC API call.
Deleting a device password
To delete a device password:
- In the management console
, select the folder to delete a device password from. - Select IoT Core.
- Select the registry with the required device from the list.
- On the left side of the window, select the Devices section.
- Select the device from the list.
- In the row with the password, click
and select Delete from the drop-down list. - In the window that opens, click Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To delete a password:
-
Get a list of device passwords:
yc iot device password list --device-name device-with-pass
Result:
+----------------------+---------------------+ | ID | CREATED AT | +----------------------+---------------------+ | areuin5t7pnd******** | 2019-12-16 15:18:39 | +----------------------+---------------------+
-
Delete the password:
yc iot device password delete --device-name device-with-pass --password-id areuin5t7pnd********
-
Make sure that the password was deleted:
yc iot device password list --device-name device-with-pass
Result:
+----+------------+ | ID | CREATED AT | +----+------------+ +----+------------+
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To delete the password of a device created using Terraform:
-
Open the Terraform configuration file and delete the password value in the
passwords
section, in the device description fragment. To delete all passwords, delete the entirepasswords
section.Example device description in the Terraform configuration:
resource "yandex_iot_core_device" "my_device" { registry_id = "<registry_ID>" name = "<device_name>" description = "test device for terraform provider documentation" ... passwords = [ "<password>", ] ... }
For more information about the
yandex_iot_core_device
resource parameters in Terraform, see the relevant provider documentation . -
In the command line, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can verify device passwords in the management console
or using the following CLI command:yc iot device password list --device-name <device_name>
To delete a device password, use the deletePassword REST API method for the Device resource or the DeviceService/DeletePassword gRPC API call.