Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and Process Policy Files into SemConv Registry + Generic Diagnostic Reporting #153

Merged
merged 20 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1ba992c
feat(checker): Detect policy files into semconv registry
lquerel May 9, 2024
f7ebacb
chore(diagnostic): Render diagnostics from Jinja templates.
lquerel May 14, 2024
acae8bd
chore(diagnostic): Render diagnostics from Jinja templates into gh_wo…
lquerel May 14, 2024
4cae210
chore(diagnostic): Fix build issues.
lquerel May 15, 2024
c02adc1
chore(forge): Improve test coverage
lquerel May 15, 2024
ba7dc9c
chore(common): Improve test coverage
lquerel May 15, 2024
a8a6333
chore(common): Improve test coverage
lquerel May 15, 2024
d0bfca7
chore(common): Implement --diagnostic-format
lquerel May 15, 2024
50f0933
chore(diag): Unify diagnostic message processing and rendering.
lquerel May 16, 2024
54e3f6a
Merge branch 'main' into policy-engine-ext
lquerel May 16, 2024
eb399fd
chore: Merge with main
lquerel May 16, 2024
790c879
chore(cli): Unify parameters across sub-commands
lquerel May 16, 2024
0f66337
chore(cli): Add test infrastructure for the command line
lquerel May 17, 2024
5b5b525
feat(CLI): Support --diagnostic-format and --diagnostic-templates on …
lquerel May 17, 2024
e3b609e
chore: Clean-up before to submit the PR
lquerel May 17, 2024
fdc4c0d
Merge branch 'main' into policy-engine-ext
lquerel May 17, 2024
ae7eb93
chore: Clean-up before to merge the PR
lquerel May 20, 2024
5b064f2
chore: Replace many map_err by a From<fmt::Error> for Error.
lquerel May 20, 2024
d2343a3
chore: Update weaver_checker README.md to introduce PolicyStage
lquerel May 20, 2024
1bb4931
Merge branch 'main' into policy-engine-ext
lquerel May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ordered-float = { version = "4.2.0", features = ["serde"] }
walkdir = "2.5.0"
anyhow = "1.0.83"
itertools = "0.12.1"
globset = { version = "0.4.14", features = ["serde1"] }
miette = { version = "7.2.0", features = ["fancy", "serde"] }

# Features definition =========================================================
[features]
Expand Down Expand Up @@ -67,6 +69,7 @@ serde.workspace = true
serde_yaml.workspace = true
serde_json.workspace = true
walkdir.workspace = true

rayon = "1.10.0"

[profile.release]
Expand Down
1 change: 1 addition & 0 deletions crates/weaver_cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ gix = { version = "0.62.0", default-features = false, features = [
] }

thiserror.workspace = true
serde.workspace = true

1 change: 1 addition & 0 deletions crates/weaver_cache/allowed-external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# This is used with cargo-check-external-types to reduce the surface area of downstream crates from
# the public API. Ideally this can have a few exceptions as possible.
allowed_external_types = [
"serde::ser::Serialize",
]
3 changes: 2 additions & 1 deletion crates/weaver_cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use gix::clone::PrepareFetch;
use gix::create::Kind;
use gix::remote::fetch::Shallow;
use gix::{create, open, progress};
use serde::Serialize;
use tempdir::TempDir;

/// An error that can occur while creating or using a cache.
#[derive(thiserror::Error, Debug)]
#[derive(thiserror::Error, Debug, Serialize)]
#[non_exhaustive]
pub enum Error {
/// Home directory not found.
Expand Down
3 changes: 3 additions & 0 deletions crates/weaver_checker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ thiserror.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
walkdir.workspace = true
globset.workspace = true
miette.workspace = true

regorus = { version = "0.1.4", default-features = false, features = [
"arc",
Expand Down
3 changes: 2 additions & 1 deletion crates/weaver_checker/allowed-external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
allowed_external_types = [
"serde::ser::Serialize",
"serde::de::Deserialize",
"weaver_common::error::WeaverError"
"weaver_common::error::WeaverError",
"miette::protocol::Diagnostic",
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package otel
package before_resolution

# Conventions for OTel:
# - `data` holds the current released semconv, which is known to be valid.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is not a rego file (use for test purposes only).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is another invalid rego file! (use for test purposes only)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package otel
package before_resolution

# Conventions for OTel:
# - `data` holds the current released semconv, which is known to be valid.
Expand Down
2 changes: 1 addition & 1 deletion crates/weaver_checker/data/policies/otel_policies.rego
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package otel
package before_resolution

# Conventions for OTel:
# - `data` holds the current released semconv, which is known to be valid.
Expand Down
79 changes: 79 additions & 0 deletions crates/weaver_checker/data/registries/otel_policies.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package before_resolution

# Conventions for OTel:
# - `data` holds the current released semconv, which is known to be valid.
# - `input` holds the new candidate semconv version, whose validity is unknown.
#
# Note: `data` and `input` are predefined variables in Rego.

# ========= Violation rules applied on unresolved semconv files =========

# A registry `attribute_group` containing at least one `ref` attribute is
# considered invalid.
deny[attr_registry_violation("registry_with_ref_attr", group.id, attr.ref)] {
group := input.groups[_]
startswith(group.id, "registry.")
attr := group.attributes[_]
attr.ref != null
}

# An attribute whose stability is not `deprecated` but has the deprecated field
# set to true is invalid.
deny[attr_violation("attr_stability_deprecated", group.id, attr.id)] {
group := input.groups[_]
attr := group.attributes[_]
attr.stability != "deprecaded"
attr.deprecated
}

# An attribute cannot be removed from a group that has already been released.
deny[schema_evolution_violation("attr_removed", old_group.id, old_attr.id)] {
old_group := data.groups[_]
old_attr := old_group.attributes[_]
not attr_exists_in_new_group(old_group.id, old_attr.id)
}


# ========= Helper functions =========

# Check if an attribute from the old group exists in the new
# group's attributes
attr_exists_in_new_group(group_id, attr_id) {
new_group := input.groups[_]
new_group.id == group_id
attr := new_group.attributes[_]
attr.id == attr_id
}

# Build an attribute registry violation
attr_registry_violation(violation_id, group_id, attr_id) = violation {
violation := {
"id": violation_id,
"type": "semconv_attribute",
"category": "attrigute_registry",
"group": group_id,
"attr": attr_id,
}
}

# Build an attribute violation
attr_violation(violation_id, group_id, attr_id) = violation {
violation := {
"id": violation_id,
"type": "semconv_attribute",
"category": "attrigute",
"group": group_id,
"attr": attr_id,
}
}

# Build a schema evolution violation
schema_evolution_violation(violation_id, group_id, attr_id) = violation {
violation := {
"id": violation_id,
"type": "semconv_attribute",
"category": "schema_evolution",
"group": group_id,
"attr": attr_id,
}
}
Loading
Loading