-
Notifications
You must be signed in to change notification settings - Fork 742
New methods to provide IAM-tokens when accessing managed YDB from dqrun.
#2386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
ydb/library/yql/providers/generic/actors/yql_generic_token_provider.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #include "yql_generic_token_provider.h" | ||
|
|
||
| #include <ydb/library/yql/providers/common/structured_token/yql_token_builder.h> | ||
|
|
||
| namespace NYql::NDq { | ||
| TGenericTokenProvider::TGenericTokenProvider( | ||
| const NYql::Generic::TSource& source, const ISecuredServiceAccountCredentialsFactory::TPtr& credentialsFactory) | ||
| : Source_(source) | ||
| , StaticIAMToken_(source.GetToken()) | ||
| , CredentialsProvider_(nullptr) | ||
| { | ||
| // 1. User has provided IAM-token itself. | ||
| // This token will be used during the whole lifetime of a read actor. | ||
| if (!StaticIAMToken_.empty()) { | ||
| return; | ||
| } | ||
|
|
||
| // 2. User has provided service account creds. | ||
| // We create token accessor client that will renew token accessor by demand. | ||
| if (source.GetServiceAccountId() && source.GetServiceAccountIdSignature()) { | ||
| Y_ENSURE(credentialsFactory, "CredentialsFactory is not initialized"); | ||
|
|
||
| auto structuredTokenJSON = | ||
| TStructuredTokenBuilder() | ||
| .SetServiceAccountIdAuth(source.GetServiceAccountId(), source.GetServiceAccountIdSignature()) | ||
| .ToJson(); | ||
|
|
||
| // If service account is provided, obtain IAM-token | ||
| Y_ENSURE(structuredTokenJSON, "empty structured token"); | ||
|
|
||
| auto credentialsProviderFactory = | ||
| CreateCredentialsProviderFactoryForStructuredToken(credentialsFactory, structuredTokenJSON, false); | ||
| CredentialsProvider_ = credentialsProviderFactory->CreateProvider(); | ||
| } | ||
|
|
||
| // 3. If we reached this point, it means that user doesn't need token auth. | ||
| } | ||
|
|
||
| void TGenericTokenProvider::MaybeFillToken(NConnector::NApi::TDataSourceInstance& dsi) const { | ||
| // 1. Don't need tokens if basic auth is set | ||
| if (dsi.credentials().has_basic()) { | ||
| return; | ||
| } | ||
|
|
||
| *dsi.mutable_credentials()->mutable_token()->mutable_type() = "IAM"; | ||
|
|
||
| // 2. If static IAM-token has been provided, use it | ||
| if (!StaticIAMToken_.empty()) { | ||
| *dsi.mutable_credentials()->mutable_token()->mutable_value() = StaticIAMToken_; | ||
| return; | ||
| } | ||
|
|
||
| // 3. Otherwise use credentials provider to get token | ||
| Y_ENSURE(CredentialsProvider_, "CredentialsProvider is not initialized"); | ||
|
|
||
| auto iamToken = CredentialsProvider_->GetAuthInfo(); | ||
| Y_ENSURE(iamToken, "CredentialsProvider returned empty IAM token"); | ||
|
|
||
| *dsi.mutable_credentials()->mutable_token()->mutable_value() = std::move(iamToken); | ||
| } | ||
|
|
||
| TGenericTokenProvider::TPtr | ||
| CreateGenericTokenProvider(const NYql::Generic::TSource& source, | ||
| const ISecuredServiceAccountCredentialsFactory::TPtr& credentialsFactory) { | ||
| return std::make_unique<TGenericTokenProvider>(source, credentialsFactory); | ||
| } | ||
| } //namespace NYql::NDq |
30 changes: 30 additions & 0 deletions
30
ydb/library/yql/providers/generic/actors/yql_generic_token_provider.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <ydb/library/yql/providers/common/token_accessor/client/factory.h> | ||
| #include <ydb/library/yql/providers/generic/connector/api/service/protos/connector.pb.h> | ||
| #include <ydb/library/yql/providers/generic/proto/source.pb.h> | ||
|
|
||
| namespace NYql::NDq { | ||
| // When accessing external data sources using authentication via tokens, | ||
| // there are two options: | ||
| // 1. Use static IAM-token provided by user (especially useful during debugging); | ||
| // 2. Use service account credentials in order to get (and refresh) IAM-token by demand. | ||
| class TGenericTokenProvider { | ||
| public: | ||
| using TPtr = std::unique_ptr<TGenericTokenProvider>; | ||
|
|
||
| TGenericTokenProvider(const NYql::Generic::TSource& source, | ||
| const ISecuredServiceAccountCredentialsFactory::TPtr& credentialsFactory); | ||
|
|
||
| void MaybeFillToken(NConnector::NApi::TDataSourceInstance& dsi) const; | ||
|
|
||
| private: | ||
| NYql::Generic::TSource Source_; | ||
| TString StaticIAMToken_; | ||
| NYdb::TCredentialsProviderPtr CredentialsProvider_; | ||
| }; | ||
|
|
||
| TGenericTokenProvider::TPtr | ||
| CreateGenericTokenProvider(const NYql::Generic::TSource& source, | ||
| const ISecuredServiceAccountCredentialsFactory::TPtr& credentialsFactory); | ||
| } //namespace NYql::NDq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что с обратной совместимостью? Из any можно будет достаточно и старый и новый протобуф?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не уверен, что однозначно понял вопрос, но 100% ответа у меня в любом случае нет. Поэтому вернул название неймспейса к тому виду, который был у нас всегда вплоть до предыдущего PR, вмёрженного в пятницу.