VK Cloud logo
Updated at March 19, 2024   02:14 PM

Working with tokensBeta

To interact with Cloud Spark clusters, the Cloud ML Platform Python library is used. When working with the library, most actions require authorization using a token.

The library supports two types of tokens:

  • Access tokens (refresh tokens). They are used to interact with Spark clusters.
  • Registration tokens (register tokens). They are used to create access tokens using the library (without using your personal account).

Getting a list of access tokens

  1. Go to your VK Cloud personal account.
  2. Select the project where the tokens are located.
  3. Go to ML Platform → Tokens.

A list of access tokens will be displayed.

Creating an access token

  1. Go to your VK Cloud personal account.

  2. Select the project in which you want to create a token.

  3. Go to ML Platform → Tokens.

  4. Click the Create access token button.

  5. In the window that opens, specify the token parameters:

    • Name: can be anything.

    • Role: one of the roles of the token.

      • User. This role gives the right to perform operations that require authorization when working with the Cloud ML Platform library (for example, send a task to the Spark cluster).
      • Administrator. This role gives the same rights as the User role and also provides additional rights to work with tokens.
  6. Click the Create button.

  7. In the window that opens, copy the token value and save it on your device.

  8. Click the Ready button.

Creating a registration token

  1. Prepare the environment for working with Python in any convenient way, if you have not done it already:

    Create a JupyterHub instance on the VK Cloud platform. It already contains configured Python 3.x and pip, which you can work with from JupyterHub notebook.

  2. Install the Cloud ML Platform library for Python if you have not done it already.

    1. Connect to your JupyterHub instance.

    2. In the JupyterHub notebook, create and execute a cell with the following content:

      %pip install https://mlplatform.hb.ru-msk.vkcs.cloud/mlplatform_client.tar.gz

    The current version of the library is available at the link provided.

  3. Create an access token with the Administrator role if you don't have one yet.

  4. Create a registration token by executing a Python script:

    from mlplatform_client import MLPlatformfrom mlplatform_client.serializers.auth import MLPTokenType ADMIN_REFRESH_TOKEN = "<the value of the access token with the Administrator role>" mlp = MLPlatform(ADMIN_REFRESH_TOKEN)register_token = mlp.create_register_token(    client_name="<access token name>",    access_ttl="<lifetime of the registration token>",    refresh_ttl="<access token lifetime>",    token_type=<the role of the access token>)print(register_token)

    Here:

    • client_name: the name of the access token that will be created using this registration token.

    • access_ttl: the lifetime of the registration token (in the format 2h45m30s). The expired registration token cannot be used to create an access token.

    • refresh_ttl: the lifetime of the access token (in the 2h format). If you do not specify this parameter, the access token will be valid indefinitely.

    • token_type: the role of the access token:

      • The value MLPTokenType.USER corresponds to the role User. This role gives the right to perform operations that require authorization when working with the Cloud ML Platform library (for example, to send a task to the Spark cluster).
      • The value of MLPTokenType.ADMIN corresponds to the role of Administrator. This role gives the same rights as the User role and also provides additional rights to work with tokens.

    After executing this script, the value of the created registration token will be output.

  5. Provide this registration token to another user so that he or she can use this token to create an access token with the specified parameters.

Deleting an access token

  1. Go to your VK Cloud personal account.
  2. Select the project where the desired token is located.
  3. Go to ML Platform → Tokens.
  4. Expand the menu of the desired token and select Delete.
  5. Click the Confirm button.