Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Skip security-proxy runtime config options on deferred startup (#25)
Browse files Browse the repository at this point in the history
This change disables the application of the following config options
in defer-startup install mode to be applied separately after the setup 
of security-proxy:
* env.security-proxy.user
* env.security-proxy.public-key
* env.security-proxy.tls-certificate
* env.security-proxy.tls-private-key
* env.security-proxy.tls-sni

This is change is coupled with edgexfoundry/edgex-go#3856
  • Loading branch information
farshidtz authored Jan 19, 2022
1 parent 15bfb8d commit d63b067
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ func HandleEdgeXConfig(service, envJSON string, extraConf map[string]string) err
// This uses the standard naming schema but doesn't actually use environment variables
if service == "security-proxy" {
value := strings.TrimSpace(v)
// These config options are read and validated in the loop,
// but handled collectively afterwards
switch k {
case "user":
if value != "" {
Expand Down Expand Up @@ -695,35 +697,45 @@ func HandleEdgeXConfig(service, envJSON string, extraConf map[string]string) err
}
}

// Handle security-* service naming. The service names in this
// hook historically do not align with the actual binary commands.
// As such, when handling configuration settings for them, we need
// to translate the hook name to the actual binary name.
if service == "security-proxy" {
service = "security-proxy-setup"
// install-mode is set in the install hook of edgexfoundry
installMode, err := NewSnapCtl().Config("install-mode")
if err != nil {
return fmt.Errorf("failed to read 'install-mode': %s", err)
}

if jwtUsername == "" && jwtPublicKey == "" {
// if the values have been set to "" then delete the current user
securityProxyDeleteCurrentUserIfSet()
} else if jwtUsername != "" && jwtPublicKey != "" {
// else add a new user
err = securityProxyAddUser(jwtUsername, jwtUserID, jwtAlgorithm, jwtPublicKey)
if err != nil {
return err
// post-startup config handling
if installMode != "defer-startup" {
if service == "security-proxy" {
if jwtUsername == "" && jwtPublicKey == "" {
// if the values have been set to "" then delete the current user
securityProxyDeleteCurrentUserIfSet()
} else if jwtUsername != "" && jwtPublicKey != "" {
// else add a new user
err = securityProxyAddUser(jwtUsername, jwtUserID, jwtAlgorithm, jwtPublicKey)
if err != nil {
return err
}
}
}

if tlsCertificate == "" && tlsPrivateKey == "" {
// if the values have been set to "" then clear the semaphore so that a new cert can be set
securityProxyDeleteCurrentTLSCertIfSet()
} else if tlsCertificate != "" && tlsPrivateKey != "" {
// Set the TLS certificate and private key
err = securityProxySetTLSCertificate(tlsCertificate, tlsPrivateKey, tlsSNI)
if err != nil {
return err
if tlsCertificate == "" && tlsPrivateKey == "" {
// if the values have been set to "" then clear the semaphore so that a new cert can be set
securityProxyDeleteCurrentTLSCertIfSet()
} else if tlsCertificate != "" && tlsPrivateKey != "" {
// Set the TLS certificate and private key
err = securityProxySetTLSCertificate(tlsCertificate, tlsPrivateKey, tlsSNI)
if err != nil {
return err
}
}
}
}

// Handle security-* service naming. The service names in this
// hook historically do not align with the actual binary commands.
// As such, when handling configuration settings for them, we need
// to translate the hook name to the actual binary name.
if service == "security-proxy" {
service = "security-proxy-setup"
} else if service == "security-secret-store" {
service = "security-secretstore-setup"
}
Expand Down

0 comments on commit d63b067

Please sign in to comment.