-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,830 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
cmd/ydbcp/ydbcp | ||
plugins/auth_nebius/auth_nebius.so |
This file contains 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 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 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,39 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"plugin" | ||
|
||
"ydbcp/internal/config" | ||
"ydbcp/internal/util/xlog" | ||
"ydbcp/pkg/plugins/auth" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
func NewAuthProvider(ctx context.Context, cfg config.AuthConfig) (auth.AuthProvider, error) { | ||
xlog.Info(ctx, "Loading auth provider plugin", zap.String("path", cfg.PluginPath)) | ||
|
||
plug, err := plugin.Open(cfg.PluginPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("can't load auth provider plugin, path %s: %w", cfg.PluginPath, err) | ||
} | ||
symbol, err := plug.Lookup("AuthProvider") | ||
if err != nil { | ||
return nil, fmt.Errorf("can't lookup AuthProvider symbol, plugin path %s: %w", cfg.PluginPath, err) | ||
} | ||
var instance auth.AuthProvider | ||
instance, ok := symbol.(auth.AuthProvider) | ||
if !ok { | ||
return nil, fmt.Errorf("can't cast AuthProvider symbol, plugin path %s", cfg.PluginPath) | ||
} | ||
pluginConfig, err := cfg.ConfigurationString() | ||
if err != nil { | ||
return nil, fmt.Errorf("can't get auth provider configuration: %w", err) | ||
} | ||
if err = instance.Init(ctx, pluginConfig); err != nil { | ||
return nil, fmt.Errorf("can't initialize auth provider plugin: %w", err) | ||
} | ||
return instance, nil | ||
} |
This file contains 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,78 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"ydbcp/internal/util/xlog" | ||
"ydbcp/pkg/plugins/auth" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
type authProviderDummy struct { | ||
} | ||
|
||
const ( | ||
anonymousSubject = "anonymous" | ||
) | ||
|
||
func (p *authProviderDummy) Init(ctx context.Context, config string) error { | ||
xlog.Info(ctx, "AuthProviderDummy init", zap.String("config", config)) | ||
return nil | ||
} | ||
|
||
func (p *authProviderDummy) Finish(ctx context.Context) error { | ||
xlog.Info(ctx, "AuthProviderDummy finish") | ||
return nil | ||
} | ||
|
||
func (p *authProviderDummy) Authenticate(ctx context.Context, token string) (string, auth.AuthCode, error) { | ||
xlog.Debug( | ||
ctx, | ||
"AuthProviderDummy Authenticate", | ||
zap.String("token", auth.MaskToken(token)), | ||
) | ||
code := auth.AuthCodeSuccess | ||
xlog.Debug(ctx, "AuthProviderDummy authenticate result", | ||
zap.String("token", auth.MaskToken(token)), | ||
zap.String("code", code.String()), | ||
zap.String("subject", anonymousSubject), | ||
) | ||
return anonymousSubject, code, nil | ||
} | ||
|
||
func (p *authProviderDummy) Authorize( | ||
ctx context.Context, | ||
token string, | ||
checks []auth.AuthorizeCheck, | ||
) (results []auth.AuthorizeResult, subject string, err error) { | ||
xlog.Info( | ||
ctx, | ||
"AuthProviderDummy Authorize", | ||
zap.String("token", auth.MaskToken(token)), | ||
zap.String("checks", fmt.Sprintf("%v", checks)), | ||
) | ||
if len(checks) == 0 { | ||
xlog.Error(ctx, "AuthProviderDummy AuthorizeCheck list is empty") | ||
return nil, "", errors.New("AuthorizeCheck list is empty") | ||
} | ||
|
||
results = make([]auth.AuthorizeResult, 0, len(checks)) | ||
for range len(checks) { | ||
results = append(results, auth.AuthorizeResult{Code: auth.AuthCodeSuccess}) | ||
} | ||
xlog.Info(ctx, "AuthProviderDummy Authorize result", | ||
zap.String("results", fmt.Sprintf("%v", results)), | ||
zap.String("subject", anonymousSubject), | ||
) | ||
return results, subject, nil | ||
} | ||
|
||
func NewDummyAuthProvider(ctx context.Context) (auth.AuthProvider, error) { | ||
p := &authProviderDummy{} | ||
if err := p.Init(ctx, ""); err != nil { | ||
return nil, err | ||
} | ||
return p, nil | ||
} |
Oops, something went wrong.