Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create optional kong certificate config options #2940

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Protocol = "http"
Server = "edgex-vault"
ServerName = ""
Port = 8200
CaFilePath = ''
CaFilePath = ""

[TokenFileProvider]
PrivilegedTokenPath = "/run/edgex/secrets/tokenprovider/secrets-token.json"
Expand Down
6 changes: 3 additions & 3 deletions cmd/security-secretstore-setup/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ LogLevel = 'DEBUG'
Protocol = "http"
Server = "edgex-vault"
Port = 8200
CertPath = "v1/secret/edgex/edgex-security-proxy-setup/kong-tls"
CertPath = ""
CaFilePath = ""
CertFilePath = "/tmp/edgex/secrets/edgex-kong/server.crt"
KeyFilePath = "/tmp/edgex/secrets/edgex-kong/server.key"
CertFilePath = ""
KeyFilePath = ""
TokenFolderPath = "/vault/config/assets"
TokenFile = "resp-init.json"
VaultSecretShares = 5
Expand Down
63 changes: 40 additions & 23 deletions internal/security/secretstore/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -340,36 +341,52 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, _ *sync.WaitGroup, _ s
os.Exit(1)
}

cert := NewCerts(req, configuration.SecretService.CertPath, rootToken, configuration.SecretService.GetSecretSvcBaseURL(), lc)
existing, err := cert.AlreadyinStore()
if err != nil {
lc.Error(err.Error())
os.Exit(1)
}
// Concat all cert path config vals together to check for empty vals
certPathCheck := configuration.SecretService.CertPath +
configuration.SecretService.CertFilePath +
configuration.SecretService.KeyFilePath

if existing == true {
lc.Info("proxy certificate pair are in the secret store already, skip uploading")
return false
}
// If any of the previous three proxy cert path values are present (len > 0), attempt to upload to secret store
if len(strings.TrimSpace(certPathCheck)) != 0 {

lc.Info("proxy certificate pair are not in the secret store yet, uploading them")
cp, err := cert.ReadFrom(configuration.SecretService.CertFilePath, configuration.SecretService.KeyFilePath)
if err != nil {
lc.Error("failed to get certificate pair from volume")
os.Exit(1)
}
// Grab the certificate & check to see if it's already in the secret store
cert := NewCerts(req, configuration.SecretService.CertPath, rootToken, configuration.SecretService.GetSecretSvcBaseURL(), lc)
existing, err := cert.AlreadyinStore()
if err != nil {
lc.Error(err.Error())
os.Exit(1)
}

lc.Info("proxy certificate pair are loaded from volume successfully, will upload to secret store")
if existing {
lc.Info("proxy certificate pair are in the secret store already, skip uploading")
return false
}

err = cert.UploadToStore(cp)
if err != nil {
lc.Error("failed to upload the proxy cert pair into the secret store")
lc.Error(err.Error())
os.Exit(1)
lc.Info("proxy certificate pair are not in the secret store yet, uploading them")
cp, err := cert.ReadFrom(configuration.SecretService.CertFilePath, configuration.SecretService.KeyFilePath)
if err != nil {
lc.Error("failed to get certificate pair from volume")
os.Exit(1)
}

lc.Info("proxy certificate pair are loaded from volume successfully, will upload to secret store")

err = cert.UploadToStore(cp)
if err != nil {
lc.Error("failed to upload the proxy cert pair into the secret store")
lc.Error(err.Error())
os.Exit(1)
}

lc.Info("proxy certificate pair are uploaded to secret store successfully")

} else {
lc.Info("proxy certificate pair upload was skipped because cert config value(s) were blank")
}
beaufrusetta marked this conversation as resolved.
Show resolved Hide resolved

lc.Info("proxy certificate pair are uploaded to secret store successfully, Vault init done successfully")
lc.Info("Vault init done successfully")
return false

}

// XXX Collapse addServiceCredential and addDBCredential together by passing in the path or using
Expand Down