Resolving the "Unauthenticated" error
Written by
Updated at November 27, 2023
Issue description
When trying to access Yandex Managed Service for YDB from a local machine, you see the Unauthenticated
error.
Solution
You can authenticate using an IAM-token or a service account token. You can view code examples here
Note
Example of working with YDB Python SDK
:
- Create a folder, for example,
ydb
and navigate to it via PowerShell/Bash:cd ydb
. Run subsequent commands in the terminal from this folder. - Create an authorized key for the service account:
yc iam key create --service-account-id <id_SA> --output token.json
. Thetoken.json
key will be created in theydb
folder. - Next, check that the key is operable:
ydb --endpoint grpcs://ydb.serverless.yandexcloud.net:2135 --database /ru-central1/b1gb4.../etn0fu... --sa-key-file token.json discovery whoami
. The response should be:User SID: ajei6s...@as
: this means that the connection has been established. - Clone the example from GitHub:
git clone https://github.com/ydb-platform/ydb-python-sdk.git
. It will be saved in the currentydb
folder for convenience. - Install the library:
python -m pip install iso8601
. - Add the location of this file to the
SA_KEY_FILE
environment variable:- Linux:
export SA_KEY_FILE=~/ydb/token.json
- Windows:
$SA_KEY_FILE="C:\Users\<user>\ydb\token.json"
- Linux:
- Run the script:
python ydb-python-sdk/examples/basic_example_v1/ -e grpcs://ydb.serverless.yandexcloud.net:2135 -d /ru-central1/b1gb4.../etn0fu...
.