Skip to content

Commit 174ba0e

Browse files
authored
Merge pull request #10019 from monicagangwar/master
[calico] awsSrcDstCheck to disable src/dest checks in AWS
2 parents 9dc4288 + a63ccd5 commit 174ba0e

File tree

11 files changed

+89
-6
lines changed

11 files changed

+89
-6
lines changed

docs/networking/calico.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ To enable this mode in a cluster, add the following to the cluster spec:
5555
calico:
5656
crossSubnet: true
5757
```
58-
5958
In the case of AWS, EC2 instances have source/destination checks enabled by default.
60-
When you enable cross-subnet mode in kops, an addon controller ([k8s-ec2-srcdst](https://github.com/ottoyiu/k8s-ec2-srcdst))
59+
When you enable cross-subnet mode in kops 1.19+, it is equivalent to:
60+
```yaml
61+
networking:
62+
calico:
63+
awsSrcDstCheck: Disable
64+
IPIPMode: CrossSubnet
65+
```
66+
An IAM policy will be added to all nodes to allow Calico to execute `ec2:DescribeInstances` and `ec2:ModifyNetworkInterfaceAttribute`, as required when [awsSrcDstCheck](https://docs.projectcalico.org/reference/resources/felixconfig#spec) is set.
67+
For older versions of kops, an addon controller ([k8s-ec2-srcdst](https://github.com/ottoyiu/k8s-ec2-srcdst))
6168
will be deployed as a Pod (which will be scheduled on one of the masters) to facilitate the disabling of said source/destination address checks.
62-
Only the masters have the IAM policy (`ec2:*`) to allow k8s-ec2-srcdst to execute `ec2:ModifyInstanceAttribute`.
69+
Only the control plane nodes have an IAM policy to allow k8s-ec2-srcdst to execute `ec2:ModifyInstanceAttribute`.
6370

6471
### Configuring Calico MTU
6572

k8s/crds/kops.k8s.io_clusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,9 @@ spec:
21222122
calico:
21232123
description: CalicoNetworkingSpec declares that we want Calico networking
21242124
properties:
2125+
awsSrcDstCheck:
2126+
description: 'AwsSrcDstCheck enables/disables source/destination checks (AWS only) Options: "DoNothing" (default) , "Enable" or "Disable"'
2127+
type: string
21252128
chainInsertMode:
21262129
description: 'ChainInsertMode controls whether Felix inserts rules to the top of iptables chains, or appends to the bottom. Leaving the default option is safest to prevent accidentally breaking connectivity. Default: ''insert'' (other options: ''append'')'
21272130
type: string

pkg/apis/kops/networking.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ type CalicoNetworkingSpec struct {
108108
CPURequest *resource.Quantity `json:"cpuRequest,omitempty"`
109109
// CrossSubnet enables Calico's cross-subnet mode when set to true
110110
CrossSubnet bool `json:"crossSubnet,omitempty"`
111+
// AwsSrcDstCheck enables/disables source/destination checks (AWS only)
112+
// Options: "DoNothing" (default) , "Enable" or "Disable"
113+
AwsSrcDstCheck string `json:"awsSrcDstCheck,omitempty"`
111114
// LogSeverityScreen lets us set the desired log level. (Default: info)
112115
LogSeverityScreen string `json:"logSeverityScreen,omitempty"`
113116
// MTU to be set in the cni-network-config for calico.

pkg/apis/kops/v1alpha2/networking.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ type CalicoNetworkingSpec struct {
108108
CPURequest *resource.Quantity `json:"cpuRequest,omitempty"`
109109
// CrossSubnet enables Calico's cross-subnet mode when set to true
110110
CrossSubnet bool `json:"crossSubnet,omitempty"`
111+
// AwsSrcDstCheck enables/disables source/destination checks (AWS only)
112+
// Options: "DoNothing" (default) , "Enable" or "Disable"
113+
AwsSrcDstCheck string `json:"awsSrcDstCheck,omitempty"`
111114
// LogSeverityScreen lets us set the desired log level. (Default: info)
112115
LogSeverityScreen string `json:"logSeverityScreen,omitempty"`
113116
// MTU to be set in the cni-network-config for calico.

pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/validation/validation.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,11 @@ func validateNetworkingCalico(v *kops.CalicoNetworkingSpec, e kops.EtcdClusterSp
966966
allErrs = append(allErrs, IsValidValue(fldPath.Child("chainInsertMode"), &v.ChainInsertMode, valid)...)
967967
}
968968

969+
if v.AwsSrcDstCheck != "" {
970+
valid := []string{"Enable", "Disable", "DoNothing"}
971+
allErrs = append(allErrs, IsValidValue(fldPath.Child("awsSrcDstCheck"), &v.AwsSrcDstCheck, valid)...)
972+
}
973+
969974
if v.IptablesBackend != "" {
970975
valid := []string{"Auto", "Legacy", "NFT"}
971976
allErrs = append(allErrs, IsValidValue(fldPath.Child("iptablesBackend"), &v.IptablesBackend, valid)...)

pkg/apis/kops/validation/validation_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,39 @@ func Test_Validate_Calico(t *testing.T) {
516516
},
517517
ExpectedErrors: []string{"Invalid value::calico.ipv4AutoDetectionMethod"},
518518
},
519+
{
520+
Input: caliInput{
521+
Calico: &kops.CalicoNetworkingSpec{
522+
AwsSrcDstCheck: "off",
523+
},
524+
Etcd: kops.EtcdClusterSpec{},
525+
},
526+
ExpectedErrors: []string{"Unsupported value::calico.awsSrcDstCheck"},
527+
},
528+
{
529+
Input: caliInput{
530+
Calico: &kops.CalicoNetworkingSpec{
531+
AwsSrcDstCheck: "Enable",
532+
},
533+
Etcd: kops.EtcdClusterSpec{},
534+
},
535+
},
536+
{
537+
Input: caliInput{
538+
Calico: &kops.CalicoNetworkingSpec{
539+
AwsSrcDstCheck: "Disable",
540+
},
541+
Etcd: kops.EtcdClusterSpec{},
542+
},
543+
},
544+
{
545+
Input: caliInput{
546+
Calico: &kops.CalicoNetworkingSpec{
547+
AwsSrcDstCheck: "DoNothing",
548+
},
549+
Etcd: kops.EtcdClusterSpec{},
550+
},
551+
},
519552
}
520553
for _, g := range grid {
521554
errs := validateNetworkingCalico(g.Input.Calico, g.Input.Etcd, field.NewPath("calico"))

pkg/model/iam/iam_builder.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ func (r *NodeRoleMaster) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
275275
addCiliumEniPermissions(p, resource, b.Cluster.Spec.IAM.Legacy)
276276
}
277277

278+
if b.Cluster.Spec.Networking != nil && b.Cluster.Spec.Networking.Calico != nil && b.Cluster.Spec.Networking.Calico.AwsSrcDstCheck != "" {
279+
addCalicoSrcDstCheckPermissions(p)
280+
}
281+
278282
return p, nil
279283
}
280284

@@ -310,6 +314,10 @@ func (r *NodeRoleNode) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
310314
addLyftVPCPermissions(p, resource, b.Cluster.Spec.IAM.Legacy, b.Cluster.GetName())
311315
}
312316

317+
if b.Cluster.Spec.Networking != nil && b.Cluster.Spec.Networking.Calico != nil && b.Cluster.Spec.Networking.Calico.AwsSrcDstCheck != "" {
318+
addCalicoSrcDstCheckPermissions(p)
319+
}
320+
313321
return p, nil
314322
}
315323

@@ -667,6 +675,17 @@ func addECRPermissions(p *Policy) {
667675
})
668676
}
669677

678+
func addCalicoSrcDstCheckPermissions(p *Policy) {
679+
p.Statement = append(p.Statement, &Statement{
680+
Effect: StatementEffectAllow,
681+
Action: stringorslice.Of(
682+
"ec2:DescribeInstances",
683+
"ec2:ModifyNetworkInterfaceAttribute",
684+
),
685+
Resource: stringorslice.Slice([]string{"*"}),
686+
})
687+
}
688+
670689
// addLegacyDNSControllerPermissions adds legacy IAM permissions used by the node roles.
671690
func addLegacyDNSControllerPermissions(b *PolicyBuilder, p *Policy) {
672691
// Legacy IAM permissions for node roles

upup/models/bindata.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

upup/models/cloudup/resources/addons/networking.projectcalico.org/k8s-1.16.yaml.template

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3893,6 +3893,9 @@ spec:
38933893
# Enable Prometheus process metrics collection
38943894
- name: FELIX_PROMETHEUSPROCESSMETRICSENABLED
38953895
value: "{{- or .Networking.Calico.PrometheusProcessMetricsEnabled "true" }}"
3896+
# Enable / Disable source/destination checks in AWS
3897+
- name: FELIX_AWSSRCDSTCHECK
3898+
value: "{{- if and (eq .CloudProvider "aws") (.Networking.Calico.CrossSubnet) -}}Disable{{- else -}} {{- or .Networking.Calico.AwsSrcDstCheck "DoNothing" -}} {{- end -}}"
38963899
securityContext:
38973900
privileged: true
38983901
resources:
@@ -4062,6 +4065,7 @@ metadata:
40624065
# pod) may not match the receiving machine's address.
40634066
#
40644067
# This only applies for AWS environments.
4068+
# This is a deprecated setting, use awsSrcDstCheck instead
40654069
---
40664070

40674071
kind: ClusterRole
@@ -4119,7 +4123,7 @@ metadata:
41194123
k8s-app: k8s-ec2-srcdst
41204124
role.kubernetes.io/networking: "1"
41214125
spec:
4122-
replicas: 1
4126+
replicas: 0
41234127
selector:
41244128
matchLabels:
41254129
k8s-app: k8s-ec2-srcdst

0 commit comments

Comments
 (0)