private/testplanet: add uplink config to use different path cipher

From time to time it would be handy to test uplink operations
without encrypting paths.

Change-Id: I00c64fafa133cb711fcdcfe915c3bfbe5eb75d81
This commit is contained in:
Michal Niewrzal 2023-02-17 17:06:24 +01:00
parent a1f46fe721
commit 3abe7ac0da
4 changed files with 65 additions and 37 deletions

View File

@ -23,6 +23,7 @@ type Reconfigure struct {
SatelliteDB func(log *zap.Logger, index int, db satellite.DB) (satellite.DB, error) SatelliteDB func(log *zap.Logger, index int, db satellite.DB) (satellite.DB, error)
SatelliteMetabaseDB func(log *zap.Logger, index int, db *metabase.DB) (*metabase.DB, error) SatelliteMetabaseDB func(log *zap.Logger, index int, db *metabase.DB) (*metabase.DB, error)
Satellite func(log *zap.Logger, index int, config *satellite.Config) Satellite func(log *zap.Logger, index int, config *satellite.Config)
Uplink func(log *zap.Logger, index int, config *UplinkConfig)
StorageNodeDB func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) StorageNodeDB func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error)
StorageNode func(index int, config *storagenode.Config) StorageNode func(index int, config *storagenode.Config)

View File

@ -12,8 +12,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"storj.io/common/context2" "storj.io/common/context2"
"storj.io/common/grant"
"storj.io/common/storj"
"storj.io/common/testcontext" "storj.io/common/testcontext"
"storj.io/private/dbutil" "storj.io/private/dbutil"
"storj.io/private/dbutil/pgtest" "storj.io/private/dbutil/pgtest"
@ -21,7 +19,6 @@ import (
"storj.io/private/tagsql" "storj.io/private/tagsql"
"storj.io/storj/private/testmonkit" "storj.io/storj/private/testmonkit"
"storj.io/storj/satellite/satellitedb/satellitedbtest" "storj.io/storj/satellite/satellitedb/satellitedbtest"
"storj.io/uplink"
) )
// Run runs testplanet in multiple configurations. // Run runs testplanet in multiple configurations.
@ -70,7 +67,6 @@ func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.C
defer ctx.Check(planet.Shutdown) defer ctx.Check(planet.Shutdown)
planet.Start(ctx) planet.Start(ctx)
provisionUplinks(ctx, t, planet)
var rawDB tagsql.DB var rawDB tagsql.DB
var queriesBefore []string var queriesBefore []string
@ -144,40 +140,9 @@ func Bench(b *testing.B, config Config, bench func(b *testing.B, ctx *testcontex
defer ctx.Check(planet.Shutdown) defer ctx.Check(planet.Shutdown)
planet.Start(ctx) planet.Start(ctx)
provisionUplinks(ctx, b, planet)
bench(b, ctx, planet) bench(b, ctx, planet)
}) })
}) })
} }
} }
func provisionUplinks(ctx context.Context, t testing.TB, planet *Planet) {
for _, planetUplink := range planet.Uplinks {
for _, satellite := range planet.Satellites {
apiKey := planetUplink.APIKey[satellite.ID()]
// create access grant manually to avoid dialing satellite for
// project id and deriving key with argon2.IDKey method
encAccess := grant.NewEncryptionAccessWithDefaultKey(&storj.Key{})
encAccess.SetDefaultPathCipher(storj.EncAESGCM)
grantAccess := grant.Access{
SatelliteAddress: satellite.URL(),
APIKey: apiKey,
EncAccess: encAccess,
}
serializedAccess, err := grantAccess.Serialize()
if err != nil {
t.Fatalf("%+v", err)
}
access, err := uplink.ParseAccess(serializedAccess)
if err != nil {
t.Fatalf("%+v", err)
}
planetUplink.Access[satellite.ID()] = access
}
}
}

View File

