|
@@ -1303,6 +1303,108 @@ std::string projSettingsPath(const std::string& project) {
|
|
|
}
|
|
}
|
|
|
} // namespace
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
+// --- network egress: an ADMIN-ONLY control on the FUNCTIONS route -----------
|
|
|
|
|
+//
|
|
|
|
|
+// These exist because the write landed in the wrong handler and shipped that
|
|
|
|
|
+// way. The embeddings PUT is requireProjectManage, the functions PUT is
|
|
|
|
|
+// requireAdmin, so the block being in the first one meant the control was
|
|
|
|
|
+// ignored on its documented route AND writable by a non-admin - which would
|
|
|
|
|
+// have let a project-manage key undo an admin's `deny`. Acceptance caught it on
|
|
|
|
|
+// prod; nothing in the suite did, because no test exercised the route.
|
|
|
|
|
+
|
|
|
|
|
+namespace {
|
|
|
|
|
+std::string fnSettingsPath(const std::string& project) {
|
|
|
|
|
+ return "/api/v1/projects/" + project + "/settings/functions";
|
|
|
|
|
+}
|
|
|
|
|
+} // namespace
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, NetworkEgressDefaultsToAllowAndSaysItIsNotSet) {
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ auto r = c.Get(fnSettingsPath(project_).c_str());
|
|
|
|
|
+ ASSERT_EQ(r->status, 200);
|
|
|
|
|
+ auto j = nlohmann::json::parse(r->body);
|
|
|
|
|
+ EXPECT_EQ(j["network_egress"], "allow");
|
|
|
|
|
+ EXPECT_FALSE(j["network_egress_set"].get<bool>());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, NetworkEgressDenyActuallyPersistsOnTheFunctionsRoute) {
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ auto put = c.Put(fnSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"network_egress", "deny"}}.dump(), "application/json");
|
|
|
|
|
+ ASSERT_EQ(put->status, 200) << put->body;
|
|
|
|
|
+ // The PUT's own response must already show it - it returned "allow" while
|
|
|
|
|
+ // silently discarding the write, which is how this got to prod.
|
|
|
|
|
+ auto pj = nlohmann::json::parse(put->body);
|
|
|
|
|
+ EXPECT_EQ(pj["network_egress"], "deny") << put->body;
|
|
|
|
|
+ EXPECT_TRUE(pj["network_egress_set"].get<bool>());
|
|
|
|
|
+ // And it must still be there on a fresh read.
|
|
|
|
|
+ auto j = nlohmann::json::parse(c.Get(fnSettingsPath(project_).c_str())->body);
|
|
|
|
|
+ EXPECT_EQ(j["network_egress"], "deny");
|
|
|
|
|
+ EXPECT_TRUE(j["network_egress_set"].get<bool>());
|
|
|
|
|
+
|
|
|
|
|
+ // null clears it back to inherit.
|
|
|
|
|
+ ASSERT_EQ(c.Put(fnSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"network_egress", nullptr}}.dump(),
|
|
|
|
|
+ "application/json")->status, 200);
|
|
|
|
|
+ auto j2 = nlohmann::json::parse(c.Get(fnSettingsPath(project_).c_str())->body);
|
|
|
|
|
+ EXPECT_EQ(j2["network_egress"], "allow");
|
|
|
|
|
+ EXPECT_FALSE(j2["network_egress_set"].get<bool>());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, NetworkEgressRejectsAValueItDoesNotUnderstand) {
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ auto r = c.Put(fnSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"network_egress", "maybe"}}.dump(), "application/json");
|
|
|
|
|
+ // 200 here means the key was ignored, which is exactly the failure that
|
|
|
|
|
+ // shipped: a typo in an admin-only control must not look like it applied.
|
|
|
|
|
+ EXPECT_EQ(r->status, 422) << r->body;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, TheEmbeddingsRouteCannotTouchNetworkEgress) {
|
|
|
|
|
+ // The security half. The embeddings route is project-manage, so if it
|
|
|
|
|
+ // honoured this key a tenant could re-enable egress an admin had denied.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ ASSERT_EQ(c.Put(fnSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"network_egress", "deny"}}.dump(),
|
|
|
|
|
+ "application/json")->status, 200);
|
|
|
|
|
+
|
|
|
|
|
+ auto put = c.Put(projSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"network_egress", "allow"},
|
|
|
|
|
+ {"default_embedding_model", "text-embedding-3-large"}}
|
|
|
|
|
+ .dump(),
|
|
|
|
|
+ "application/json");
|
|
|
|
|
+ ASSERT_EQ(put->status, 200) << put->body;
|
|
|
|
|
+
|
|
|
|
|
+ // The embedding override applied; the egress key was ignored, and the
|
|
|
|
|
+ // admin's deny SURVIVED rather than being overwritten.
|
|
|
|
|
+ auto j = nlohmann::json::parse(c.Get(fnSettingsPath(project_).c_str())->body);
|
|
|
|
|
+ EXPECT_EQ(j["network_egress"], "deny") << "the embeddings route overwrote an admin-only control";
|
|
|
|
|
+ EXPECT_TRUE(j["network_egress_set"].get<bool>());
|
|
|
|
|
+
|
|
|
|
|
+ c.Put(fnSettingsPath(project_).c_str(), nlohmann::json{{"network_egress", nullptr}}.dump(),
|
|
|
|
|
+ "application/json");
|
|
|
|
|
+ c.Delete(projSettingsPath(project_).c_str());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, ClearingAnEmbeddingOverrideDoesNotDropNetworkEgress) {
|
|
|
|
|
+ // DELETE /settings/embeddings clears the EMBEDDING fields only. It used to
|
|
|
|
|
+ // delete the whole document, which silently dropped a function policy; the
|
|
|
|
|
+ // egress switch lives in the same document and must survive too.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ ASSERT_EQ(c.Put(fnSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"network_egress", "deny"}}.dump(),
|
|
|
|
|
+ "application/json")->status, 200);
|
|
|
|
|
+ ASSERT_EQ(c.Put(projSettingsPath(project_).c_str(),
|
|
|
|
|
+ nlohmann::json{{"default_embedding_model", "text-embedding-3-large"}}.dump(),
|
|
|
|
|
+ "application/json")->status, 200);
|
|
|
|
|
+ ASSERT_EQ(c.Delete(projSettingsPath(project_).c_str())->status, 200);
|
|
|
|
|
+
|
|
|
|
|
+ auto j = nlohmann::json::parse(c.Get(fnSettingsPath(project_).c_str())->body);
|
|
|
|
|
+ EXPECT_EQ(j["network_egress"], "deny") << "clearing embeddings took the egress setting with it";
|
|
|
|
|
+ c.Put(fnSettingsPath(project_).c_str(), nlohmann::json{{"network_egress", nullptr}}.dump(),
|
|
|
|
|
+ "application/json");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST_F(ApiFixture, ProjectSettingsDefaultToInherited) {
|
|
TEST_F(ApiFixture, ProjectSettingsDefaultToInherited) {
|
|
|
auto c = admin();
|
|
auto c = admin();
|
|
|
auto r = c.Get(projSettingsPath(project_).c_str());
|
|
auto r = c.Get(projSettingsPath(project_).c_str());
|