Skip to content

Commit

Permalink
feat(security): Remove Writable from security services
Browse files Browse the repository at this point in the history
Update for security services on:

- Loglevel is on the top level of ConfigurationStruct
- Remove Writable from Configuration struct
- Make UpdateFromRaw, UpdateWritableFromRaw do nothing and make EmptyWritablePtr just return nil

Fixes: #3123

Signed-off-by: Jim Wang <yutsung.jim.wang@intel.com>
  • Loading branch information
jim-wang-intel committed Feb 8, 2021
1 parent 9ee6a91 commit 15c04cc
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 89 deletions.
2 changes: 1 addition & 1 deletion cmd/secrets-config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func main() {
os.Setenv("WRITABLE_LOGLEVEL", "ERROR") // Workaround for https://github.com/edgexfoundry/edgex-go/issues/2922
os.Setenv("LOGLEVEL", "ERROR") // Workaround for https://github.com/edgexfoundry/edgex-go/issues/2922
ctx, cancel := context.WithCancel(context.Background())
exitStatusCode := config.Main(ctx, cancel)
os.Exit(exitStatusCode)
Expand Down
1 change: 0 additions & 1 deletion cmd/security-bootstrapper/res/configuration.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[Writable]
LogLevel = 'INFO'

[StageGate]
Expand Down
3 changes: 2 additions & 1 deletion cmd/security-proxy-setup/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

# This is a TOML config file for edgexsecurity service.

[Writable]
LogLevel = "DEBUG"

[ProxySetup]
RequestTimeout = 10

[KongURL]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[Writable]
LogLevel = 'DEBUG'

[SecretService]
Expand Down
1 change: 0 additions & 1 deletion cmd/security-secretstore-setup/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

# This is a TOML config file for EdgeX security-secretstore-setup service.

[Writable]
LogLevel = 'DEBUG'

[SecretService]
Expand Down
22 changes: 5 additions & 17 deletions internal/security/bootstrapper/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,26 @@ import (
)

type ConfigurationStruct struct {
Writable WritableInfo
LogLevel string
StageGate StageGateInfo
}

type WritableInfo struct {
LogLevel string
}

// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
// then used to overwrite the service's existing configuration struct.
func (c *ConfigurationStruct) UpdateFromRaw(rawConfig interface{}) bool {
configuration, ok := rawConfig.(*ConfigurationStruct)
if ok {
*c = *configuration
}
return ok
return false
}

// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to
// provide the appropriate structure to registry.Client's WatchForChanges().
func (c *ConfigurationStruct) EmptyWritablePtr() interface{} {
return &WritableInfo{}
return nil
}

// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
// which is then used to overwrite the service's existing configuration's WritableInfo struct.
func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable interface{}) bool {
writable, ok := rawWritable.(*WritableInfo)
if ok {
c.Writable = *writable
}
return ok
return false
}

// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration
Expand All @@ -65,7 +53,7 @@ func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfigurat

// GetLogLevel returns the current ConfigurationStruct's log level.
func (c *ConfigurationStruct) GetLogLevel() string {
return c.Writable.LogLevel
return c.LogLevel
}

// GetRegistryInfo returns the RegistryInfo from the ConfigurationStruct.
Expand Down
27 changes: 5 additions & 22 deletions internal/security/fileprovider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ import (
)

type ConfigurationStruct struct {
Writable WritableInfo
LogLevel string
SecretService secretstoreclient.SecretServiceInfo
TokenFileProvider TokenFileProviderInfo
}

type WritableInfo struct {
LogLevel string
Title string
}

