From cf33d091cd1798ff06317d9c50f9e82ba09a0df7 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Wed, 2 Oct 2024 15:18:48 -0400 Subject: [PATCH] Minor key updates --- go.mod | 6 +++--- go.sum | 12 +++++------ hyperdrive-cli/client/auth.go | 20 +------------------ hyperdrive-cli/client/client.go | 8 +++++--- .../modules/constellation/cs_daemon.tmpl | 4 ++-- .../modules/stakewise/sw_daemon.tmpl | 4 ++-- internal/tests/cfg_test.go | 11 ++++++---- 7 files changed, 26 insertions(+), 39 deletions(-) diff --git a/go.mod b/go.mod index 9ca82de..0a3a9e7 100644 --- a/go.mod +++ b/go.mod @@ -15,9 +15,9 @@ require ( github.com/goccy/go-json v0.10.3 github.com/mholt/archiver/v4 v4.0.0-alpha.8 github.com/mitchellh/go-homedir v1.1.0 - github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002073727-0d956e28557d - github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002073218-07357eb81ca4 - github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002074720-5fa69604ea9f + github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002183331-b9b94bf2218f + github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002190845-1a9ed88f4627 + github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002183435-c4cb9515df86 github.com/nodeset-org/osha v0.3.1-0.20240927160812-d66358d4e091 github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/rivo/tview v0.0.0-20230208211350-7dfff1ce7854 // DO NOT UPGRADE diff --git a/go.sum b/go.sum index fc1142d..5ef0016 100644 --- a/go.sum +++ b/go.sum @@ -444,12 +444,12 @@ github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOEL github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002073727-0d956e28557d h1:dCoRAdCOw7Ow/mnPupF+/klClG097TFfF9913AQG+dw= -github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002073727-0d956e28557d/go.mod h1:0LcBrdrHkkAs3m7bFRIg9Fb5HbBJazJE3lvgy+QbST8= -github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002073218-07357eb81ca4 h1:sBdg5zBUwDtjNYfmx8PxvvFWiSKsQSiBKN9ZsJZWib0= -github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002073218-07357eb81ca4/go.mod h1:VXYiN0ZrXbeNALJLa0sin4AzlSrFuGH8gW1YSywoVoI= -github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002074720-5fa69604ea9f h1:OCJ9aniDFD5vR1Y6kcZZo4HzORNbISfjPF5QslyRY3Y= -github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002074720-5fa69604ea9f/go.mod h1:hGpWV7iJwpJg/8pbQnv3t6oGWoMZBHyeY24btNDP324= +github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002183331-b9b94bf2218f h1:uy8P5wxv5lBEPurP3OlaCKMaq+0bw7j/lYtAnD7TM7c= +github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002183331-b9b94bf2218f/go.mod h1:Qf6r3WnPqaxgZI9L/9SYQZnjEIv9+OLEF0VnjzElziU= +github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002190845-1a9ed88f4627 h1:7Gj61zC4/+ZHd94QHq7pz/82PKto+5C3LPeZolEeIN0= +github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002190845-1a9ed88f4627/go.mod h1:VXYiN0ZrXbeNALJLa0sin4AzlSrFuGH8gW1YSywoVoI= +github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002183435-c4cb9515df86 h1:Sf/NTZN3u23+fgdMVR40Ewf8lTFEUfxBonAQ05670W4= +github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002183435-c4cb9515df86/go.mod h1:ZeMwsXDZWB3U2N8H2QqtMUBO/JbCYS2VCSyptxHZeNM= github.com/nodeset-org/nodeset-client-go v1.0.1-0.20240927160821-e348e05e2363 h1:iivCknAFZlpxPwbIDjPc9E2bnj55c2STrXT9MvuMzQM= github.com/nodeset-org/nodeset-client-go v1.0.1-0.20240927160821-e348e05e2363/go.mod h1:slpwejkJ/vYU9SKA3SYw4hIPJLzDUeQxcx+Cm04kkIA= github.com/nodeset-org/osha v0.3.1-0.20240927160812-d66358d4e091 h1:oAs4/Yx4jnsNdWh3vTKum1sXC8VCvsY1H2VFSRRkgjc= diff --git a/hyperdrive-cli/client/auth.go b/hyperdrive-cli/client/auth.go index 9e257d6..a88822c 100644 --- a/hyperdrive-cli/client/auth.go +++ b/hyperdrive-cli/client/auth.go @@ -23,28 +23,15 @@ var ( // Create the metrics and modules folders, and deploy the config templates for Prometheus and Grafana func (c *HyperdriveClient) GenerateDaemonAuthKeys(config *GlobalConfig) error { - // Make sure the secrets path exists - secretsDirPath := filepath.Join(c.Context.UserDirPath, hdconfig.SecretsDir) - modulesDirPath := filepath.Join(secretsDirPath, hdconfig.ModulesName) - err := os.MkdirAll(modulesDirPath, authDirMode) - if err != nil { - return fmt.Errorf("error creating secrets and modules directories [%s]: %w", modulesDirPath, err) - } - // Create the API key for the Hyperdrive daemon hdApiKeyPath := filepath.Join(c.Context.UserDirPath, hdApiKeyRelPath) - err = auth.GenerateAuthKeyIfNotPresent(hdApiKeyPath, auth.DefaultKeyLength) + err := auth.GenerateAuthKeyIfNotPresent(hdApiKeyPath, auth.DefaultKeyLength) if err != nil { return fmt.Errorf("error generating Hyperdrive daemon API key: %w", err) } // Create the API key for the StakeWise module if enabled if config.StakeWise.Enabled.Value { - swDirPath := filepath.Join(modulesDirPath, swconfig.ModuleName) - err := os.MkdirAll(swDirPath, authDirMode) - if err != nil { - return fmt.Errorf("error creating StakeWise API key module directory [%s]: %w", swDirPath, err) - } swApiKeyPath := filepath.Join(c.Context.UserDirPath, swApiKeyRelPath) err = auth.GenerateAuthKeyIfNotPresent(swApiKeyPath, auth.DefaultKeyLength) if err != nil { @@ -54,11 +41,6 @@ func (c *HyperdriveClient) GenerateDaemonAuthKeys(config *GlobalConfig) error { // Create the API key for the Constellation module if enabled if config.Constellation.Enabled.Value { - csDirPath := filepath.Join(modulesDirPath, csconfig.ModuleName) - err := os.MkdirAll(csDirPath, authDirMode) - if err != nil { - return fmt.Errorf("error creating Constellation API key module directory [%s]: %w", csDirPath, err) - } csApiKeyPath := filepath.Join(c.Context.UserDirPath, csApiKeyRelPath) err = auth.GenerateAuthKeyIfNotPresent(csApiKeyPath, auth.DefaultKeyLength) if err != nil { diff --git a/hyperdrive-cli/client/client.go b/hyperdrive-cli/client/client.go index b152e3c..ee364e6 100644 --- a/hyperdrive-cli/client/client.go +++ b/hyperdrive-cli/client/client.go @@ -29,6 +29,8 @@ const ( BackupSettingsFile string = "user-settings-backup.yml" terminalLogColor color.Attribute = color.FgHiYellow + + cliIssuer string = "hd-cli" ) // Hyperdrive client @@ -104,7 +106,7 @@ func NewHyperdriveClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext) (*Hy // Create the auth manager authPath := filepath.Join(hdCtx.UserDirPath, hdApiKeyRelPath) - authMgr := auth.NewAuthorizationManager(authPath) + authMgr := auth.NewAuthorizationManager(authPath, cliIssuer, auth.DefaultRequestLifespan) // Create the API client hdClient.Api = client.NewApiClient(url, logger, tracer, authMgr) @@ -158,7 +160,7 @@ func NewStakewiseClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext, hdCli // Create the auth manager authPath := filepath.Join(hdCtx.UserDirPath, swApiKeyRelPath) - authMgr := auth.NewAuthorizationManager(authPath) + authMgr := auth.NewAuthorizationManager(authPath, cliIssuer, auth.DefaultRequestLifespan) // Create the API client swClient.Api = swclient.NewApiClient(url, logger, tracer, authMgr) @@ -206,7 +208,7 @@ func NewConstellationClientFromCtx(c *cli.Context, hdClient *HyperdriveClient) ( // Create the auth manager authPath := filepath.Join(hdCtx.UserDirPath, csApiKeyRelPath) - authMgr := auth.NewAuthorizationManager(authPath) + authMgr := auth.NewAuthorizationManager(authPath, cliIssuer, auth.DefaultRequestLifespan) // Create the API client csClient.Api = csclient.NewApiClient(url, logger, tracer, authMgr) diff --git a/install/deploy/templates/modules/constellation/cs_daemon.tmpl b/install/deploy/templates/modules/constellation/cs_daemon.tmpl index febbe69..7f16f79 100644 --- a/install/deploy/templates/modules/constellation/cs_daemon.tmpl +++ b/install/deploy/templates/modules/constellation/cs_daemon.tmpl @@ -31,9 +31,9 @@ services: - --port - "{{.Constellation.ApiPort}}" - --api-key - - "{{.Hyperdrive.GetUserDirectory}}//{{.ConstellationApiKeyPath}}" + - "{{.Hyperdrive.GetUserDirectory}}/{{.ConstellationApiKeyPath}}" - --hd-api-key - - "{{.Hyperdrive.GetUserDirectory}}//{{.HyperdriveApiKeyPath}}" + - "{{.Hyperdrive.GetUserDirectory}}/{{.HyperdriveApiKeyPath}}" networks: - net {{- range $network := .Hyperdrive.GetAdditionalDockerNetworks}} diff --git a/install/deploy/templates/modules/stakewise/sw_daemon.tmpl b/install/deploy/templates/modules/stakewise/sw_daemon.tmpl index 21ca21b..54d48ae 100644 --- a/install/deploy/templates/modules/stakewise/sw_daemon.tmpl +++ b/install/deploy/templates/modules/stakewise/sw_daemon.tmpl @@ -31,9 +31,9 @@ services: - --port - "{{.StakeWise.ApiPort}}" - --api-key - - "{{.Hyperdrive.GetUserDirectory}}//{{.StakeWiseApiKeyPath}}" + - "{{.Hyperdrive.GetUserDirectory}}/{{.StakeWiseApiKeyPath}}" - --hd-api-key - - "{{.Hyperdrive.GetUserDirectory}}//{{.HyperdriveApiKeyPath}}" + - "{{.Hyperdrive.GetUserDirectory}}/{{.HyperdriveApiKeyPath}}" networks: - net {{- range $network := .Hyperdrive.GetAdditionalDockerNetworks}} diff --git a/internal/tests/cfg_test.go b/internal/tests/cfg_test.go index cf25e1b..096b32d 100644 --- a/internal/tests/cfg_test.go +++ b/internal/tests/cfg_test.go @@ -90,9 +90,9 @@ func TestNewConfig_Holesky(t *testing.T) { hdSp, err := hdcommon.NewHyperdriveServiceProvider(hdCtx.UserDirPath, hdCtx.NetworksDir) require.NoError(t, err) hdWg := &sync.WaitGroup{} - authMgr := auth.NewAuthorizationManager("") - authMgr.SetKey([]byte(hdTestApiKey)) - hdServer, err := hdserver.NewServerManager(hdSp, "localhost", 0, hdWg, authMgr) + serverAuthMgr := auth.NewAuthorizationManager("", "server", auth.DefaultRequestLifespan) + serverAuthMgr.SetKey([]byte(hdTestApiKey)) + hdServer, err := hdserver.NewServerManager(hdSp, "localhost", 0, hdWg, serverAuthMgr) require.NoError(t, err) hdServerPort := hdServer.GetPort() defer hdServer.Stop() @@ -105,9 +105,12 @@ func TestNewConfig_Holesky(t *testing.T) { require.NoError(t, err) swSettings, err := hdclient.LoadStakeWiseSettings(hdCtx.NetworksDir) require.NoError(t, err) + + clientAuthMgr := auth.NewAuthorizationManager("", "client", auth.DefaultRequestLifespan) + clientAuthMgr.SetKey([]byte(hdTestApiKey)) modSp, err := modservices.NewModuleServiceProvider(hdApiUrl, swModDir, swconfig.ModuleName, swconfig.ClientLogName, func(hdCfg *hdconfig.HyperdriveConfig) (*swconfig.StakeWiseConfig, error) { return swconfig.NewStakeWiseConfig(hdCfg, swSettings) - }, authMgr) + }, clientAuthMgr) require.NoError(t, err) swSp, err := swcommon.NewStakeWiseServiceProvider(modSp, swSettings) require.NoError(t, err)