Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
xwa153 committed Aug 4, 2023
2 parents b1682ef + 1f28ac2 commit 0c13388
Show file tree
Hide file tree
Showing 66 changed files with 9,340 additions and 380 deletions.
31 changes: 31 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,34 @@
# release configuration
/.release/ @hashicorp/release-engineering @hashicorp/github-consul-core
/.github/workflows/build.yml @hashicorp/release-engineering @hashicorp/github-consul-core


# Staff Engineer Review (protocol buffer definitions)
/proto-public/ @hashicorp/consul-core-staff
/proto/ @hashicorp/consul-core-staff

# Staff Engineer Review (v1 architecture shared components)
/agent/cache/ @hashicorp/consul-core-staff
/agent/consul/fsm/ @hashicorp/consul-core-staff
/agent/consul/leader*.go @hashicorp/consul-core-staff
/agent/consul/server*.go @hashicorp/consul-core-staff
/agent/consul/state/ @hashicorp/consul-core-staff
/agent/consul/stream/ @hashicorp/consul-core-staff
/agent/submatview/ @hashicorp/consul-core-staff
/agent/blockingquery/ @hashicorp/consul-core-staff

# Staff Engineer Review (raft/autopilot)
/agent/consul/autopilotevents/ @hashicorp/consul-core-staff
/agent/consul/autopilot*.go @hashicorp/consul-core-staff

# Staff Engineer Review (v2 architecture shared components)
/internal/controller/ @hashicorp/consul-core-staff
/internal/resource/ @hashicorp/consul-core-staff
/internal/storage/ @hashicorp/consul-core-staff
/agent/consul/controller/ @hashicorp/consul-core-staff
/agent/grpc-external/services/resource/ @hashicorp/consul-core-staff

