rough in secrets grpc listener (#968)

This commit is contained in:
Michael Quigley 2025-06-16 13:08:30 -04:00
parent 7a9cf3b183
commit 632632e0bf
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 67 additions and 6 deletions

View File

@ -1,6 +1,10 @@
package config package config
import ( import (
"os"
"strconv"
"time"
"github.com/michaelquigley/cf" "github.com/michaelquigley/cf"
"github.com/openziti/zrok/controller/agentController" "github.com/openziti/zrok/controller/agentController"
"github.com/openziti/zrok/controller/emailUi" "github.com/openziti/zrok/controller/emailUi"
@ -10,9 +14,6 @@ import (
"github.com/openziti/zrok/controller/store" "github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/controller/zrokEdgeSdk" "github.com/openziti/zrok/controller/zrokEdgeSdk"
"github.com/pkg/errors" "github.com/pkg/errors"
"os"
"strconv"
"time"
) )
const ConfigVersion = 4 const ConfigVersion = 4
@ -30,6 +31,7 @@ type Config struct {
Metrics *metrics.Config Metrics *metrics.Config
Registration *RegistrationConfig Registration *RegistrationConfig
ResetPassword *ResetPasswordConfig ResetPassword *ResetPasswordConfig
Secrets *SecretsConfig
Store *store.Config Store *store.Config
Ziti *zrokEdgeSdk.Config Ziti *zrokEdgeSdk.Config
Tls *TlsConfig Tls *TlsConfig
@ -78,6 +80,12 @@ type ResetPasswordMaintenanceConfig struct {
BatchLimit int BatchLimit int
} }
type SecretsConfig struct {
ZId string
IdentityPath string
ServiceName string
}
type TlsConfig struct { type TlsConfig struct {
CertPath string CertPath string
KeyPath string KeyPath string

View File

@ -2,6 +2,10 @@ package controller
import ( import (
"context" "context"
"log"
"net/http"
_ "net/http/pprof"
"github.com/go-openapi/loads" "github.com/go-openapi/loads"
influxdb2 "github.com/influxdata/influxdb-client-go/v2" influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/jessevdk/go-flags" "github.com/jessevdk/go-flags"
@ -15,9 +19,6 @@ import (
"github.com/openziti/zrok/rest_server_zrok/operations/metadata" "github.com/openziti/zrok/rest_server_zrok/operations/metadata"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"log"
"net/http"
_ "net/http/pprof"
) )
var ( var (
@ -153,6 +154,8 @@ func Run(inCfg *config.Config) error {
} }
} }
go startSecretsListener(cfg)
server := rest_server_zrok.NewServer(api) server := rest_server_zrok.NewServer(api)
defer func() { _ = server.Shutdown() }() defer func() { _ = server.Shutdown() }()
if cfg.Tls != nil { if cfg.Tls != nil {

50
controller/secrets.go Normal file
View File

@ -0,0 +1,50 @@
package controller
import (
"context"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/controller/secretsGrpc"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
func startSecretsListener(cfg *config.Config) {
if cfg != nil && cfg.Secrets != nil {
zcfg, err := ziti.NewConfigFromFile(cfg.Secrets.IdentityPath)
if err != nil {
logrus.Errorf("error loading secrets listener identity '%v': %v", cfg.Secrets.IdentityPath, err)
return
}
zctx, err := ziti.NewContext(zcfg)
if err != nil {
logrus.Errorf("error creating ziti context: %v", err)
return
}
l, err := zctx.Listen(cfg.Secrets.ServiceName)
if err != nil {
logrus.Errorf("error listening on '%v': %v", cfg.Secrets.ServiceName, err)
return
}
srv := grpc.NewServer()
secretsGrpc.RegisterSecretsServer(srv, &secretsGrpcImpl{})
if err := srv.Serve(l); err != nil {
logrus.Errorf("error serving '%v': %v", cfg.Secrets.ServiceName, err)
return
}
} else {
logrus.Warnf("secrets listener disabled")
}
}
type secretsGrpcImpl struct {
secretsGrpc.UnimplementedSecretsServer
}
func (i *secretsGrpcImpl) FetchSecrets(_ context.Context, req *secretsGrpc.SecretsRequest) (*secretsGrpc.SecretsResponse, error) {
logrus.Infof("request for secrets for '%v'", req.ShareToken)
return nil, nil
}