Skip to content

Commit dbedd24

Browse files
authored
Report connection count for communication between a workload in the cluster to a workload outside of the cluster (Internet edge) (#290)
1 parent 83776a9 commit dbedd24

File tree

11 files changed

+600
-425
lines changed

11 files changed

+600
-425
lines changed

src/mapper/pkg/cloudclient/generated.go

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

src/mapper/pkg/cloudclient/schema.graphql

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,21 @@ directive @include(
3232
if: Boolean!
3333
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
3434

35+
"""@noRole indicates that the specified query / mutation / subscription can be executed regardless of the user's roles.
36+
This practically means that the query will not allow accessing any org-specific data."""
37+
directive @noRole on FIELD_DEFINITION
38+
3539
"""@noauth indicates that the specified query / mutation / subscription can be executed anonymously without
40+
user authentication, meaning anyone and everyone can execute it. USE WITH CAUTION.
3641
user authentication, meaning anyone and everyone can execute it. USE WITH CAUTION."""
3742
directive @noauth on FIELD_DEFINITION
3843

44+
"""@requiresRole indicates that the specified query / mutation / subscription requires any of the provided roles to be executed.
45+
Users without any of the specified roles will not be able to execute the query / mutation / subscription."""
46+
directive @requiresRole(
47+
roles: [AuthRole!]!
48+
) on FIELD_DEFINITION
49+
3950
directive @restApiField(
4051
action: ApiFieldAction
4152
) on FIELD_DEFINITION
@@ -275,6 +286,11 @@ type AppliedIntentsRequestWithDetails {
275286
clientIntents: ClientIntentsFileRepresentation!
276287
}
277288

289+
enum AuthRole {
290+
ADMIN
291+
VIEWER
292+
}
293+
278294
enum AutomateThirdPartyNetworkPolicy {
279295
OFF
280296
ALWAYS
@@ -823,6 +839,7 @@ input ExternalTrafficIntentInput {
823839
namespace: String!
824840
clientName: String!
825841
target: DNSIPPairInput!
842+
connectionsCount: ConnectionsCount
826843
}
827844

828845
input ExternallyAccessibleServiceInput {
@@ -1216,6 +1233,7 @@ input InputIntegrationAccessGraphFilter {
12161233
namespaceFilterType: IDFilterOperators
12171234
serviceIds: [ID!]
12181235
serviceFilterType: IDFilterOperators
1236+
targets: [IntentType!]
12191237
}
12201238

12211239
""" Network policies filter """
@@ -1341,6 +1359,7 @@ type IntegrationAccessGraphFilter {
13411359
serviceIds: [ID!]
13421360
serviceFilterType: IDFilterOperators
13431361
lastSeenAfter: Time
1362+
targets: [IntentType!]
13441363
}
13451364

13461365
type IntegrationComponents {
@@ -1458,6 +1477,7 @@ input IntentStatusInput {
14581477
}
14591478

14601479
enum IntentType {
1480+
KUBERNETES
14611481
HTTP
14621482
KAFKA
14631483
DATABASE
@@ -1535,6 +1555,7 @@ type Invite {
15351555
id: ID!
15361556
email: String!
15371557
organization: Organization!
1558+
organizationMembership: OrganizationMembership!
15381559
inviter: User!
15391560
created: Time!
15401561
acceptedAt: Time
@@ -2052,6 +2073,7 @@ type Mutation {
20522073
"""Create user invite"""
20532074
createInvite(
20542075
email: String!
2076+
organizationMembership: OrganizationMembershipInput
20552077
): Invite!
20562078
"""Delete user invite"""
20572079
deleteInvite(
@@ -2105,7 +2127,7 @@ type Mutation {
21052127
settings: OrganizationSettingsInput
21062128
): Organization!
21072129
updateDomainsDefaultRole(
2108-
defaultRole: OrgMembershipRole!
2130+
defaultRole: AuthRole!
21092131
): Organization!
21102132
"""Remove user from organization"""
21112133
removeUserFromOrganization(
@@ -2235,6 +2257,7 @@ input NetworkPolicyInput {
22352257
enum NetworkPolicyKind {
22362258
NETWORK_POLICY
22372259
CILIUM_NETWORK_POLICY
2260+
CILIUM_CLUSTER_WIDE_NETWORK_POLICY
22382261
}
22392262

22402263
enum NetworkPolicyScope {
@@ -2248,11 +2271,6 @@ type NetworkPolicyWorkload {
22482271
service: Service!
22492272
}
22502273

2251-
enum OrgMembershipRole {
2252-
ADMIN
2253-
VIEWER
2254-
}
2255-
22562274
type Organization {
22572275
id: ID!
22582276
name: String!
@@ -2262,19 +2280,45 @@ type Organization {
22622280
created: Time!
22632281
}
22642282

2283+
type OrganizationMembership {
2284+
role: AuthRole!
2285+
restrictions: OrganizationMembershipRestrictions
2286+
}
2287+
2288+
input OrganizationMembershipInput {
2289+
role: AuthRole!
2290+
restrictions: OrganizationMembershipRestrictionsInput
2291+
}
2292+
2293+
type OrganizationMembershipRestrictions {
2294+
clusterIds: IDFilterValue
2295+
serviceIds: IDFilterValue
2296+
namespaceIds: IDFilterValue
2297+
environmentIds: IDFilterValue
2298+
}
2299+
2300+
input OrganizationMembershipRestrictionsInput {
2301+
clusterIds: InputIDFilterValue
2302+
serviceIds: InputIDFilterValue
2303+
namespaceIds: InputIDFilterValue
2304+
environmentIds: InputIDFilterValue
2305+
}
2306+
22652307
type OrganizationSettings {
22662308
domains: [String!]
22672309
enforcedRegulations: [String!]
22682310
ignoredCloudDomains: [String!]
22692311
defaultIntentsApprovalActionByEnv: [DefaultIntentsApprovalActionByEnv!]!
2270-
domainsDefaultRole: OrgMembershipRole!
2312+
ignoreInternetIntents: Boolean
2313+
domainsDefaultRole: AuthRole!
22712314
}
22722315

22732316
input OrganizationSettingsInput {
22742317
domains: [String!]
22752318
enforcedRegulations: [String]
22762319
ignoredCloudDomains: [String!]
22772320
defaultIntentsApprovalActionByEnv: [InputDefaultIntentsApprovalActionByEnv!]
2321+
ignoreInternetIntents: Boolean
22782322
}
22792323

22802324
input PaginationInput {
@@ -2979,6 +3023,7 @@ type User {
29793023
authProviderUserId: String!
29803024
tutorials: [UserTutorial!]
29813025
activeTutorial: UserTutorial!
3026+
orgMembership: OrganizationMembership!
29823027
awsCustomer: AWSCustomer
29833028
}
29843029

src/mapper/pkg/clouduploader/cloud_upload.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/otterize/network-mapper/src/mapper/pkg/externaltrafficholder"
1111
"github.com/otterize/network-mapper/src/mapper/pkg/gcpintentsholder"
1212
"github.com/otterize/network-mapper/src/mapper/pkg/incomingtrafficholder"
13+
"github.com/otterize/nilable"
1314
"time"
1415

1516
"github.com/cenkalti/backoff/v4"
@@ -139,6 +140,9 @@ func (c *CloudUploader) NotifyExternalTrafficIntents(ctx context.Context, intent
139140
for ip := range intent.Intent.IPs {
140141
output.Intent.Target.Ips = append(output.Intent.Target.Ips, lo.ToPtr(string(ip)))
141142
}
143+
144+
output.Intent.ConnectionsCount = nilable.FromPtr(intent.ConnectionsCount)
145+
142146
return output
143147
})
144148

src/mapper/pkg/intentsstore/concurrent_connection_counter.go renamed to src/mapper/pkg/concurrentconnectioncounter/concurrent_connection_counter.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package intentsstore
1+
package concurrentconnectioncounter
22

33
import (
44
"github.com/otterize/network-mapper/src/mapper/pkg/cloudclient"
5-
"github.com/otterize/network-mapper/src/mapper/pkg/graph/model"
65
"github.com/samber/lo"
76
"sync"
87
)
@@ -17,32 +16,32 @@ const (
1716
CountMethodSourcePort CountMethod = 2
1817
)
1918

20-
type CounterInput struct {
21-
Intent model.Intent
19+
type CounterInput[T CountableIntent] struct {
20+
Intent T
2221
SourcePorts []int64
2322
}
2423

25-
type ConnectionCounter struct {
24+
type ConnectionCounter[T CountableIntent] struct {
2625
SourcePorts SourcePortsSet
2726
DNSCounter int
2827
countMethod CountMethod
2928
lock sync.Mutex
3029
}
3130

32-
func NewConnectionCounter() *ConnectionCounter {
33-
return &ConnectionCounter{
31+
func NewConnectionCounter[T CountableIntent]() *ConnectionCounter[T] {
32+
return &ConnectionCounter[T]{
3433
SourcePorts: make(SourcePortsSet),
3534
DNSCounter: 0,
3635
countMethod: CountMethodUnset,
3736
lock: sync.Mutex{},
3837
}
3938
}
4039

41-
func (c *ConnectionCounter) AddConnection(input CounterInput) {
40+
func (c *ConnectionCounter[T]) AddConnection(input CounterInput[T]) {
4241
c.lock.Lock()
4342
defer c.lock.Unlock()
4443

45-
if c.shouldHandleIntentAsSrcPortCount(input.Intent) {
44+
if input.Intent.ShouldCountUsingSrcPortMethod() {
4645
// TCP source port connections wins over DNS (in terms of connections count)
4746
c.countMethod = CountMethodSourcePort
4847
lo.ForEach(input.SourcePorts, func(port int64, _ int) {
@@ -51,7 +50,7 @@ func (c *ConnectionCounter) AddConnection(input CounterInput) {
5150
return
5251
}
5352

54-
if (c.countMethod == CountMethodUnset || c.countMethod == CountMethodDNS) && c.shouldHandleIntentAsDNSCount(input.Intent) {
53+
if (c.countMethod == CountMethodUnset || c.countMethod == CountMethodDNS) && input.Intent.ShouldCountUsingDNSMethod() {
5554
c.countMethod = CountMethodDNS
5655
c.DNSCounter++
5756
return
@@ -61,14 +60,14 @@ func (c *ConnectionCounter) AddConnection(input CounterInput) {
6160
// or because it is an unknown intent type
6261
}
6362

64-
func (c *ConnectionCounter) GetConnectionCount() (int, bool) {
63+
func (c *ConnectionCounter[T]) GetConnectionCount() (int, bool) {
6564
c.lock.Lock()
6665
defer c.lock.Unlock()
6766

6867
return c.getConnectionCountUnsafe()
6968
}
7069

71-
func (c *ConnectionCounter) getConnectionCountUnsafe() (int, bool) {
70+
func (c *ConnectionCounter[T]) getConnectionCountUnsafe() (int, bool) {
7271
if c.countMethod == CountMethodSourcePort {
7372
return len(c.SourcePorts), true
7473
}
@@ -80,18 +79,7 @@ func (c *ConnectionCounter) getConnectionCountUnsafe() (int, bool) {
8079
return 0, false
8180
}
8281

83-
func (c *ConnectionCounter) shouldHandleIntentAsDNSCount(intent model.Intent) bool {
84-
return intent.ResolutionData != nil && *(intent.ResolutionData) == DNSTrafficIntentResolution
85-
}
86-
87-
func (c *ConnectionCounter) shouldHandleIntentAsSrcPortCount(intent model.Intent) bool {
88-
return intent.ResolutionData != nil &&
89-
(*(intent.ResolutionData) == SocketScanServiceIntentResolution ||
90-
*intent.ResolutionData == SocketScanPodIntentResolution ||
91-
*intent.ResolutionData == TCPTrafficIntentResolution)
92-
}
93-
94-
func (c *ConnectionCounter) GetConnectionCountDiff(other *ConnectionCounter) (cloudclient.ConnectionsCount, bool) {
82+
func (c *ConnectionCounter[T]) GetConnectionCountDiff(other *ConnectionCounter[T]) (cloudclient.ConnectionsCount, bool) {
9583
c.lock.Lock()
9684
defer c.lock.Unlock()
9785

0 commit comments

Comments
 (0)