mirror of https://github.com/status-im/consul.git
revert go changes to hide rotation config
This commit is contained in:
parent
c20bbf8760
commit
162daca4d7
|
@ -88,10 +88,6 @@ func fixupConfig(conf *structs.CAConfiguration) {
|
||||||
if k == "PrivateKey" && strVal != "" {
|
if k == "PrivateKey" && strVal != "" {
|
||||||
conf.Config["PrivateKey"] = "hidden"
|
conf.Config["PrivateKey"] = "hidden"
|
||||||
}
|
}
|
||||||
// todo(kyhavlov): add this back in when it's actually used
|
|
||||||
if k == "RotationPeriod" {
|
|
||||||
delete(conf.Config, k)
|
|
||||||
}
|
|
||||||
case structs.VaultCAProvider:
|
case structs.VaultCAProvider:
|
||||||
if k == "Token" && strVal != "" {
|
if k == "Token" && strVal != "" {
|
||||||
conf.Config["Token"] = "hidden"
|
conf.Config["Token"] = "hidden"
|
||||||
|
|
|
@ -2,11 +2,10 @@ package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/connect"
|
"github.com/hashicorp/consul/agent/connect"
|
||||||
ca "github.com/hashicorp/consul/agent/connect/ca"
|
ca "github.com/hashicorp/consul/agent/connect/ca"
|
||||||
|
@ -66,8 +65,9 @@ func TestConnectCAConfig(t *testing.T) {
|
||||||
a := NewTestAgent(t.Name(), "")
|
a := NewTestAgent(t.Name(), "")
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
root := connect.TestCA(t, nil)
|
expected := &structs.ConsulCAProviderConfig{
|
||||||
expected := &structs.ConsulCAProviderConfig{}
|
RotationPeriod: 90 * 24 * time.Hour,
|
||||||
|
}
|
||||||
|
|
||||||
// Get the initial config.
|
// Get the initial config.
|
||||||
{
|
{
|
||||||
|
@ -85,17 +85,13 @@ func TestConnectCAConfig(t *testing.T) {
|
||||||
|
|
||||||
// Set the config.
|
// Set the config.
|
||||||
{
|
{
|
||||||
conf := fmt.Sprintf(`
|
body := bytes.NewBuffer([]byte(`
|
||||||
{
|
{
|
||||||
"Provider": "consul",
|
"Provider": "consul",
|
||||||
"Config": {
|
"Config": {
|
||||||
"PrivateKey": "%s",
|
"RotationPeriod": 3600000000000
|
||||||
"RootCert": "%s"
|
}
|
||||||
}
|
}`))
|
||||||
}`,
|
|
||||||
strings.Replace(root.SigningKey, "\n", "\\n", -1),
|
|
||||||
strings.Replace(root.RootCert, "\n", "\\n", -1))
|
|
||||||
body := bytes.NewBuffer([]byte(conf))
|
|
||||||
req, _ := http.NewRequest("PUT", "/v1/connect/ca/configuration", body)
|
req, _ := http.NewRequest("PUT", "/v1/connect/ca/configuration", body)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
_, err := a.srv.ConnectCAConfiguration(resp, req)
|
_, err := a.srv.ConnectCAConfiguration(resp, req)
|
||||||
|
@ -104,8 +100,7 @@ func TestConnectCAConfig(t *testing.T) {
|
||||||
|
|
||||||
// The config should be updated now.
|
// The config should be updated now.
|
||||||
{
|
{
|
||||||
expected.PrivateKey = "hidden"
|
expected.RotationPeriod = time.Hour
|
||||||
expected.RootCert = root.RootCert
|
|
||||||
req, _ := http.NewRequest("GET", "/v1/connect/ca/configuration", nil)
|
req, _ := http.NewRequest("GET", "/v1/connect/ca/configuration", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := a.srv.ConnectCAConfiguration(resp, req)
|
obj, err := a.srv.ConnectCAConfiguration(resp, req)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pascaldekloe/goe/verify"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/testutil"
|
"github.com/hashicorp/consul/testutil"
|
||||||
"github.com/hashicorp/consul/testutil/retry"
|
"github.com/hashicorp/consul/testutil/retry"
|
||||||
|
@ -59,6 +61,10 @@ func TestAPI_ConnectCAConfig_get_set(t *testing.T) {
|
||||||
c, s := makeClient(t)
|
c, s := makeClient(t)
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
|
|
||||||
|
expected := &ConsulCAProviderConfig{
|
||||||
|
RotationPeriod: 90 * 24 * time.Hour,
|
||||||
|
}
|
||||||
|
|
||||||
// This fails occasionally if server doesn't have time to bootstrap CA so
|
// This fails occasionally if server doesn't have time to bootstrap CA so
|
||||||
// retry
|
// retry
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
|
@ -69,15 +75,21 @@ func TestAPI_ConnectCAConfig_get_set(t *testing.T) {
|
||||||
if conf.Provider != "consul" {
|
if conf.Provider != "consul" {
|
||||||
r.Fatalf("expected default provider, got %q", conf.Provider)
|
r.Fatalf("expected default provider, got %q", conf.Provider)
|
||||||
}
|
}
|
||||||
_, err = ParseConsulCAConfig(conf.Config)
|
parsed, err := ParseConsulCAConfig(conf.Config)
|
||||||
r.Check(err)
|
r.Check(err)
|
||||||
|
verify.Values(r, "", parsed, expected)
|
||||||
|
|
||||||
// Change a config value and update
|
// Change a config value and update
|
||||||
conf.Config["PrivateKey"] = "invalid"
|
conf.Config["PrivateKey"] = ""
|
||||||
|
conf.Config["RotationPeriod"] = 120 * 24 * time.Hour
|
||||||
_, err = connect.CASetConfig(conf, nil)
|
_, err = connect.CASetConfig(conf, nil)
|
||||||
if err == nil || !strings.Contains(err.Error(),
|
r.Check(err)
|
||||||
"error parsing private key \"invalid\": no PEM-encoded data found") {
|
|
||||||
r.Fatal(err)
|
updated, _, err := connect.CAGetConfig(nil)
|
||||||
}
|
r.Check(err)
|
||||||
|
expected.RotationPeriod = 120 * 24 * time.Hour
|
||||||
|
parsed, err = ParseConsulCAConfig(updated.Config)
|
||||||
|
r.Check(err)
|
||||||
|
verify.Values(r, "", parsed, expected)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue