Skip to content

Commit 9bba11e

Browse files
mergify[bot]pchila
andauthored
pass unprivileged flag to store migration (#4688) (#4700)
(cherry picked from commit 25c9efd) Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
1 parent 5b34981 commit 9bba11e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

internal/pkg/agent/storage/store/state_store.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ type stateSerializer struct {
7575
}
7676

7777
// NewStateStoreWithMigration creates a new state store and migrates the old one.
78-
func NewStateStoreWithMigration(ctx context.Context, log *logger.Logger, actionStorePath, stateStorePath string) (*StateStore, error) {
79-
err := migrateStateStore(ctx, log, actionStorePath, stateStorePath)
78+
func NewStateStoreWithMigration(ctx context.Context, log *logger.Logger, actionStorePath, stateStorePath string, storageOpts ...storage.EncryptedOptionFunc) (*StateStore, error) {
79+
err := migrateStateStore(ctx, log, actionStorePath, stateStorePath, storageOpts...)
8080
if err != nil {
8181
return nil, err
8282
}
8383

84-
encryptedDiskStore, err := storage.NewEncryptedDiskStore(ctx, stateStorePath)
84+
encryptedDiskStore, err := storage.NewEncryptedDiskStore(ctx, stateStorePath, storageOpts...)
8585
if err != nil {
8686
return nil, fmt.Errorf("error instantiating encrypted disk store: %w", err)
8787
}
@@ -147,14 +147,14 @@ func NewStateStore(log *logger.Logger, store storeLoad) (*StateStore, error) {
147147
}, nil
148148
}
149149

150-
func migrateStateStore(ctx context.Context, log *logger.Logger, actionStorePath, stateStorePath string) (err error) {
150+
func migrateStateStore(ctx context.Context, log *logger.Logger, actionStorePath, stateStorePath string, storageOpts ...storage.EncryptedOptionFunc) (err error) {
151151
log = log.Named("state_migration")
152152
actionDiskStore, err := storage.NewDiskStore(actionStorePath)
153153
if err != nil {
154154
return fmt.Errorf("error creating disk store: %w", err)
155155
}
156156

157-
stateDiskStore, err := storage.NewEncryptedDiskStore(ctx, stateStorePath)
157+
stateDiskStore, err := storage.NewEncryptedDiskStore(ctx, stateStorePath, storageOpts...)
158158
if err != nil {
159159
return fmt.Errorf("error instantiating encrypted disk store: %w", err)
160160
}

internal/pkg/config/operations/inspector.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func LoadFullAgentConfig(ctx context.Context, logger *logger.Logger, cfgPath str
5555
return c, nil
5656
}
5757

58-
fleetConfig, err := loadFleetConfig(ctx, logger)
58+
fleetConfig, err := loadFleetConfig(ctx, logger, unprivileged)
5959
if err != nil {
6060
return nil, fmt.Errorf("error obtaining fleet config: %w", err)
6161
} else if fleetConfig == nil {
@@ -115,8 +115,8 @@ func loadConfig(ctx context.Context, configPath string, unprivileged bool) (*con
115115
return rawConfig, nil
116116
}
117117

118-
func loadFleetConfig(ctx context.Context, l *logger.Logger) (map[string]interface{}, error) {
119-
stateStore, err := store.NewStateStoreWithMigration(ctx, l, paths.AgentActionStoreFile(), paths.AgentStateStoreFile())
118+
func loadFleetConfig(ctx context.Context, l *logger.Logger, unprivileged bool) (map[string]interface{}, error) {
119+
stateStore, err := store.NewStateStoreWithMigration(ctx, l, paths.AgentActionStoreFile(), paths.AgentStateStoreFile(), storage.WithUnprivileged(unprivileged))
120120
if err != nil {
121121
return nil, err
122122
}

0 commit comments

Comments
 (0)