# Staff Engineer Review (v1 security)
/acl/ @hashicorp/consul-core-staff
/agent/xds/rbac*.go @hashicorp/consul-core-staff
/agent/xds/jwt*.go @hashicorp/consul-core-staff
7 changes: 7 additions & 0 deletions agent/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package agent
import (
"fmt"
"net/http"
"net/url"
"strings"

"github.com/hashicorp/consul/acl"
Expand Down Expand Up @@ -145,6 +146,12 @@ func (s *HTTPHandlers) ACLPolicyCRUD(resp http.ResponseWriter, req *http.Request
}

func (s *HTTPHandlers) ACLPolicyRead(resp http.ResponseWriter, req *http.Request, policyID, policyName string) (interface{}, error) {
// policy name needs to be unescaped in case there were `/` characters
policyName, err := url.QueryUnescape(policyName)
if err != nil {
return nil, err
}

args := structs.ACLPolicyGetRequest{
Datacenter: s.agent.config.Datacenter,
PolicyID: policyID,
Expand Down
3 changes: 1 addition & 2 deletions agent/proxycfg/testing_api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (

"github.com/mitchellh/go-testing-interface"

"github.com/hashicorp/consul/agent/configentry"
"github.com/hashicorp/consul/agent/connect"
"github.com/hashicorp/consul/agent/consul/discoverychain"

"github.com/hashicorp/consul/agent/configentry"
"github.com/hashicorp/consul/agent/structs"
)

Expand Down
67 changes: 67 additions & 0 deletions agent/proxycfg/testing_mesh_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,73 @@ func TestConfigSnapshotPeeredMeshGateway(t testing.T, variant string, nsFn func(
},
},
)
case "mgw-peered-upstream":
// This is a modified version of "chain-and-l7-stuff" that adds a peer field to the resolver
// and removes some of the extraneous disco-chain testing.
entries = []structs.ConfigEntry{
&structs.ProxyConfigEntry{
Kind: structs.ProxyDefaults,
Name: structs.ProxyConfigGlobal,
Config: map[string]interface{}{
"protocol": "http",
},
},
&structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver,
Name: "db",
Redirect: &structs.ServiceResolverRedirect{
Service: "alt",
Peer: "peer-b",
},
ConnectTimeout: 33 * time.Second,
RequestTimeout: 33 * time.Second,
},
}
for _, entry := range entries {
require.NoError(t, entry.Normalize())
require.NoError(t, entry.Validate())
}

set := configentry.NewDiscoveryChainSet()
set.AddEntries(entries...)

var (
dbSN = structs.NewServiceName("db", nil)
altSN = structs.NewServiceName("alt", nil)

dbChain = discoverychain.TestCompileConfigEntries(t, "db", "default", "default", "dc1", connect.TestClusterID+".consul", nil, set)
)

needPeerA = true
needLeaf = true
discoChains[dbSN] = dbChain
endpoints[dbSN] = TestUpstreamNodes(t, "db")
endpoints[altSN] = TestUpstreamNodes(t, "alt")

extraUpdates = append(extraUpdates,
UpdateEvent{
CorrelationID: datacentersWatchID,
Result: &[]string{"dc1"},
},
UpdateEvent{
CorrelationID: exportedServiceListWatchID,
Result: &structs.IndexedExportedServiceList{
Services: map[string]structs.ServiceList{
"peer-a": []structs.ServiceName{dbSN},
},
},
},
UpdateEvent{
CorrelationID: serviceListWatchID,
Result: &structs.IndexedServiceList{
Services: []structs.ServiceName{
dbSN,
altSN,
},
},
},
)

case "chain-and-l7-stuff":
entries = []structs.ConfigEntry{
&structs.ProxyConfigEntry{
Expand Down
3 changes: 3 additions & 0 deletions agent/proxycfg/testing_terminating_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package proxycfg

import (
"time"

"github.com/mitchellh/go-testing-interface"

"github.com/hashicorp/consul/agent/structs"
Expand Down Expand Up @@ -648,6 +650,7 @@ func testConfigSnapshotTerminatingGatewayLBConfig(t testing.T, variant string) *
OnlyPassing: true,
},
},
RequestTimeout: 200 * time.Millisecond,
LoadBalancer: &structs.LoadBalancer{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
Expand Down
120 changes: 120 additions & 0 deletions agent/proxycfg/testing_upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ func setupTestVariationConfigEntriesAndSnapshot(
case "chain-and-router":
case "lb-resolver":
case "register-to-terminating-gateway":
case "redirect-to-lb-node":
case "resolver-with-lb":
case "splitter-overweight":
default:
extraEvents := extraUpdateEvents(t, variation, dbUID)
events = append(events, extraEvents...)
Expand Down Expand Up @@ -580,6 +583,61 @@ func setupTestVariationDiscoveryChain(
},
},
)
case "splitter-overweight":
entries = append(entries,
&structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver,
Name: "db",
EnterpriseMeta: entMeta,
ConnectTimeout: 33 * time.Second,
RequestTimeout: 33 * time.Second,
},
&structs.ProxyConfigEntry{
Kind: structs.ProxyDefaults,
Name: structs.ProxyConfigGlobal,
EnterpriseMeta: entMeta,
Config: map[string]interface{}{
"protocol": "http",
},
},
&structs.ServiceSplitterConfigEntry{
Kind: structs.ServiceSplitter,
Name: "db",
EnterpriseMeta: entMeta,
Splits: []structs.ServiceSplit{
{
Weight: 100.0,
Service: "big-side",
RequestHeaders: &structs.HTTPHeaderModifiers{
Set: map[string]string{"x-split-leg": "big"},
},
ResponseHeaders: &structs.HTTPHeaderModifiers{
Set: map[string]string{"x-split-leg": "big"},
},
},
{
Weight: 100.0,
Service: "goldilocks-side",
RequestHeaders: &structs.HTTPHeaderModifiers{
Set: map[string]string{"x-split-leg": "goldilocks"},
},
ResponseHeaders: &structs.HTTPHeaderModifiers{
Set: map[string]string{"x-split-leg": "goldilocks"},
},
},
{
Weight: 100.0,
Service: "lil-bit-side",
RequestHeaders: &structs.HTTPHeaderModifiers{
Set: map[string]string{"x-split-leg": "small"},
},
ResponseHeaders: &structs.HTTPHeaderModifiers{
Set: map[string]string{"x-split-leg": "small"},
},
},
},
},
)
case "grpc-router":
entries = append(entries,
&structs.ServiceResolverConfigEntry{
Expand Down Expand Up @@ -917,12 +975,74 @@ func setupTestVariationDiscoveryChain(
Field: "header",
FieldValue: "x-user-id",
},
{
Field: "query_parameter",
FieldValue: "my-pretty-param",
},
{
SourceIP: true,
Terminal: true,
},
},
},
})
case "redirect-to-lb-node":
entries = append(entries,
&structs.ProxyConfigEntry{
Kind: structs.ProxyDefaults,
Name: structs.ProxyConfigGlobal,
EnterpriseMeta: entMeta,
Config: map[string]interface{}{
"protocol": "http",
},
},
&structs.ServiceRouterConfigEntry{
Kind: structs.ServiceRouter,
Name: "db",
EnterpriseMeta: entMeta,
Routes: []structs.ServiceRoute{
{
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
PathPrefix: "/web",
}),
Destination: toService("web"),
},
},
},
&structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver,
Name: "web",
EnterpriseMeta: entMeta,
LoadBalancer: &structs.LoadBalancer{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 20,
MaximumRingSize: 30,
},
},
},
)
case "resolver-with-lb":
entries = append(entries,
&structs.ProxyConfigEntry{
Kind: structs.ProxyDefaults,
Name: structs.ProxyConfigGlobal,
EnterpriseMeta: entMeta,
Config: map[string]interface{}{
"protocol": "http",
},
},
&structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver,
Name: "db",
EnterpriseMeta: entMeta,
LoadBalancer: &structs.LoadBalancer{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 20,
MaximumRingSize: 30,
},
},
},
)
default:
Expand Down
7 changes: 5 additions & 2 deletions agent/xds/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,10 @@ func (s *ResourceGenerator) clustersFromSnapshotAPIGateway(cfgSnap *proxycfg.Con
// Grab the discovery chain compiled in handlerAPIGateway.recompileDiscoveryChains
chain, ok := cfgSnap.APIGateway.DiscoveryChain[uid]
if !ok {
// this should not happen
return nil, fmt.Errorf("no discovery chain for upstream %q", uid)
// this should not happen, but it can't error out because the equivalent
// listener generation will continue
s.Logger.Warn("could not find discovery chain for gateway upstream", "upstream", uid)
continue
}

// Generate the list of upstream clusters for the discovery chain
Expand Down Expand Up @@ -2027,6 +2029,7 @@ func (s *ResourceGenerator) getTargetClusterName(upstreamsSnapshot *proxycfg.Con
target := chain.Targets[tid]
clusterName := target.Name
targetUID := proxycfg.NewUpstreamIDFromTargetID(tid)

if targetUID.Peer != "" {
tbs, ok := upstreamsSnapshot.UpstreamPeerTrustBundles.Get(targetUID.Peer)
// We can't generate cluster on peers without the trust bundle. The
Expand Down
6 changes: 4 additions & 2 deletions agent/xds/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ func TestAllResourcesFromSnapshot(t *testing.T) {
},
},
{
name: "transparent-proxy",
create: proxycfg.TestConfigSnapshotTransparentProxy,
name: "transparent-proxy",
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
return proxycfg.TestConfigSnapshotTransparentProxy(t)
},
},
{
name: "connect-proxy-with-peered-upstreams",
Expand Down
Loading

0 comments on commit 0c13388

Please sign in to comment.