From 35da78715d964eaefebf147e895f0c819388efe1 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Thu, 11 Jan 2024 13:42:43 +0000 Subject: [PATCH] docs: Validate ecosystem keys (#6522) At the moment we have some entries with . chars in their ids, this makes the hugo page look up break, so now these are validated to be sausage-case-values. Signed-off-by: Charlie Egan --- build/policy/integrations.rego | 42 +++++++++++++++++++ build/policy/integrations_test.rego | 42 +++++++++++++++++++ .../content/integrations/asp-dotnet-core.md | 2 +- .../content/integrations/nodejs-express.md | 3 +- .../content/integrations/php-authorization.md | 2 +- .../integrations/springsecurity-api.md | 2 +- .../{build.security.md => build-security.md} | 0 7 files changed, 88 insertions(+), 5 deletions(-) rename docs/website/content/organizations/{build.security.md => build-security.md} (100%) diff --git a/build/policy/integrations.rego b/build/policy/integrations.rego index 6dec6ed882..ff0e70e485 100644 --- a/build/policy/integrations.rego +++ b/build/policy/integrations.rego @@ -6,6 +6,20 @@ import future.keywords.in allowed_image_extensions := ["png", "svg"] +# check that each integration key is valid +deny contains result if { + some path, _ in input.integrations + + id := split(path, "/")[2] + + not regex.match("^([a-z0-9-]+)$", id) + + result := { + "key": "key", + "message": sprintf("integration %s has an invalid key characters, change filename to lowercase and replace spaces with dashes", [id]), + } +} + # check that all integrations have an image deny contains result if { some path, integration in input.integrations @@ -161,6 +175,34 @@ deny contains result if { } } +# check that each organization key is valid +deny contains result if { + some path, _ in input.organizations + + id := split(path, "/")[2] + + not regex.match("^([a-z0-9-]+)$", id) + + result := { + "key": "key", + "message": sprintf("organization %s has an invalid key characters, change filename to lowercase and replace spaces with dashes", [id]), + } +} + +# check that each software key is valid +deny contains result if { + some path, _ in input.softwares + + id := split(path, "/")[2] + + not regex.match("^([a-z0-9-]+)$", id) + + result := { + "key": "key", + "message": sprintf("software %s has an invalid key characters, change filename to lowercase and replace spaces with dashes", [id]), + } +} + # check that each software has at least one integration deny contains result if { some path, software in input.softwares diff --git a/build/policy/integrations_test.rego b/build/policy/integrations_test.rego index f0f9a846c3..d21b331d53 100644 --- a/build/policy/integrations_test.rego +++ b/build/policy/integrations_test.rego @@ -26,6 +26,20 @@ print_if(false, key, expected, output) := false { print("Got:", messages_for_key(key, output)) } +test_integration_has_valid_key { + output := data.integrations.deny with input as {"integrations": {"/integrations/in.valid/": {"link": "https://example.com/", "title": "Example"}}} + + key := "key" + + got := messages_for_key(key, output) + + message := "integration in.valid has an invalid key characters, change filename to lowercase and replace spaces with dashes" + + result := message in got + + print_if(result, key, message, output) +} + test_integration_has_required_fields_missing { output := data.integrations.deny with input as {"integrations": {"/integrations/regal/": {}}} @@ -274,6 +288,20 @@ test_organization_has_required_fields_present { print_if(result, key, false, output) } +test_organization_has_valid_key { + output := data.integrations.deny with input as {"organizations": {"/organizations/sty.ra/": {"link": "https://styra.com/", "title": "Styra"}}} + + key := "key" + + got := messages_for_key(key, output) + + message := "organization sty.ra has an invalid key characters, change filename to lowercase and replace spaces with dashes" + + result := message in got + + print_if(result, key, message, output) +} + test_organization_has_one_or_more_integrations_none { output := data.integrations.deny with input as {"organizations": {"/organizations/foobar/": {}}, "integrations": {}} @@ -332,3 +360,17 @@ test_software_has_one_or_more_integrations_one { print_if(result, key, false, output) } + +test_software_has_valid_key { + output := data.integrations.deny with input as {"softwares": {"/softwares/in.valid/": {"link": "https://example.com/", "title": "Example"}}} + + key := "key" + + got := messages_for_key(key, output) + + message := "software in.valid has an invalid key characters, change filename to lowercase and replace spaces with dashes" + + result := message in got + + print_if(result, key, message, output) +} diff --git a/docs/website/content/integrations/asp-dotnet-core.md b/docs/website/content/integrations/asp-dotnet-core.md index 732056a358..8bc6e772d2 100644 --- a/docs/website/content/integrations/asp-dotnet-core.md +++ b/docs/website/content/integrations/asp-dotnet-core.md @@ -6,7 +6,7 @@ labels: code: - https://github.com/build-security/OPA-AspDotNetCore-Middleware inventors: -- build.security +- build-security --- Use ASP.NET Core to create web apps and services that are fast, secure, cross-platform, and cloud-based. OPA can be used to implement authorization policies for APIs used in the ASP.NET Core framework. diff --git a/docs/website/content/integrations/nodejs-express.md b/docs/website/content/integrations/nodejs-express.md index 09662fdb14..caf88a4d2d 100644 --- a/docs/website/content/integrations/nodejs-express.md +++ b/docs/website/content/integrations/nodejs-express.md @@ -6,7 +6,7 @@ labels: code: - https://github.com/build-security/opa-express-middleware inventors: -- build.security +- build-security software: - nodejsexpress docs_features: @@ -19,4 +19,3 @@ docs_features: --- Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. OPA can be used to implement authorization policies for APIs used in the express framework. - diff --git a/docs/website/content/integrations/php-authorization.md b/docs/website/content/integrations/php-authorization.md index 18aa117239..cbab51680a 100644 --- a/docs/website/content/integrations/php-authorization.md +++ b/docs/website/content/integrations/php-authorization.md @@ -12,7 +12,7 @@ code: - https://github.com/segrax/openpolicyagent - https://github.com/build-security/opa-symfony-middleware inventors: -- build.security +- build-security docs_features: rest-api-integration: note: | diff --git a/docs/website/content/integrations/springsecurity-api.md b/docs/website/content/integrations/springsecurity-api.md index d79c1aee86..5edb7873f6 100644 --- a/docs/website/content/integrations/springsecurity-api.md +++ b/docs/website/content/integrations/springsecurity-api.md @@ -17,7 +17,7 @@ tutorials: - https://www.baeldung.com/spring-security-authorization-opa inventors: - styra -- build.security +- build-security - bisnode - alertavert docs_features: diff --git a/docs/website/content/organizations/build.security.md b/docs/website/content/organizations/build-security.md similarity index 100% rename from docs/website/content/organizations/build.security.md rename to docs/website/content/organizations/build-security.md