type TokenFileProviderInfo struct {
// Path to Vault authorization token to be used by the service
PrivilegedTokenPath string
Expand All @@ -47,31 +42,19 @@ type TokenFileProviderInfo struct {
// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
// then used to overwrite the service's existing configuration struct.
func (c *ConfigurationStruct) UpdateFromRaw(rawConfig interface{}) bool {
configuration, ok := rawConfig.(*ConfigurationStruct)
if ok {
// Check that information was successfully read from Registry
if configuration.SecretService.Port == 0 {
return false
}
*c = *configuration
}
return ok
return false
}

// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to
// provide the appropriate structure to registry.Client's WatchForChanges().
func (c *ConfigurationStruct) EmptyWritablePtr() interface{} {
return &WritableInfo{}
return nil
}

// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
// which is then used to overwrite the service's existing configuration's WritableInfo struct.
func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable interface{}) bool {
writable, ok := rawWritable.(*WritableInfo)
if ok {
c.Writable = *writable
}
return ok
return false
}

// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration
Expand All @@ -85,7 +68,7 @@ func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfigurat

// GetLogLevel returns the current ConfigurationStruct's log level.
func (c *ConfigurationStruct) GetLogLevel() string {
return c.Writable.LogLevel
return c.LogLevel
}

// GetRegistryInfo returns the RegistryInfo from the ConfigurationStruct.
Expand Down
29 changes: 9 additions & 20 deletions internal/security/proxy/config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*******************************************************************************
* Copyright 2021 Intel Corporation
* Copyright 2019 Dell Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
Expand All @@ -24,7 +25,8 @@ import (
)

type ConfigurationStruct struct {
Writable WritableInfo
LogLevel string
ProxySetup ProxySetupInfo
KongURL KongUrlInfo
KongAuth KongAuthInfo
KongACL KongAclInfo
Expand All @@ -33,8 +35,7 @@ type ConfigurationStruct struct {
Clients map[string]bootstrapConfig.ClientInfo
}

type WritableInfo struct {
LogLevel string
type ProxySetupInfo struct {
RequestTimeout int
}

Expand Down Expand Up @@ -92,31 +93,19 @@ func (s SecretServiceInfo) GetSecretSvcBaseURL() string {
// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
// then used to overwrite the service's existing configuration struct.
func (c *ConfigurationStruct) UpdateFromRaw(rawConfig interface{}) bool {
configuration, ok := rawConfig.(*ConfigurationStruct)
if ok {
// Check that information was successfully read from Registry
if configuration.SecretService.Port == 0 {
return false
}
*c = *configuration
}
return ok
return false
}

// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to
// provide the appropriate structure to registry.Client's WatchForChanges().
func (c *ConfigurationStruct) EmptyWritablePtr() interface{} {
return &WritableInfo{}
return nil
}

// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
// which is then used to overwrite the service's existing configuration's WritableInfo struct.
func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable interface{}) bool {
writable, ok := rawWritable.(*WritableInfo)
if ok {
c.Writable = *writable
}
return ok
return false
}

// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration
Expand Down Expand Up @@ -148,7 +137,7 @@ func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfigurat

// GetLogLevel returns the current ConfigurationStruct's log level.
func (c *ConfigurationStruct) GetLogLevel() string {
return c.Writable.LogLevel
return c.LogLevel
}

// GetRegistryInfo returns the RegistryInfo from the ConfigurationStruct.
Expand All @@ -158,7 +147,7 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
panic("GetDatabaseInfo() called unexpectedly.")
return nil
}

// GetInsecureSecrets returns the service's InsecureSecrets which this service doesn't support
Expand Down
4 changes: 2 additions & 2 deletions internal/security/proxy/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func (b *Bootstrap) BootstrapHandler(_ context.Context, _ *sync.WaitGroup, _ sta
if len(configuration.SecretService.CACertPath) > 0 {
req = NewRequestor(
b.insecureSkipVerify,
configuration.Writable.RequestTimeout,
configuration.ProxySetup.RequestTimeout,
configuration.SecretService.CACertPath,
lc)
} else {
req = NewRequestor(
true, // non-TLS mode internally
configuration.Writable.RequestTimeout,
configuration.ProxySetup.RequestTimeout,
"", // irrelevant
lc)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/security/proxy/testdata/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

# This is a TOML config file for edgexsecurity service.

[Writable]
LogLevel = 'DEBUG'

[ProxySetup]
RequestTimeout = 10

[KongURL]
Expand Down
27 changes: 5 additions & 22 deletions internal/security/secretstore/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ import (
)

type ConfigurationStruct struct {
Writable WritableInfo
LogLevel string
SecretService secretstoreclient.SecretServiceInfo
Databases map[string]Database
}

type WritableInfo struct {
LogLevel string
Title string
}

type Database struct {
Username string
Service string
Expand All @@ -40,31 +35,19 @@ type Database struct {
// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
// then used to overwrite the service's existing configuration struct.
func (c *ConfigurationStruct) UpdateFromRaw(rawConfig interface{}) bool {
configuration, ok := rawConfig.(*ConfigurationStruct)
if ok {
// Check that information was successfully read from Registry
if configuration.SecretService.Port == 0 {
return false
}
*c = *configuration
}
return ok
return false
}

// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to
// provide the appropriate structure to registry.Client's WatchForChanges().
func (c *ConfigurationStruct) EmptyWritablePtr() interface{} {
return &WritableInfo{}
return nil
}

// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
// which is then used to overwrite the service's existing configuration's WritableInfo struct.
func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable interface{}) bool {
writable, ok := rawWritable.(*WritableInfo)
if ok {
c.Writable = *writable
}
return ok
return false
}

// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration
Expand All @@ -78,7 +61,7 @@ func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfigurat

// GetLogLevel returns the current ConfigurationStruct's log level.
func (c *ConfigurationStruct) GetLogLevel() string {
return c.Writable.LogLevel
return c.LogLevel
}

// GetRegistryInfo returns the RegistryInfo from the ConfigurationStruct.
Expand Down

0 comments on commit 15c04cc

Please sign in to comment.