-
Notifications
You must be signed in to change notification settings - Fork 21
Implement Secret storage backend as gRPC server #644
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
10 commits
Select commit
Hold shift + click to select a range
795dd28
Implement Secret storage backend as gRPC server
pkosiec 3864019
Move the Go gRPC client example to `pkg/hub/api/grpc` and fix lint is…
pkosiec 6474795
Update teller and example
pkosiec 90d53dc
Include secret storage backend in build
pkosiec 591b543
Add additional value printing to example
pkosiec bc2b57b
Fix tests
pkosiec fcdccf3
Increase lint timeout, update Teller
pkosiec 0f3c7b2
Install missing binaries for gRPC generation
pkosiec 397b49f
Introduce improvements requested in review
pkosiec 20c0480
Prevent caching test result for gRPC client
pkosiec 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Secret Storage Backend | ||
|
|
||
| ## Overview | ||
|
|
||
| Secret Storage Backend is a service which handles multiple secret storages for TypeInstances. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Go](https://golang.org) | ||
| - (Optional - if AWS Secrets Manager provider should be used) an AWS account with **AdministratorAccess** permissions on it | ||
|
|
||
| ## Usage | ||
|
|
||
| ### AWS Secrets Manager provider | ||
|
|
||
| By default, the Secret Storage Backend has the `aws_secretsmanager` provider enabled. | ||
|
|
||
| 1. Create AWS security credentials with `SecretsManagerReadWrite` policy. | ||
| 2. Export environment variables: | ||
|
|
||
| ```bash | ||
| export AWS_ACCESS_KEY_ID="{accessKey}" | ||
| export AWS_SECRET_ACCESS_KEY="{secretKey}" | ||
| ``` | ||
| 3. Run the server: | ||
|
|
||
| ```bash | ||
| APP_LOGGER_DEV_MODE=true go run ./cmd/secret-storage-backend/main.go | ||
| ``` | ||
|
|
||
| The server listens to gRPC calls according to the [Storage Backend Protocol Buffers schema](../../pkg/hub/api/grpc/storage_backend.proto). | ||
| To perform such calls, you can use e.g. [Insomnia](https://insomnia.rest/) tool. | ||
|
|
||
| ### Dotenv provider | ||
|
|
||
| To run the server with `dotenv` provider enabled, which stores data in files, execute: | ||
|
|
||
| ```bash | ||
| APP_SUPPORTED_PROVIDERS=dotenv,aws_secretsmanager APP_LOGGER_DEV_MODE=true go run ./cmd/secret-storage-backend/main.go | ||
| ``` | ||
|
|
||
| > **NOTE:** You can enable multiple providers, separating them by comma, such as: `APP_SUPPORTED_PROVIDERS=aws_secretsmanager,dotenv`. | ||
|
|
||
| ## Configuration | ||
|
|
||
| | Name | Required | Default | Description | | ||
|
pkosiec marked this conversation as resolved.
|
||
| |-------------------------|----------|----------------------|-------------------------------------------------------------------------------------------------------------------------------| | ||
| | APP_GRPC_ADDR | no | `:50051` | TCP address the gRPC server binds to. | | ||
| | APP_HEALTHZ_ADDR | no | `:8082` | TCP address the health probes endpoint binds to. | | ||
| | APP_SUPPORTED_PROVIDERS | no | `aws_secretsmanager` | Supported secret providers separated by `,`. A given provider must be passed in additional parameters of gRPC request inputs. | | ||
| | APP_LOGGER_DEV_MODE | no | `false` | Enable development mode logging. | | ||
|
|
||
| To configure providers, use environmental variables described in the [Providers](https://github.com/SpectralOps/teller#providers) paragraph for Teller's Readme. | ||
|
|
||
| ## Development | ||
|
|
||
| To read more about development, see the [Development guide](https://capact.io/community/development/development-guide). | ||
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,104 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "log" | ||
| "net" | ||
|
|
||
| "capact.io/capact/internal/healthz" | ||
| "capact.io/capact/internal/logger" | ||
| secret_storage_backend "capact.io/capact/internal/secret-storage-backend" | ||
| "capact.io/capact/pkg/hub/api/grpc/storage_backend" | ||
| "github.com/pkg/errors" | ||
| tellerpkg "github.com/spectralops/teller/pkg" | ||
| tellercore "github.com/spectralops/teller/pkg/core" | ||
| "github.com/vrischmann/envconfig" | ||
| "go.uber.org/zap" | ||
| "golang.org/x/sync/errgroup" | ||
| "google.golang.org/grpc" | ||
| "sigs.k8s.io/controller-runtime/pkg/manager/signals" | ||
| ) | ||
|
|
||
| // Config holds application related configuration. | ||
| type Config struct { | ||
| // GRPCAddr is the TCP address the gRPC server binds to. | ||
| GRPCAddr string `envconfig:"default=:50051"` | ||
|
|
||
| // HealthzAddr is the TCP address the health probes endpoint binds to. | ||
| HealthzAddr string `envconfig:"default=:8082"` | ||
|
|
||
| // SupportedProviders holds enabled secret providers separated by comma. | ||
| SupportedProviders []string `envconfig:"default=aws_secretsmanager"` | ||
|
pkosiec marked this conversation as resolved.
|
||
|
|
||
| Logger logger.Config | ||
| } | ||
|
|
||
| const appName = "secret-storage-backend" | ||
|
|
||
| func main() { | ||
| var cfg Config | ||
| err := envconfig.InitWithPrefix(&cfg, "APP") | ||
| exitOnError(err, "while loading configuration") | ||
|
|
||
| ctx := signals.SetupSignalHandler() | ||
|
|
||
| // setup logger | ||
| unnamedLogger, err := logger.New(cfg.Logger) | ||
| exitOnError(err, "while creating zap logger") | ||
|
|
||
| logger := unnamedLogger.Named(appName) | ||
|
|
||
| // setup servers | ||
| parallelServers := new(errgroup.Group) | ||
|
|
||
| healthzServer := healthz.NewHTTPServer(logger, cfg.HealthzAddr, appName) | ||
| parallelServers.Go(func() error { return healthzServer.Start(ctx) }) | ||
|
|
||
| providers, err := loadProviders(cfg.SupportedProviders) | ||
| exitOnError(err, "while loading providers") | ||
|
|
||
| handler := secret_storage_backend.NewHandler(logger, providers) | ||
| exitOnError(err, "while creating new handler") | ||
|
|
||
| listenCfg := net.ListenConfig{} | ||
| listener, err := listenCfg.Listen(ctx, "tcp", cfg.GRPCAddr) | ||
| exitOnError(err, "while listening") | ||
|
|
||
| srv := grpc.NewServer() | ||
| storage_backend.RegisterStorageBackendServer(srv, handler) | ||
|
|
||
| go func() { | ||
| <-ctx.Done() | ||
| logger.Info("Stopping server gracefully") | ||
| srv.GracefulStop() | ||
| }() | ||
|
|
||
| parallelServers.Go(func() error { | ||
| logger.Info("Starting TCP server", zap.String("addr", cfg.GRPCAddr)) | ||
| return srv.Serve(listener) | ||
| }) | ||
|
|
||
| err = parallelServers.Wait() | ||
| exitOnError(err, "while waiting for servers to finish gracefully") | ||
| } | ||
|
|
||
| func exitOnError(err error, context string) { | ||
| if err != nil { | ||
| log.Fatalf("%s: %v", context, err) | ||
| } | ||
| } | ||
|
|
||
| func loadProviders(providerNames []string) (map[string]tellercore.Provider, error) { | ||
| builtInProviders := tellerpkg.BuiltinProviders{} | ||
| providersMap := map[string]tellercore.Provider{} | ||
|
|
||
| for _, providerName := range providerNames { | ||
| provider, err := builtInProviders.GetProvider(providerName) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "while loading provider %q", provider) | ||
| } | ||
|
|
||
| providersMap[providerName] = provider | ||
| } | ||
|
|
||
| return providersMap, nil | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.