Skip to content

Commit

Permalink
layer: Use gate private key instead of anonymous
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 3, 2023
1 parent 86392ee commit 8381bbd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api/handler/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func prepareHandlerContext(t *testing.T) *handlerContext {

layerCfg := &layer.Config{
Caches: layer.DefaultCachesConfigs(zap.NewExample()),
AnonKey: layer.AnonymousKey{Key: key},
GateKey: key,
Resolver: testResolver,
TreeService: layer.NewTreeService(),
}
Expand Down
20 changes: 5 additions & 15 deletions api/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type (
layer struct {
neoFS NeoFS
log *zap.Logger
anonKey AnonymousKey
gateKey *keys.PrivateKey
resolver BucketResolver
ncontroller EventListener
cache *Cache
Expand All @@ -56,16 +56,11 @@ type (
Config struct {
ChainAddress string
Caches *CachesConfig
AnonKey AnonymousKey
GateKey *keys.PrivateKey
Resolver BucketResolver
TreeService TreeService
}

// AnonymousKey contains data for anonymous requests.
AnonymousKey struct {
Key *keys.PrivateKey
}

// GetObjectParams stores object get request parameters.
GetObjectParams struct {
Range *RangeParams
Expand Down Expand Up @@ -185,7 +180,6 @@ type (
// Client provides S3 API client interface.
Client interface {
Initialize(ctx context.Context, c EventListener) error
EphemeralKey() *keys.PublicKey

GetBucketSettings(ctx context.Context, bktInfo *data.BucketInfo) (*data.BucketSettings, error)
PutBucketSettings(ctx context.Context, p *PutSettingsParams) error
Expand Down Expand Up @@ -271,17 +265,13 @@ func NewLayer(log *zap.Logger, neoFS NeoFS, config *Config) Client {
return &layer{
neoFS: neoFS,
log: log,
anonKey: config.AnonKey,
gateKey: config.GateKey,
resolver: config.Resolver,
cache: NewCache(config.Caches),
treeService: config.TreeService,
}
}

func (n *layer) EphemeralKey() *keys.PublicKey {
return n.anonKey.Key.PublicKey()
}

func (n *layer) Initialize(ctx context.Context, c EventListener) error {
if n.IsNotificationEnabled() {
return fmt.Errorf("already initialized")
Expand Down Expand Up @@ -321,7 +311,7 @@ func (n *layer) Owner(ctx context.Context) user.ID {
}

var ownerID user.ID
if err := user.IDFromKey(&ownerID, n.EphemeralKey().Bytes()); err != nil {
if err := user.IDFromKey(&ownerID, n.gateKey.PublicKey().Bytes()); err != nil {
panic(fmt.Errorf("id from key: %w", err))
}

Expand All @@ -336,7 +326,7 @@ func (n *layer) prepareAuthParameters(ctx context.Context, prm *PrmAuth, bktOwne
}
}

prm.PrivateKey = &n.anonKey.Key.PrivateKey
prm.PrivateKey = &n.gateKey.PrivateKey
}

// GetBucketInfo returns bucket info by name.
Expand Down
2 changes: 1 addition & 1 deletion api/layer/versioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func prepareContext(t *testing.T, cachesConfig ...*CachesConfig) *testContext {

layerCfg := &Config{
Caches: config,
AnonKey: AnonymousKey{Key: key},
GateKey: key,
TreeService: NewTreeService(),
}

Expand Down
12 changes: 2 additions & 10 deletions cmd/s3-gw/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,9 @@ func (a *App) initLayer(ctx context.Context) {
}
a.log.Info("init tree service", zap.String("endpoint", treeServiceEndpoint))

// prepare random key for anonymous requests
randomKey, err := keys.NewPrivateKey()
if err != nil {
a.log.Fatal("couldn't generate random key", zap.Error(err))
}

layerCfg := &layer.Config{
Caches: getCacheOptions(a.cfg, a.log),
AnonKey: layer.AnonymousKey{
Key: randomKey,
},
Caches: getCacheOptions(a.cfg, a.log),
GateKey: a.key,
Resolver: a.bucketResolver,
TreeService: treeService,
}
Expand Down

0 comments on commit 8381bbd

Please sign in to comment.