Skip to content
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
9 changes: 9 additions & 0 deletions agent/cache-types/trust_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/mitchellh/hashstructure"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/hashicorp/consul/agent/cache"
external "github.com/hashicorp/consul/agent/grpc-external"
Expand Down Expand Up @@ -87,6 +89,13 @@ func (t *TrustBundles) Fetch(_ cache.FetchOptions, req cache.Request) (cache.Fet
// Fetch
reply, err := t.Client.TrustBundleListByService(external.ContextWithToken(context.Background(), reqReal.Token), reqReal.Request)
if err != nil {
// Return an empty result if the error is due to peering being disabled.
// This allows mesh gateways to receive an update and confirm that the watch is set.
if e, ok := status.FromError(err); ok && e.Code() == codes.FailedPrecondition {
result.Index = 1
result.Value = &pbpeering.TrustBundleListByServiceResponse{Index: 1}
return result, nil
}
return result, err
}

Expand Down
25 changes: 25 additions & 0 deletions agent/cache-types/trust_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

"github.com/hashicorp/consul/agent/cache"
"github.com/hashicorp/consul/proto/pbpeering"
Expand Down Expand Up @@ -48,6 +50,29 @@ func TestTrustBundles(t *testing.T) {
}, result)
}

func TestTrustBundles_PeeringDisabled(t *testing.T) {
client := NewMockTrustBundleLister(t)
typ := &TrustBundles{Client: client}

var resp *pbpeering.TrustBundleListByServiceResponse

// Expect the proper call.
// This also returns the canned response above.
client.On("TrustBundleListByService", mock.Anything, mock.Anything).
Return(resp, grpcstatus.Error(codes.FailedPrecondition, "peering must be enabled to use this endpoint"))

// Fetch and assert against the result.
result, err := typ.Fetch(cache.FetchOptions{}, &TrustBundleListRequest{
Request: &pbpeering.TrustBundleListByServiceRequest{
ServiceName: "foo",
},
})
require.NoError(t, err)
require.NotNil(t, result)
require.EqualValues(t, 1, result.Index)
require.NotNil(t, result.Value)
}

func TestTrustBundles_badReqType(t *testing.T) {
client := pbpeering.NewPeeringServiceClient(nil)
typ := &TrustBundles{Client: client}
Expand Down
3 changes: 0 additions & 3 deletions agent/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ func DefaultSource() Source {
kv_max_value_size = ` + strconv.FormatInt(raft.SuggestedMaxDataSize, 10) + `
txn_max_req_len = ` + strconv.FormatInt(raft.SuggestedMaxDataSize, 10) + `
}
peering = {
enabled = true
}
performance = {
leave_drain_time = "5s"
raft_multiplier = ` + strconv.Itoa(int(consul.DefaultRaftMultiplier)) + `
Expand Down
10 changes: 0 additions & 10 deletions agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5548,16 +5548,6 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
"tls.grpc was provided but TLS will NOT be enabled on the gRPC listener without an HTTPS listener configured (e.g. via ports.https)",
},
})
run(t, testCase{
desc: "peering.enabled defaults to true",
args: []string{
`-data-dir=` + dataDir,
},
expected: func(rt *RuntimeConfig) {
rt.DataDir = dataDir
rt.PeeringEnabled = true
},
})
}

func (tc testCase) run(format string, dataDir string) func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion agent/consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ func DefaultConfig() *Config {
DefaultQueryTime: 300 * time.Second,
MaxQueryTime: 600 * time.Second,

PeeringEnabled: true,
PeeringTestAllowPeerRegistrations: false,

EnterpriseConfig: DefaultEnterpriseConfig(),
Expand Down
1 change: 1 addition & 0 deletions agent/consul/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func testServerConfig(t *testing.T) (string, *Config) {
"IntermediateCertTTL": "288h",
},
}
config.PeeringEnabled = true
return dir, config
}

Expand Down
1 change: 1 addition & 0 deletions agent/rpc/peering/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ func newTestServer(t *testing.T, cb func(conf *consul.Config)) testingServer {

ports := freeport.GetN(t, 4) // {rpc, serf_lan, serf_wan, grpc}

conf.PeeringEnabled = true
conf.Bootstrap = true
conf.Datacenter = "dc1"
conf.DataDir = dir
Expand Down
3 changes: 3 additions & 0 deletions agent/testagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func TestConfigHCL(nodeID string) string {
}
performance {
raft_multiplier = 1
}
peering {
enabled = true
}`, nodeID, connect.TestClusterID,
)
}
Expand Down
10 changes: 8 additions & 2 deletions sdk/testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type TestServerConfig struct {
Connect map[string]interface{} `json:"connect,omitempty"`
EnableDebug bool `json:"enable_debug,omitempty"`
SkipLeaveOnInt bool `json:"skip_leave_on_interrupt"`
Peering *TestPeeringConfig `json:"peering,omitempty"`
ReadyTimeout time.Duration `json:"-"`
StopTimeout time.Duration `json:"-"`
Stdout io.Writer `json:"-"`
Expand Down Expand Up @@ -139,6 +140,10 @@ type TestTokens struct {
AgentRecovery string `json:"agent_master,omitempty"`
}

type TestPeeringConfig struct {
Enabled bool `json:"enabled,omitempty"`
}

// ServerConfigCallback is a function interface which can be
// passed to NewTestServerConfig to modify the server config.
type ServerConfigCallback func(c *TestServerConfig)
Expand Down Expand Up @@ -192,8 +197,9 @@ func defaultServerConfig(t TestingTB) *TestServerConfig {
ReturnPorts: func() {
freeport.Return(ports)
},
Stdout: logBuffer,
Stderr: logBuffer,
Stdout: logBuffer,
Stderr: logBuffer,
Peering: &TestPeeringConfig{Enabled: true},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
primary_datacenter = "alpha"
log_level = "trace"
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
primary_datacenter = "alpha"
log_level = "trace"
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
primary_datacenter = "alpha"
log_level = "trace"
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
primary_datacenter = "alpha"
log_level = "trace"
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
peering {
enabled = true
}
2 changes: 1 addition & 1 deletion website/content/docs/agent/config/config-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'."

The following sub-keys are available:

- `enabled` ((#peering_enabled)) (Defaults to `true`) Controls whether cluster peering is enabled.
- `enabled` ((#peering_enabled)) (Defaults to `false`) Controls whether cluster peering is enabled.
When disabled, the UI won't show peering, all peering APIs will return
an error, any peerings stored in Consul already will be ignored (but they will not be deleted),
and all peering connections from other clusters will be rejected. This was added in Consul 1.13.0.
Expand Down