generated from falcosecurity/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(decl/loader): add validator leveraging JSON schema
Signed-off-by: Leonardo Di Giovanna <[email protected]> Co-authored-by: Aldo Lacuku <[email protected]>
- Loading branch information
Showing
41 changed files
with
2,363 additions
and
0 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 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,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (C) 2024 The Falco Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package schema provides validation for the loaded tests description leveraging JSON schemas. | ||
package schema |
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,11 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "binding.schema.json", | ||
"title": "Field binding", | ||
"description": "A field binding allows to bind a value in a test step's field with the value in a preceding test resource/step's field. The syntax requires to specify the name of the source resource/step followed by a '.' and the relative path to the source resource/step's field", | ||
"examples": [ | ||
"${resourceA.fieldX}", | ||
"${stepA.fieldY.subFieldZ}" | ||
], | ||
"pattern": "\\${.+}" | ||
} |
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,94 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "context.schema.json", | ||
"title": "Test context", | ||
"description": "The test context allowing to specify process chain details. It can be used to run the test under a specific (even containerized) process chain", | ||
"type": "object", | ||
"properties": { | ||
"container": { | ||
"description": "The container context containing information regarding the container that will run a test", | ||
"type": "object", | ||
"properties": { | ||
"image": { | ||
"description": "The name the base event-generator image must be tagged with before being used to spawn the container", | ||
"type": "string", | ||
"default": "docker.io/falcosecurity/event-generator:latest", | ||
"minLength": 1 | ||
}, | ||
"name": { | ||
"description": "The name that must be used to identify the running container", | ||
"type": "string", | ||
"default": "event-generator", | ||
"minLength": 1 | ||
}, | ||
"env": { | ||
"description": "The set of environment variables that must be provided to the container (in addition to the default ones)", | ||
"type": "object", | ||
"minProperties": 1, | ||
"additionalProperties": { | ||
"description": "An environment variable in the form KEY=VALUE", | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
} | ||
} | ||
}, | ||
"processes": { | ||
"description": "The list of process contexts", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"description": "The process context containing information regarding the process that will run a test, or information about one of its ancestors", | ||
"type": "object", | ||
"properties": { | ||
"exePath": { | ||
"description": "The executable path", | ||
"type": "string", | ||
"default": "/tmp/event-generator<X>, where X is a randomly generated sequence", | ||
"minLength": 1 | ||
}, | ||
"args": { | ||
"description": "A string containing the space-separated list of command line arguments. If a single argument contains spaces, the entire argument must be quoted in order to not be considered as multiple arguments", | ||
"type": "string", | ||
"default": "", | ||
"minLength": 1 | ||
}, | ||
"exe": { | ||
"description": "The argument in position 0 (a.k.a. argv[0]) of the process", | ||
"type": "string", | ||
"default": "The name if this is specified; otherwise, filepath.Base(exePath)", | ||
"minLength": 1 | ||
}, | ||
"name": { | ||
"description": "The process name", | ||
"type": "string", | ||
"default": "filepath.Base(exePath)", | ||
"minLength": 1 | ||
}, | ||
"env": { | ||
"description": "The set of environment variables that must be provided to the process (in addition to the default ones)", | ||
"type": "object", | ||
"minProperties": 1, | ||
"additionalProperties": { | ||
"description": "An environment variable in the form KEY=VALUE", | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"user": { | ||
"description": "The name of the user that must run the process. If the user does not exist, it is created before running the test and deleted after test execution", | ||
"type": "string", | ||
"default": "The current process user", | ||
"minLength": 1 | ||
}, | ||
"capabilities": { | ||
"description": "The capabilities of the process. The syntax follows the conventions specified by cap_from_text(3)", | ||
"type": "string", | ||
"default": "all=iep", | ||
"minLength": 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
pkg/test/loader/schema/jsonschemas/description.schema.json
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,17 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "description.schema.json", | ||
"title": "Tests description", | ||
"description": "The tests description", | ||
"type": "object", | ||
"properties": { | ||
"tests": { | ||
"description": "The list of tests to run", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"$ref": "test.schema.json" | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
pkg/test/loader/schema/jsonschemas/expectedOutcome.schema.json
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,37 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "expectedOutcome.schema.json", | ||
"title": "Test expected outcome", | ||
"description": "The outcome expected from Falco as a result of the test execution", | ||
"type": "object", | ||
"source": { | ||
"description": "The Falco event source", | ||
"type": "string", | ||
"minLength": 1, | ||
"examples": [ | ||
"syscall" | ||
] | ||
}, | ||
"hostname": { | ||
"description": "The Falco event hostname", | ||
"type": "string", | ||
"minLength": 1 | ||
}, | ||
"priority": { | ||
"description": "The Falco event priority", | ||
"type": "string", | ||
"minLength": 1, | ||
"examples": [ | ||
"WARNING" | ||
] | ||
}, | ||
"outputFields": { | ||
"description": "The output fields attached to the Falco event", | ||
"type": "object", | ||
"minProperties": 1, | ||
"additionalProperties": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
} | ||
} |
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,71 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "resource.schema.json", | ||
"title": "Test resource", | ||
"description": "A test resource creates one or more system resource and exposes some of their information as bindable fields", | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"description": "The test resource type", | ||
"type": "string", | ||
"enum": [ | ||
"clientServer", | ||
"fd", | ||
"process" | ||
], | ||
"examples": [ | ||
"clientServer" | ||
] | ||
}, | ||
"name": { | ||
"description": "The test resource name", | ||
"type": "string", | ||
"minLength": 1, | ||
"examples": [ | ||
"clientServer1" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"type", | ||
"name" | ||
], | ||
"allOf": [ | ||
{ | ||
"if": { | ||
"properties": { | ||
"type": { | ||
"const": "clientServer" | ||
} | ||
} | ||
}, | ||
"then": { | ||
"$ref": "resources.clientServer.schema.json" | ||
} | ||
}, | ||
{ | ||
"if": { | ||
"properties": { | ||
"type": { | ||
"const": "fd" | ||
} | ||
} | ||
}, | ||
"then": { | ||
"$ref": "resources.fd.schema.json" | ||
} | ||
}, | ||
{ | ||
"if": { | ||
"properties": { | ||
"type": { | ||
"const": "process" | ||
} | ||
} | ||
}, | ||
"then": { | ||
"$ref": "resources.process.schema.json" | ||
} | ||
} | ||
] | ||
} |
49 changes: 49 additions & 0 deletions
49
pkg/test/loader/schema/jsonschemas/resources/clientServer.schema.json
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,49 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "resources.clientServer.schema.json", | ||
"title": "The clientServer test resource", | ||
"description": "A clientServer test resource sets up a client and a server, and enables their communication by tuning the underlying network infrastructure. The user can specify udp4, udp6, tcp4, tcp6 or unix as transport protocol. For connection-oriented transport protocols, the client is automatically connected to the server. The resource enables field binding to both client and server information", | ||
"properties": { | ||
"l4Proto": { | ||
"description": "The transport protocol used by the client and the server", | ||
"type": "string", | ||
"enum": [ | ||
"udp4", | ||
"udp6", | ||
"tcp4", | ||
"tcp6", | ||
"unix" | ||
] | ||
}, | ||
"address": { | ||
"description": "The endpoint exposed by the server (as accepted by net.SplitHostPort or empty, in case of l4Proto equals to 'unix'", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"l4Proto", | ||
"address" | ||
], | ||
"x-exposedFields": { | ||
"fields": { | ||
"client": { | ||
"description": "The exposed client information", | ||
"fields": { | ||
"fd": { | ||
"description": "The client file descriptor", | ||
"fieldType": "fd" | ||
} | ||
} | ||
}, | ||
"server": { | ||
"description": "The exposed server information", | ||
"fields": { | ||
"fd": { | ||
"description": "The server file descriptor", | ||
"fieldType": "fd" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.