@ -15,6 +15,7 @@ import (
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
"storj.io/common/grant"
"storj.io/common/identity" "storj.io/common/identity"
"storj.io/common/macaroon" "storj.io/common/macaroon"
"storj.io/common/peertls/tlsopts" "storj.io/common/peertls/tlsopts"
@ -28,6 +29,11 @@ import (
"storj.io/uplink/private/testuplink" "storj.io/uplink/private/testuplink"
) )
// UplinkConfig testplanet configuration for uplink.
type UplinkConfig struct {
DefaultPathCipher storj.CipherSuite
}
// Uplink is a registered user on all satellites, // Uplink is a registered user on all satellites,
// which contains the necessary accesses and project info. // which contains the necessary accesses and project info.
type Uplink struct { type Uplink struct {
@ -82,10 +88,13 @@ func (planet *Planet) newUplinks(ctx context.Context, prefix string, count int)
var xs []*Uplink var xs []*Uplink
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
name := prefix + strconv.Itoa(i) name := prefix + strconv.Itoa(i)
log := planet.log.Named(name)
var uplink *Uplink var uplink *Uplink
var err error var err error
pprof.Do(ctx, pprof.Labels("peer", name), func(ctx context.Context) { pprof.Do(ctx, pprof.Labels("peer", name), func(ctx context.Context) {
uplink, err = planet.newUplink(ctx, name) uplink, err = planet.newUplink(ctx, i, log, name)
}) })
if err != nil { if err != nil {
return nil, errs.Wrap(err) return nil, errs.Wrap(err)
@ -97,7 +106,7 @@ func (planet *Planet) newUplinks(ctx context.Context, prefix string, count int)
} }
// newUplink creates a new uplink. // newUplink creates a new uplink.
func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, err error) { func (planet *Planet) newUplink(ctx context.Context, index int, log *zap.Logger, name string) (_ *Uplink, err error) {
defer mon.Task()(&ctx)(&err) defer mon.Task()(&ctx)(&err)
identity, err := planet.NewIdentity() identity, err := planet.NewIdentity()
@ -171,6 +180,38 @@ func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, er
RawAPIKey: apiKey, RawAPIKey: apiKey,
}) })
var config UplinkConfig
if planet.config.Reconfigure.Uplink != nil {
planet.config.Reconfigure.Uplink(log, index, &config)
}
// create access grant manually to avoid dialing satellite for
// project id and deriving key with argon2.IDKey method
encAccess := grant.NewEncryptionAccessWithDefaultKey(&storj.Key{})
if config.DefaultPathCipher == storj.EncUnspecified {
encAccess.SetDefaultPathCipher(storj.EncAESGCM)
} else {
encAccess.SetDefaultPathCipher(config.DefaultPathCipher)
}
grantAccess := grant.Access{
SatelliteAddress: satellite.URL(),
APIKey: apiKey,
EncAccess: encAccess,
}
serializedAccess, err := grantAccess.Serialize()
if err != nil {
return nil, errs.Wrap(err)
}
access, err := uplink.ParseAccess(serializedAccess)
if err != nil {
return nil, errs.Wrap(err)
}
planetUplink.Access[satellite.ID()] = access
} }
planet.Uplinks = append(planet.Uplinks, planetUplink) planet.Uplinks = append(planet.Uplinks, planetUplink)

View File

@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"storj.io/common/memory" "storj.io/common/memory"
@ -271,3 +272,23 @@ func TestUplinkOpenProject(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}) })
} }
func TestUplinkDifferentPathCipher(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, UplinkCount: 1,
Reconfigure: testplanet.Reconfigure{
Uplink: func(log *zap.Logger, index int, config *testplanet.UplinkConfig) {
config.DefaultPathCipher = storj.EncNull
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", "object-name", []byte("data"))
require.NoError(t, err)
objects, err := planet.Satellites[0].Metabase.DB.TestingAllObjects(ctx)
require.NoError(t, err)
require.Len(t, objects, 1)
require.EqualValues(t, "object-name", objects[0].ObjectKey)
})
}