Skip to content

Commit

Permalink
orchestrator: do not use AS names for tenants
Browse files Browse the repository at this point in the history
This was introduced with #1059, but I think this was a mistake. Notably,
it enables erasing the tenants provided by the user.

It also opens the question whetever to have network sources or static
sources override more specific entries or not. This is currently not the
case, but then, if a more specific GeoIP entry appears, it may require
to add a more specific entry if overriding is needed.

This could also be configurable.
  • Loading branch information
vincentbernat committed Apr 27, 2024
1 parent 2ed891c commit 794e57a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 65 deletions.
1 change: 1 addition & 0 deletions console/data/docs/99-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ identified with a specific icon:

## 1.10.2 - 2024-04-27

- 🩹 *orchestrator*: do not use AS names from GeoIP as tenant for networks
- 🩹 *inlet*: fix sampling rate parsing for IPFIX packets using "packet interval"
- 🩹 *inlet*: fix `inlet``metadata``providers``targets` for gNMI provider

Expand Down
63 changes: 0 additions & 63 deletions orchestrator/clickhouse/geoip_test.go

This file was deleted.

3 changes: 1 addition & 2 deletions orchestrator/clickhouse/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func (c *Component) networksCSVRefresher() {
return err
}
attrs := NetworkAttributes{
ASN: data.ASNumber,
Tenant: data.ASName,
ASN: data.ASNumber,
}
return networks.Update(subV6Str, attrs, overrideNetworkAttrs(attrs))
})
Expand Down
117 changes: 117 additions & 0 deletions orchestrator/clickhouse/networks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-FileCopyrightText: 2024 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only

package clickhouse

import (
"testing"

"akvorado/common/clickhousedb"
"akvorado/common/daemon"
"akvorado/common/helpers"
"akvorado/common/httpserver"
"akvorado/common/reporter"
"akvorado/common/schema"
"akvorado/orchestrator/geoip"
)

func TestNetworksCSVWithGeoip(t *testing.T) {
config := DefaultConfiguration()
config.SkipMigrations = true
r := reporter.NewMock(t)
clickHouseComponent := clickhousedb.SetupClickHouse(t, r, false)

{
// First use only GeoIP
c, err := New(r, config, Dependencies{
Daemon: daemon.NewMock(t),
HTTP: httpserver.NewMock(t, r),
Schema: schema.NewMock(t),
GeoIP: geoip.NewMock(t, r, true),
ClickHouse: clickHouseComponent,
})
if err != nil {
t.Fatalf("New() error:\n%+v", err)
}
helpers.StartStop(t, c)

helpers.TestHTTPEndpoints(t, c.d.HTTP.LocalAddr(), helpers.HTTPEndpointCases{
{
Description: "networks.csv",
URL: "/api/v0/orchestrator/clickhouse/networks.csv",
ContentType: "text/csv; charset=utf-8",
FirstLines: []string{
"network,name,role,site,region,country,state,city,tenant,asn",
"1.0.0.0/24,,,,,,,,,15169",
"1.128.0.0/11,,,,,,,,,1221",
"2.19.4.136/30,,,,,SG,,,,32787",
"2.19.4.140/32,,,,,SG,,,,32787",
"2.125.160.216/29,,,,,GB,,,,",
"12.81.92.0/22,,,,,,,,,7018",
"12.81.96.0/19,,,,,,,,,7018",
"12.81.128.0/17,,,,,,,,,7018",
"12.82.0.0/15,,,,,,,,,7018",
"12.84.0.0/14,,,,,,,,,7018",
"12.88.0.0/13,,,,,,,,,7018",
"12.96.0.0/20,,,,,,,,,7018",
"12.96.16.0/24,,,,,,,,,7018",
"15.0.0.0/8,,,,,,,,,71",
"16.0.0.0/8,,,,,,,,,71",
"18.0.0.0/8,,,,,,,,,3",
},
},
})
}

{
// Second use: add custom networks
config.Networks = helpers.MustNewSubnetMap(map[string]NetworkAttributes{
"::ffff:12.80.0.0/112": {Name: "infra"}, // not covered by GeoIP
"::ffff:12.81.96.0/115": {Name: "infra"}, // matching a GeoIP entry
"::ffff:12.81.96.0/120": {Tenant: "Alfred"}, // nested in previous one
"::ffff:14.0.0.0/103": {Tenant: "Alfred"}, // not covered by GeoIP but covers GeoIP entries
})

c, err := New(r, config, Dependencies{
Daemon: daemon.NewMock(t),
HTTP: httpserver.NewMock(t, r),
Schema: schema.NewMock(t),
GeoIP: geoip.NewMock(t, r, true),
ClickHouse: clickHouseComponent,
})
if err != nil {
t.Fatalf("New() error:\n%+v", err)
}
helpers.StartStop(t, c)
helpers.TestHTTPEndpoints(t, c.d.HTTP.LocalAddr(), helpers.HTTPEndpointCases{
{
Description: "networks.csv",
URL: "/api/v0/orchestrator/clickhouse/networks.csv",
ContentType: "text/csv; charset=utf-8",
FirstLines: []string{
"network,name,role,site,region,country,state,city,tenant,asn",
"1.0.0.0/24,,,,,,,,,15169",
"1.128.0.0/11,,,,,,,,,1221",
"2.19.4.136/30,,,,,SG,,,,32787",
"2.19.4.140/32,,,,,SG,,,,32787",
"2.125.160.216/29,,,,,GB,,,,",
"12.80.0.0/16,infra,,,,,,,,", // not covered by GeoIP
"12.81.92.0/22,,,,,,,,,7018",
"12.81.96.0/19,infra,,,,,,,,7018", // matching a GeoIP entry
"12.81.96.0/24,infra,,,,,,,Alfred,7018", // nested in previous one
"12.81.128.0/17,,,,,,,,,7018",
"12.82.0.0/15,,,,,,,,,7018",
"12.84.0.0/14,,,,,,,,,7018",
"12.88.0.0/13,,,,,,,,,7018",
"12.96.0.0/20,,,,,,,,,7018",
"12.96.16.0/24,,,,,,,,,7018",
"14.0.0.0/7,,,,,,,,Alfred,", // not covered by GeoIP
"15.0.0.0/8,,,,,,,,Alfred,71", // but covers GeoIP entries
"16.0.0.0/8,,,,,,,,,71",
"18.0.0.0/8,,,,,,,,,3",
},
},
})
}

}

0 comments on commit 794e57a

Please sign in to comment.