-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orchestrator: do not use AS names for tenants
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
1 parent
2ed891c
commit 794e57a
Showing
4 changed files
with
119 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
} |