Skip to content

Commit

Permalink
revertprovider: crypted provider was not supported in v4
Browse files Browse the repository at this point in the history
also ensure to initialize kms before the dataprovider, it could be
needed to downgrade secret from cloud kms providers
  • Loading branch information
drakkan committed Dec 6, 2020
1 parent 034d898 commit c451f74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
6 changes: 6 additions & 0 deletions cmd/initprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Please take a look at the usage below to customize the options.`,
logger.WarnToConsole("Unable to initialize data provider, config load error: %v", err)
return
}
kmsConfig := config.GetKMSConfig()
err = kmsConfig.Initialize()
if err != nil {
logger.ErrorToConsole("unable to initialize KMS: %v", err)
os.Exit(1)
}
providerConf := config.GetProviderConf()
logger.InfoToConsole("Initializing provider: %#v config file: %#v", providerConf.Driver, viper.ConfigFileUsed())
err = dataprovider.InitializeDatabase(providerConf, configDir)
Expand Down
6 changes: 6 additions & 0 deletions cmd/revertprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Please take a look at the usage below to customize the options.`,
logger.WarnToConsole("Unable to initialize data provider, config load error: %v", err)
return
}
kmsConfig := config.GetKMSConfig()
err = kmsConfig.Initialize()
if err != nil {
logger.ErrorToConsole("unable to initialize KMS: %v", err)
os.Exit(1)
}
providerConf := config.GetProviderConf()
logger.InfoToConsole("Reverting provider: %#v config file: %#v target version %v", providerConf.Driver,
viper.ConfigFileUsed(), revertProviderTargetVersion)
Expand Down
10 changes: 5 additions & 5 deletions cmd/startsubsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Command-line flags should be specified in the Subsystem declaration.
commonConfig.IdleTimeout = 0
config.SetCommonConfig(commonConfig)
common.Initialize(config.GetCommonConfig())
kmsConfig := config.GetKMSConfig()
if err := kmsConfig.Initialize(); err != nil {
logger.Error(logSender, connectionID, "unable to initialize KMS: %v", err)
os.Exit(1)
}
dataProviderConf := config.GetProviderConf()
if dataProviderConf.Driver == dataprovider.SQLiteDataProviderName || dataProviderConf.Driver == dataprovider.BoltDataProviderName {
logger.Debug(logSender, connectionID, "data provider %#v not supported in subsystem mode, using %#v provider",
Expand All @@ -83,11 +88,6 @@ Command-line flags should be specified in the Subsystem declaration.
}
httpConfig := config.GetHTTPConfig()
httpConfig.Initialize(configDir)
kmsConfig := config.GetKMSConfig()
if err := kmsConfig.Initialize(); err != nil {
logger.Error(logSender, connectionID, "unable to initialize KMS: %v", err)
os.Exit(1)
}
user, err := dataprovider.UserExists(username)
if err == nil {
if user.HomeDir != filepath.Clean(homedir) && !preserveHomeDir {
Expand Down
3 changes: 3 additions & 0 deletions dataprovider/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func convertFsConfigToV4(fs Filesystem, username string) (compatFilesystemV4, er
}
fsV4.GCSConfig.Credentials = []byte(creds)
}
case CryptedFilesystemProvider:
// crypted provider was not supported in v4, the configuration will be lost
fsV4.Provider = 0
}
return fsV4, nil
}
Expand Down
16 changes: 8 additions & 8 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ func (s *Service) Start() error {
}

common.Initialize(config.GetCommonConfig())
kmsConfig := config.GetKMSConfig()
err := kmsConfig.Initialize()
if err != nil {
logger.Error(logSender, "", "unable to initialize KMS: %v", err)
logger.ErrorToConsole("unable to initialize KMS: %v", err)
os.Exit(1)
}

providerConf := config.GetProviderConf()

err := dataprovider.Initialize(providerConf, s.ConfigDir)
err = dataprovider.Initialize(providerConf, s.ConfigDir)
if err != nil {
logger.Error(logSender, "", "error initializing data provider: %v", err)
logger.ErrorToConsole("error initializing data provider: %v", err)
Expand All @@ -110,13 +117,6 @@ func (s *Service) Start() error {

httpConfig := config.GetHTTPConfig()
httpConfig.Initialize(s.ConfigDir)
kmsConfig := config.GetKMSConfig()
err = kmsConfig.Initialize()
if err != nil {
logger.Error(logSender, "", "unable to initialize KMS: %v", err)
logger.ErrorToConsole("unable to initialize KMS: %v", err)
os.Exit(1)
}

s.startServices()

Expand Down

0 comments on commit c451f74

Please sign in to comment.