Skip to content
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

YDB: support authorization via service account #221

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions app/config/server.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/config/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ message TYdbConfig {
// MODE_TABLE_SERVICE_STDLIB_SCAN_QUERIES is the default mode.
Mode mode = 4;

// Path to JSON file with static SA credentials.
// If this file is provided, the YDB connector will use
// this credentials to access the database.
string service_account_key_file_credentials = 5;

TExponentialBackoffConfig exponential_backoff = 10;
}

Expand Down
7 changes: 6 additions & 1 deletion app/server/datasource/rdbms/ydb/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
ydb_sdk_config "github.com/ydb-platform/ydb-go-sdk/v3/config"
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
yc "github.com/ydb-platform/ydb-go-yc"
"go.uber.org/zap"
"google.golang.org/grpc"

Expand Down Expand Up @@ -39,7 +40,11 @@

var cred ydb_sdk.Option

if dsi.Credentials.GetToken() != nil {
if c.cfg.ServiceAccountKeyFileCredentials != "" {
logger.Debug("YDB Connector will use service account key file credentials")

cred = yc.WithServiceAccountKeyFileCredentials(c.cfg.ServiceAccountKeyFileCredentials)

Check warning on line 46 in app/server/datasource/rdbms/ydb/connection_manager.go

View check run for this annotation

Codecov / codecov/patch

app/server/datasource/rdbms/ydb/connection_manager.go#L44-L46

Added lines #L44 - L46 were not covered by tests
} else if dsi.Credentials.GetToken() != nil {
cred = ydb_sdk.WithAccessTokenCredentials(dsi.Credentials.GetToken().Value)
} else if dsi.Credentials.GetBasic() != nil {
cred = ydb_sdk.WithStaticCredentials(dsi.Credentials.GetBasic().Username, dsi.Credentials.GetBasic().Password)
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/wI2L/jsondiff v0.4.0
github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77
github.com/ydb-platform/ydb-go-sdk/v3 v3.92.5
github.com/ydb-platform/ydb-go-yc v0.11.0
go.uber.org/atomic v1.11.0
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
Expand Down Expand Up @@ -89,6 +90,8 @@ require (
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 // indirect
github.com/siddontang/go-log v0.0.0-20190221022429-1e957dd83bed // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/yandex-cloud/go-genproto v0.0.0-20240425114406-68c9b49389a1 // indirect
github.com/ydb-platform/ydb-go-yc-metadata v0.5.3 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
Expand All @@ -100,6 +103,8 @@ require (
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
Loading