Skip to content

Commit

Permalink
Merge branch 'main' of ssh://github.com/hashicorp/consul
Browse files Browse the repository at this point in the history
  • Loading branch information
im2nguyen committed Jun 12, 2023
2 parents 5732d3b + f8d3721 commit ea673de
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 57 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fmt: $(foreach mod,$(GO_MODULES),fmt/$(mod))
.PHONY: fmt/%
fmt/%:
@echo "--> Running go fmt ($*)"
@cd $* && go fmt ./...
@cd $* && gofmt -s -l -w .

.PHONY: lint
lint: $(foreach mod,$(GO_MODULES),lint/$(mod)) lint-container-test-deps
Expand Down
1 change: 1 addition & 0 deletions agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
Version: stringVal(c.Version),
VersionPrerelease: stringVal(c.VersionPrerelease),
VersionMetadata: stringVal(c.VersionMetadata),
Experiments: c.Experiments,
// What is a sensible default for BuildDate?
BuildDate: timeValWithDefault(c.BuildDate, time.Date(1970, 1, 00, 00, 00, 01, 0, time.UTC)),

Expand Down
1 change: 1 addition & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type Config struct {
EncryptKey *string `mapstructure:"encrypt" json:"encrypt,omitempty"`
EncryptVerifyIncoming *bool `mapstructure:"encrypt_verify_incoming" json:"encrypt_verify_incoming,omitempty"`
EncryptVerifyOutgoing *bool `mapstructure:"encrypt_verify_outgoing" json:"encrypt_verify_outgoing,omitempty"`
Experiments []string `mapstructure:"experiments" json:"experiments,omitempty"`
GossipLAN GossipLANConfig `mapstructure:"gossip_lan" json:"-"`
GossipWAN GossipWANConfig `mapstructure:"gossip_wan" json:"-"`
HTTPConfig HTTPConfig `mapstructure:"http_config" json:"-"`
Expand Down
3 changes: 3 additions & 0 deletions agent/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func DevSource() Source {
ports = {
grpc = 8502
}
experiments = [
"resource-apis"
]
`,
}
}
Expand Down
3 changes: 3 additions & 0 deletions agent/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,9 @@ type RuntimeConfig struct {

Reporting ReportingConfig

// List of experiments to enable
Experiments []string

EnterpriseRuntimeConfig
}

Expand Down
2 changes: 2 additions & 0 deletions agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
rt.DisableAnonymousSignature = true
rt.DisableKeyringFile = true
rt.EnableDebug = true
rt.Experiments = []string{"resource-apis"}
rt.UIConfig.Enabled = true
rt.LeaveOnTerm = false
rt.Logging.LogLevel = "DEBUG"
Expand Down Expand Up @@ -6355,6 +6356,7 @@ func TestLoad_FullConfig(t *testing.T) {
EnableRemoteScriptChecks: true,
EnableLocalScriptChecks: true,
EncryptKey: "A4wELWqH",
Experiments: []string{"foo"},
StaticRuntimeConfig: StaticRuntimeConfig{
EncryptVerifyIncoming: true,
EncryptVerifyOutgoing: true,
Expand Down
1 change: 1 addition & 0 deletions agent/config/testdata/TestRuntimeConfig_Sanitize.golden
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"EnableRemoteScriptChecks": false,
"EncryptKey": "hidden",
"EnterpriseRuntimeConfig": {},
"Experiments": [],
"ExposeMaxPort": 0,
"ExposeMinPort": 0,
"GRPCAddrs": [],
Expand Down
3 changes: 3 additions & 0 deletions agent/config/testdata/full-config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ enable_syslog = true
encrypt = "A4wELWqH"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
experiments = [
"foo"
]
http_config {
block_endpoints = [ "RBvAFcGD", "fWOWFznh" ]
allow_write_http_from = [ "127.0.0.1/8", "22.33.44.55/32", "0.0.0.0/0" ]
Expand Down
17 changes: 10 additions & 7 deletions agent/config/testdata/full-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@
"encrypt": "A4wELWqH",
"encrypt_verify_incoming": true,
"encrypt_verify_outgoing": true,
"experiments": [
"foo"
],
"http_config": {
"block_endpoints": [
"RBvAFcGD",
Expand Down Expand Up @@ -407,17 +410,17 @@
"raft_snapshot_interval": "30s",
"raft_trailing_logs": 83749,
"raft_logstore": {
"backend" : "wal",
"disable_log_cache": true,
"backend": "wal",
"disable_log_cache": true,
"verification": {
"enabled": true,
"interval":"12345s"
"enabled": true,
"interval": "12345s"
},
"boltdb": {
"no_freelist_sync": true
"no_freelist_sync": true
},
"wal": {
"segment_size_mb": 15
"segment_size_mb": 15
}
},
"read_replica": true,
Expand Down Expand Up @@ -927,4 +930,4 @@
"xds": {
"update_max_per_second": 9526.2
}
}
}
2 changes: 2 additions & 0 deletions agent/consul/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Deps struct {
// HCP contains the dependencies required when integrating with the HashiCorp Cloud Platform
HCP hcp.Deps

Experiments []string

EnterpriseDeps
}

Expand Down
16 changes: 11 additions & 5 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import (
raftstorage "github.com/hashicorp/consul/internal/storage/raft"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/lib/routine"
"github.com/hashicorp/consul/lib/stringslice"
"github.com/hashicorp/consul/logging"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/proto/private/pbsubscribe"
Expand Down Expand Up @@ -131,6 +132,8 @@ const (
reconcileChSize = 256

LeaderTransferMinVersion = "1.6.0"

catalogResourceExperimentName = "resource-apis"
)

const (
Expand Down Expand Up @@ -807,7 +810,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
s.internalResourceServiceClient,
logger.Named(logging.ControllerRuntime),
)
s.registerResources()
s.registerResources(flat)
go s.controllerManager.Run(&lib.StopChannelContext{StopCh: shutdownCh})

go s.trackLeaderChanges()
Expand Down Expand Up @@ -858,11 +861,14 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
return s, nil
}

func (s *Server) registerResources() {
catalog.RegisterTypes(s.typeRegistry)
catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies())
func (s *Server) registerResources(deps Deps) {
if stringslice.Contains(deps.Experiments, catalogResourceExperimentName) {
catalog.RegisterTypes(s.typeRegistry)
catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies())

mesh.RegisterTypes(s.typeRegistry)
}

mesh.RegisterTypes(s.typeRegistry)
reaper.RegisterControllers(s.controllerManager)

if s.config.DevMode {
Expand Down
1 change: 1 addition & 0 deletions agent/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
return d, err
}
d.WatchedFiles = result.WatchedFiles
d.Experiments = result.RuntimeConfig.Experiments
cfg := result.RuntimeConfig
logConf := cfg.Logging
logConf.Name = logging.Agent
Expand Down
13 changes: 13 additions & 0 deletions agent/xds/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,19 @@ func getAPIGatewayGoldenTestCases(t *testing.T) []goldenTestCase {
Kind: structs.HTTPRoute,
Name: "route",
Rules: []structs.HTTPRouteRule{{
Filters: structs.HTTPFilters{
Headers: []structs.HTTPHeaderFilter{
{
Add: map[string]string{
"X-Header-Add": "added",
},
Set: map[string]string{
"X-Header-Set": "set",
},
Remove: []string{"X-Header-Remove"},
},
},
},
Services: []structs.HTTPService{{
Name: "service",
}},
Expand Down
12 changes: 0 additions & 12 deletions agent/xds/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,6 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
return nil, err
}

addHeaderFiltersToVirtualHost(&reformatedRoute, virtualHost)

defaultRoute.VirtualHosts = append(defaultRoute.VirtualHosts, virtualHost)
}

Expand Down Expand Up @@ -1097,16 +1095,6 @@ func injectHeaderManipToRoute(dest *structs.ServiceRouteDestination, r *envoy_ro
return nil
}

func addHeaderFiltersToVirtualHost(dest *structs.HTTPRouteConfigEntry, vh *envoy_route_v3.VirtualHost) {
for _, rule := range dest.Rules {
for _, header := range rule.Filters.Headers {
vh.RequestHeadersToAdd = append(vh.RequestHeadersToAdd, makeHeadersValueOptions(header.Add, true)...)
vh.RequestHeadersToAdd = append(vh.RequestHeadersToAdd, makeHeadersValueOptions(header.Set, false)...)
vh.RequestHeadersToRemove = append(vh.RequestHeadersToRemove, header.Remove...)
}
}
}

func injectHeaderManipToVirtualHost(dest *structs.IngressService, vh *envoy_route_v3.VirtualHost) error {
if !dest.RequestHeaders.IsZero() {
vh.RequestHeadersToAdd = append(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
{
"versionInfo": "00000001",
"resources": [
"versionInfo": "00000001",
"resources": [
{
"@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"name": "8080",
"virtualHosts": [
"@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"name": "8080",
"virtualHosts": [
{
"name": "api-gateway-listener-9b9265b",
"domains": [
"name": "api-gateway-listener-9b9265b",
"domains": [
"*",
"*:8080"
],
"routes": [
"routes": [
{
"match": {
"prefix": "/"
"match": {
"prefix": "/"
},
"route": {
"cluster": "service.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
}
"route": {
"cluster": "service.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
},
"requestHeadersToAdd": [
{
"header": {
"key": "X-Header-Add",
"value": "added"
},
"append": true
},
{
"header": {
"key": "X-Header-Set",
"value": "set"
},
"append": false
}
],
"requestHeadersToRemove": [
"X-Header-Remove"
]
}
]
}
],
"validateClusters": true
"validateClusters": true
}
],
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
}
3 changes: 3 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func (c *cmd) run(args []string) int {
ui.Info(fmt.Sprintf(" Gossip Encryption: %t", config.EncryptKey != ""))
ui.Info(fmt.Sprintf(" Auto-Encrypt-TLS: %t", config.AutoEncryptTLS || config.AutoEncryptAllowTLS))
ui.Info(fmt.Sprintf(" ACL Enabled: %t", config.ACLsEnabled))
if config.ServerMode {
ui.Info(fmt.Sprintf(" Reporting Enabled: %t", config.Reporting.License.Enabled))
}
ui.Info(fmt.Sprintf("ACL Default Policy: %s", config.ACLResolverSettings.ACLDefaultPolicy))
ui.Info(fmt.Sprintf(" HTTPS TLS: Verify Incoming: %t, Verify Outgoing: %t, Min Version: %s",
config.TLS.HTTPS.VerifyIncoming, config.TLS.HTTPS.VerifyOutgoing, config.TLS.HTTPS.TLSMinVersion))
Expand Down
1 change: 1 addition & 0 deletions website/content/api-docs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ The corresponding CLI command is [`consul config list`](/consul/commands/config/
### Path Parameters

- `kind` `(string: <required>)` - Specifies the kind of the entry to list.
- `filter` `(string: "")` - Specifies an expression to use for filtering the results.

### Query Parameters

Expand Down
10 changes: 10 additions & 0 deletions website/content/commands/config/list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Usage: `consul config list [options]`
#### Command Options

- `-kind` - Specifies the kind of the config entry to list.
- `-filter` - Specifies an expression to use for filtering the results.

#### Enterprise Options

Expand All @@ -57,7 +58,16 @@ Usage: `consul config list [options]`

## Examples

To list all service-defaults config entries:

$ consul config list -kind service-defaults
billing
db
web

The following lists service-defaults with a filter expression:

$ consul config list -kind service-defaults -filter 'MutualTLSMode == "permissive"'
db
web

6 changes: 6 additions & 0 deletions website/content/docs/connect/config-entries/mesh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ Note that the Kubernetes example does not include a `partition` field. Configura
},
],
},
{
name: 'AllowEnablingPermissiveMutualTLS',
type: 'bool: false',
description:
'Controls whether `MutualTLSMode=permissive` can be set in the `proxy-defaults` and `service-defaults` configuration entries. '
},
{
name: 'TLS',
type: 'TLSConfig: <optional>',
Expand Down
Loading

0 comments on commit ea673de

Please sign in to comment.