Skip to content

Commit 45b8f73

Browse files
authored
Configure internal_address_config on httpConnectionManager (uswitch#89)
* Add internal-cidr-ranges flag, configure internal_address_config on httpConnectionManager * pass internal-cidr-ranges into configurator
1 parent 0274e5b commit 45b8f73

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
----
66
Yggdrasil is an Envoy control plane that configures listeners and clusters based off Kubernetes ingresses from multiple Kube Clusters. This allows you to have an envoy cluster acting as a mutli-cluster loadbalancer for Kubernetes. This was something we needed as we wanted our apps to be highly available in the event of a cluster outage but did not want the solution to live inside of Kubernetes itself.
77

8-
`Note:` Currently we support versions 1.20.x to 1.26.x of Envoy.</br>
8+
`Note:` Currently we support versions 1.20.x to 1.29.x of Envoy.</br>
99
`Note:` Yggdrasil now uses [Go modules](https://github.com/golang/go/wiki/Modules) to handle dependencies.
1010

1111
## Usage

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func init() {
8282
rootCmd.PersistentFlags().String("key", "", "keyfile")
8383
rootCmd.PersistentFlags().String("ca", "", "trustedCA")
8484
rootCmd.PersistentFlags().StringSlice("ingress-classes", nil, "Ingress classes to watch")
85+
rootCmd.PersistentFlags().StringSlice("internal-cidr-ranges", []string{"192.168.0.0/16", "10.0.0.0/8", "172.16.0.0/12"}, "CIDR ranges to treat as internal")
8586
rootCmd.PersistentFlags().StringArrayVar(&kubeConfig, "kube-config", nil, "Path to kube config")
8687
rootCmd.PersistentFlags().Bool("debug", false, "Log at debug level")
8788
rootCmd.PersistentFlags().Bool("config-dump", false, "Enable config dump endpoint at /configdump on the health-address HTTP server")
@@ -115,6 +116,7 @@ func init() {
115116
viper.BindPFlag("healthAddress", rootCmd.PersistentFlags().Lookup("health-address"))
116117
viper.BindPFlag("nodeName", rootCmd.PersistentFlags().Lookup("node-name"))
117118
viper.BindPFlag("ingressClasses", rootCmd.PersistentFlags().Lookup("ingress-classes"))
119+
viper.BindPFlag("internalCidrRanges", rootCmd.PersistentFlags().Lookup("internal-cidr-ranges"))
118120
viper.BindPFlag("cert", rootCmd.PersistentFlags().Lookup("cert"))
119121
viper.BindPFlag("key", rootCmd.PersistentFlags().Lookup("key"))
120122
viper.BindPFlag("trustCA", rootCmd.PersistentFlags().Lookup("ca"))
@@ -231,6 +233,7 @@ func main(*cobra.Command, []string) error {
231233
c.Certificates,
232234
viper.GetString("trustCA"),
233235
viper.GetStringSlice("ingressClasses"),
236+
viper.GetStringSlice("internalCidrRanges"),
234237
envoy.WithUpstreamPort(uint32(viper.GetInt32("upstreamPort"))),
235238
envoy.WithEnvoyListenerIpv4Address(viper.GetString("envoyListenerIpv4Address")),
236239
envoy.WithEnvoyPort(uint32(viper.GetInt32("envoyPort"))),

pkg/envoy/boilerplate.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package envoy
33
import (
44
"fmt"
55
"log"
6+
"strconv"
67
"strings"
78

89
cal "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3"
@@ -286,10 +287,27 @@ func (c *KubernetesConfigurator) makeConnectionManager(virtualHosts []*route.Vir
286287
}
287288
}
288289

290+
internalCidrRanges := make([]*core.CidrRange, len(c.internalCidrRanges))
291+
292+
for idx, cidrRange := range c.internalCidrRanges {
293+
cideRangeParts := strings.SplitN(cidrRange, "/", 2)
294+
prefixLen, err := strconv.ParseInt(cideRangeParts[1], 10, 32)
295+
if err != nil {
296+
return &hcm.HttpConnectionManager{}, err
297+
}
298+
internalCidrRanges[idx] = &core.CidrRange{
299+
AddressPrefix: cideRangeParts[0],
300+
PrefixLen: &wrapperspb.UInt32Value{Value: uint32(prefixLen)},
301+
}
302+
}
303+
289304
return &hcm.HttpConnectionManager{
290305
CodecType: hcm.HttpConnectionManager_AUTO,
291306
StatPrefix: "ingress_http",
292307
HttpFilters: filter,
308+
InternalAddressConfig: &hcm.HttpConnectionManager_InternalAddressConfig{
309+
CidrRanges: internalCidrRanges,
310+
},
293311
UpgradeConfigs: []*hcm.HttpConnectionManager_UpgradeConfig{
294312
{
295313
UpgradeType: "websocket",

pkg/envoy/configurator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type AccessLogger struct {
5454
// KubernetesConfigurator takes a given Ingress Class and lister to find only ingresses of that class
5555
type KubernetesConfigurator struct {
5656
ingressClasses []string
57+
internalCidrRanges []string
5758
nodeID string
5859
syncSecrets bool
5960
certificates []Certificate
@@ -78,8 +79,8 @@ type KubernetesConfigurator struct {
7879
}
7980

8081
// NewKubernetesConfigurator returns a Kubernetes configurator given a lister and ingress class
81-
func NewKubernetesConfigurator(nodeID string, certificates []Certificate, ca string, ingressClasses []string, options ...option) *KubernetesConfigurator {
82-
c := &KubernetesConfigurator{ingressClasses: ingressClasses, nodeID: nodeID, certificates: certificates, trustCA: ca}
82+
func NewKubernetesConfigurator(nodeID string, certificates []Certificate, ca string, ingressClasses []string, internalCidrRanges []string, options ...option) *KubernetesConfigurator {
83+
c := &KubernetesConfigurator{ingressClasses: ingressClasses, nodeID: nodeID, certificates: certificates, trustCA: ca, internalCidrRanges: internalCidrRanges}
8384
for _, opt := range options {
8485
opt(c)
8586
}

pkg/envoy/configurator_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestGenerate(t *testing.T) {
5252

5353
configurator := NewKubernetesConfigurator("a", []Certificate{
5454
{Hosts: []string{"*"}, Cert: "b", Key: "c"},
55-
}, "d", []string{"bar"})
55+
}, "d", []string{"bar"}, []string{"192.168.0.0/16"})
5656

5757
snapshot, _ := configurator.Generate(ingresses, []*v1.Secret{})
5858

@@ -73,7 +73,7 @@ func TestGenerateMultipleCerts(t *testing.T) {
7373
configurator := NewKubernetesConfigurator("a", []Certificate{
7474
{Hosts: []string{"*.internal.api.com"}, Cert: "com", Key: "com"},
7575
{Hosts: []string{"*.internal.api.co.uk"}, Cert: "couk", Key: "couk"},
76-
}, "d", []string{"bar"})
76+
}, "d", []string{"bar"}, []string{"192.168.0.0/16"})
7777

7878
snapshot, err := configurator.Generate(ingresses, []*v1.Secret{})
7979
if err != nil {
@@ -98,7 +98,7 @@ func TestGenerateMultipleHosts(t *testing.T) {
9898

9999
configurator := NewKubernetesConfigurator("a", []Certificate{
100100
{Hosts: []string{"*.internal.api.com", "*.internal.api.co.uk"}, Cert: "com", Key: "com"},
101-
}, "d", []string{"bar"})
101+
}, "d", []string{"bar"}, []string{"192.168.0.0/16"})
102102

103103
snapshot, err := configurator.Generate(ingresses, []*v1.Secret{})
104104
if err != nil {
@@ -123,7 +123,7 @@ func TestGenerateNoMatchingCert(t *testing.T) {
123123

124124
configurator := NewKubernetesConfigurator("a", []Certificate{
125125
{Hosts: []string{"*.internal.api.com"}, Cert: "com", Key: "com"},
126-
}, "d", []string{"bar"})
126+
}, "d", []string{"bar"}, []string{"192.168.0.0/16"})
127127

128128
snapshot, err := configurator.Generate(ingresses, []*v1.Secret{})
129129
if err != nil {
@@ -145,7 +145,7 @@ func TestGenerateIntoTwoCerts(t *testing.T) {
145145
configurator := NewKubernetesConfigurator("a", []Certificate{
146146
{Hosts: []string{"*.internal.api.com"}, Cert: "com", Key: "com"},
147147
{Hosts: []string{"*"}, Cert: "all", Key: "all"},
148-
}, "d", []string{"bar"})
148+
}, "d", []string{"bar"}, []string{"192.168.0.0/16"})
149149

150150
snapshot, err := configurator.Generate(ingresses, []*v1.Secret{})
151151
if err != nil {
@@ -218,7 +218,7 @@ func TestGenerateListeners(t *testing.T) {
218218
}
219219
for _, tc := range testcases {
220220
t.Run(tc.name, func(t *testing.T) {
221-
configurator := NewKubernetesConfigurator("a", tc.certs, "", nil)
221+
configurator := NewKubernetesConfigurator("a", tc.certs, "", nil, []string{})
222222
ret, err := configurator.generateListeners(&envoyConfiguration{VirtualHosts: tc.virtualHost})
223223
if err != nil {
224224
t.Fatalf("Error generating listeners %v", err)

0 commit comments

Comments
 (0)