@@ -44,40 +44,40 @@ Pod to pod via Kubernetes service
44
44
picked up by ebpf as 10.32.0.16:47600->10.105.173.176:5432 and 10.32.0.6:5432 (??)
45
45
NAT IPS_DST_NAT orig: 10.32.0.16:47600->10.105.173.176:5432, reply: 10.32.0.6:5432->10.32.0.16:47600
46
46
We want: 10.32.0.16:47600->10.32.0.6:5432
47
- - replace the destination (== NAT orig dst) with the NAT reply source
47
+ - replace the destination (== NAT orig dst) with the NAT reply source (A)
48
48
49
49
Incoming from outside the cluster to a NodePort:
50
50
picked up by ebpf as 10.32.0.1:13488->10.32.0.7:80
51
51
NAT: IPS_SRC_NAT IPS_DST_NAT orig: 37.157.33.76:13488->172.31.2.17:30081, reply: 10.32.0.7:80->10.32.0.1:13488
52
52
We want: 37.157.33.76:13488->10.32.0.7:80
53
- - replace the source (== NAT reply dst) with the NAT original source
53
+ - replace the source (== NAT reply dst) with the NAT original source (B)
54
54
To match another probe with the other side of this connection, also want 37.157.33.76:13488->172.31.2.17:30081
55
- - add NAT original dst as a copy of nat reply dst
55
+ - add NAT original dst as a copy of nat reply source (C)
56
56
57
57
Outgoing from a pod:
58
58
picked up by ebpf as 10.32.0.7:36078->18.221.99.178:443
59
59
NAT: IPS_SRC_NAT orig: 10.32.0.7:36078->18.221.99.178:443, reply: 18.221.99.178:443->172.31.2.17:36078
60
60
We want: 10.32.0.7:36078->18.221.99.178:443
61
- - leave it alone.
61
+ - leave it alone. (D)
62
62
63
63
Docker container exposing port to similar on different host
64
64
host1:
65
65
picked up by ebpf as ip-172-31-5-80;172.17.0.2:43042->172.31.2.17:8080
66
66
NAT: IPS_SRC_NAT orig: 172.17.0.2:43042->172.31.2.17:8080, reply: 172.31.2.17:8080-> 172.31.5.80:43042
67
67
We want: 172.31.5.80:43042->172.31.2.17:8080
68
- - can't have a blanket rule to replace NAT original source with NAT reply destination, because that breaks the "Outgoing from a pod" case
69
- we could add 172.31.5.80:43042 (nat reply destination) as a copy of ip-172-31-5-80;172.17.0.2:43042 (nat orig source)
68
+ - can't have a blanket rule to replace NAT original source with NAT reply destination, because that breaks case D.
69
+ we could add 172.31.5.80:43042 (nat reply destination) as a copy of ip-172-31-5-80;172.17.0.2:43042 (nat orig source) (E)
70
70
host2:
71
71
picked up by ebpf as 172.31.5.80:43042->ip-172-31-2-17;172.17.0.2:80
72
72
NAT: IPS_DST_NAT orig: 172.31.5.80:43042->172.31.2.17:8080, reply: 172.17.0.2:80->172.31.5.80:43042
73
73
Ideally we might want: ip-172-31-5-80;172.17.0.2:43042->ip-172-31-2-17;172.17.0.2:80
74
- we could add 172.31.2.17:8080 (nat original destination) as a copy of ip-172-31-2-17;172.17.0.2:80 (nat reply source)
74
+ we could add 172.31.2.17:8080 (nat original destination) as a copy of ip-172-31-2-17;172.17.0.2:80 (nat reply source) (F)
75
75
76
76
All of the above can be satisfied by these rules:
77
- For SRC_NAT either add NAT orig source as a copy of NAT reply destination
78
- or add NAT reply destination as a copy of NAT original source
79
- For DST_NAT replace NAT original destination in adjacencies with the NAT reply source
80
- or add nat original destination as a copy of nat reply source
77
+ For SRC_NAT either add NAT original destination as a copy of NAT reply source (C)
78
+ or add NAT reply destination as a copy of NAT original source (E)
79
+ For DST_NAT replace NAT original destination in adjacencies with the NAT reply source (A),(B)
80
+ or add nat original destination as a copy of nat reply source (F)
81
81
*/
82
82
83
83
// applyNAT modifies Nodes in the endpoint topology of a report, based on
@@ -89,14 +89,15 @@ func (n natMapper) applyNAT(rpt report.Report, scope string) {
89
89
replyDstID := endpointNodeID (scope , f .Reply .Dst , f .Reply .DstPort )
90
90
origSrcID := endpointNodeID (scope , f .Orig .Src , f .Orig .SrcPort )
91
91
if replyDstID != origSrcID {
92
- // either add NAT orig source as a copy of NAT reply destination
92
+ // either add NAT original destination as a copy of NAT reply destination (C)
93
93
if replyDstNode , ok := rpt .Endpoint .Nodes [replyDstID ]; ok {
94
- newNode := replyDstNode .WithID (origSrcID ).WithLatests (map [string ]string {
94
+ origDstID := endpointNodeID (scope , f .Orig .Dst , f .Orig .DstPort )
95
+ newNode := replyDstNode .WithID (origDstID ).WithLatests (map [string ]string {
95
96
CopyOf : replyDstID ,
96
97
})
97
98
rpt .Endpoint .AddNode (newNode )
98
99
} else if origSrcNode , ok := rpt .Endpoint .Nodes [origSrcID ]; ok {
99
- // or add NAT reply destination as a copy of NAT original source
100
+ // or add NAT reply destination as a copy of NAT original source (E)
100
101
newNode := origSrcNode .WithID (replyDstID ).WithLatests (map [string ]string {
101
102
CopyOf : origSrcID ,
102
103
})
@@ -116,12 +117,12 @@ func (n natMapper) applyNAT(rpt report.Report, scope string) {
116
117
}
117
118
118
119
if fromNode .Adjacency .Contains (origDstID ) {
119
- // replace destination with reply source
120
+ // replace destination with reply source (A),(B)
120
121
fromNode .Adjacency = fromNode .Adjacency .Minus (origDstID )
121
122
fromNode = fromNode .WithAdjacent (replySrcID )
122
123
rpt .Endpoint .Nodes [fromID ] = fromNode
123
124
} else {
124
- // add nat original destination as a copy of nat reply source
125
+ // add nat original destination as a copy of nat reply source (F)
125
126
replySrcNode , ok := rpt .Endpoint .Nodes [replySrcID ]
126
127
if ! ok {
127
128
replySrcNode = report .MakeNode (replySrcID )
0 commit comments