|
|
@@ -459,7 +459,7 @@ TEST(MayClaimHostname, TheWriteTimeAnswerAGREESWithTheRegistrysOwnPrecedence) {
|
|
|
// first customer hostname to a project turned gating on service-wide and
|
|
|
// answered the operator's own next request with a 404.
|
|
|
|
|
|
-using svapi::isDirectAddressHost;
|
|
|
+using svapi::isLoopbackAddress;
|
|
|
|
|
|
TEST(HostGating, APROJECTHostnameAloneDoesNOTTurnGatingOn) {
|
|
|
// The defect. An admin adding a customer hostname must not lock themselves
|
|
|
@@ -478,38 +478,40 @@ TEST(HostGating, THEDEPLOYMENTNamingItselfIsWhatTurnsGatingOn) {
|
|
|
EXPECT_FALSE(HostRegistry::build("", {}, {}, nullptr).gating());
|
|
|
}
|
|
|
|
|
|
-TEST(HostGating, ABareAddressOrLocalhostIsTheOPERATORSOwnAccess) {
|
|
|
- // Recovery: without this, setting admin_hostname is a one-way door that can
|
|
|
- // only be undone by editing the database by hand.
|
|
|
- for (const char* h : {"127.0.0.1", "127.0.0.1:8080", "10.0.0.5", "localhost",
|
|
|
- "localhost:8080", "[::1]", "[::1]:8080"}) {
|
|
|
- EXPECT_TRUE(isDirectAddressHost(h)) << h;
|
|
|
- const HostRegistry r = HostRegistry::build("admin.example.com", {}, {}, nullptr);
|
|
|
- EXPECT_EQ(r.resolve(h).kind, HostKind::Admin) << h;
|
|
|
- }
|
|
|
+TEST(HostGating, LoopbackIsRecognisedFromTheCONNECTIONAddress) {
|
|
|
+ // The way back in after a deployment names itself. Keyed on the interface
|
|
|
+ // the connection arrived on, which an outside client cannot forge.
|
|
|
+ for (const char* a : {"127.0.0.1", "127.0.0.53", "::1", "[::1]", "localhost",
|
|
|
+ "::ffff:127.0.0.1"})
|
|
|
+ EXPECT_TRUE(isLoopbackAddress(a)) << a;
|
|
|
}
|
|
|
|
|
|
-TEST(HostGating, ANameIsNOTADirectAddressHoweverNumericItLooks) {
|
|
|
- // THE property that makes the recovery rule safe: it must never be able to
|
|
|
- // shadow a hostname a project registered. A real hostname cannot be all
|
|
|
- // numeric labels, so the two sets are disjoint by construction rather than
|
|
|
- // by the order of a lookup.
|
|
|
- for (const char* h : {"nt.kb.smartbotics.ai", "1.example.com", "123.456.example.com",
|
|
|
- "example.com", "v1.2.3.api.example.com"}) {
|
|
|
- EXPECT_FALSE(isDirectAddressHost(h)) << h;
|
|
|
- }
|
|
|
- // And concretely: a project holding a numeric-looking name still gets it.
|
|
|
- const HostRegistry r = HostRegistry::build(
|
|
|
- "admin.example.com", {}, {{"novitax", {{"1.example.com", PathStyle::Short}}}}, nullptr);
|
|
|
- EXPECT_EQ(r.resolve("1.example.com").project, "novitax")
|
|
|
- << "the direct-address rule shadowed a registered project hostname";
|
|
|
+TEST(HostGating, APUBLICAddressIsNOTLoopback) {
|
|
|
+ // THE test this file exists for now. The previous version of this rule read
|
|
|
+ // the HOST HEADER, so an external client could send `Host: 127.0.0.1` to
|
|
|
+ // the public address and be handed the admin surface - the web UI and the
|
|
|
+ // docs catalogue - on a deployment whose whole point was to serve admin on
|
|
|
+ // one name only.
|
|
|
+ for (const char* a : {"85.155.246.191", "142.93.100.6", "10.0.0.5", "0.0.0.0",
|
|
|
+ "", "127.example.com", "1270.0.0.1", "::2"})
|
|
|
+ EXPECT_FALSE(isLoopbackAddress(a)) << a << " was treated as loopback";
|
|
|
}
|
|
|
|
|
|
-TEST(HostGating, AShortPathOnTheDirectAddressIsStillREFUSED) {
|
|
|
- // The direct address is the ADMIN surface, so rule 4 applies to it exactly
|
|
|
- // as to a named admin host - it is a way back IN, not a way around the
|
|
|
- // tenancy rules.
|
|
|
+TEST(HostGating, TheREGISTRYNoLongerKnowsAboutAddressesAtAll) {
|
|
|
+ // resolve() is exact-match and nothing else now. A bare address resolves to
|
|
|
+ // Unknown like any unregistered name; the loopback exception lives at the
|
|
|
+ // one place that can see the connection, not in the pure lookup.
|
|
|
const HostRegistry r = HostRegistry::build("admin.example.com", {}, {}, nullptr);
|
|
|
- EXPECT_FALSE(resolveProject("", r.resolve("127.0.0.1"), true).ok);
|
|
|
- EXPECT_TRUE(resolveProject("novitax", r.resolve("127.0.0.1"), true).ok);
|
|
|
+ EXPECT_EQ(r.resolve("127.0.0.1").kind, HostKind::Unknown);
|
|
|
+ EXPECT_EQ(r.resolve("localhost").kind, HostKind::Unknown);
|
|
|
+ EXPECT_EQ(r.resolve("admin.example.com").kind, HostKind::Admin);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(HostGating, AShortPathOnTheLoopbackAdminSurfaceIsStillREFUSED) {
|
|
|
+ // Loopback is a way back IN, not a way around the tenancy rules: it yields
|
|
|
+ // the ADMIN binding, and rule 4 applies to that exactly as to a named admin
|
|
|
+ // host.
|
|
|
+ const HostBinding loopbackAdmin{HostKind::Admin, {}, PathStyle::Full};
|
|
|
+ EXPECT_FALSE(resolveProject("", loopbackAdmin, true).ok);
|
|
|
+ EXPECT_TRUE(resolveProject("novitax", loopbackAdmin, true).ok);
|
|
|
}
|