|
| 1 | +package build_attestation |
| 2 | + |
| 3 | +# Required build metadata fields |
| 4 | +required_fields = { |
| 5 | + "builder_id", |
| 6 | + "build_type", |
| 7 | + "source_repo", |
| 8 | + "commit_hash", |
| 9 | + "build_timestamp", |
| 10 | + "build_platform" |
| 11 | +} |
| 12 | + |
| 13 | +# Check if all required fields are present |
| 14 | +has_required_fields { |
| 15 | + field := required_fields[_] |
| 16 | + input[field] |
| 17 | +} |
| 18 | + |
| 19 | +missing_fields[field] { |
| 20 | + field := required_fields[_] |
| 21 | + not input[field] |
| 22 | +} |
| 23 | + |
| 24 | +# Verify the build type is allowed |
| 25 | +allowed_build_types = {"Release", "Debug"} |
| 26 | + |
| 27 | +has_valid_build_type { |
| 28 | + input.build_type == allowed_build_types[_] |
| 29 | +} |
| 30 | + |
| 31 | +# Verify the build platform is allowed |
| 32 | +allowed_platforms = {"linux", "macos", "windows"} |
| 33 | + |
| 34 | +has_valid_platform { |
| 35 | + input.build_platform == allowed_platforms[_] |
| 36 | +} |
| 37 | + |
| 38 | +# Deny reasons |
| 39 | +deny[msg] { |
| 40 | + count(missing_fields) > 0 |
| 41 | + msg := sprintf("Missing required build metadata fields: %v", [missing_fields]) |
| 42 | +} |
| 43 | + |
| 44 | +deny[msg] { |
| 45 | + not has_valid_build_type |
| 46 | + msg := sprintf("Invalid build type: %s. Allowed types: %v", [input.build_type, allowed_build_types]) |
| 47 | +} |
| 48 | + |
| 49 | +deny[msg] { |
| 50 | + not has_valid_platform |
| 51 | + msg := sprintf("Invalid build platform: %s. Allowed platforms: %v", [input.build_platform, allowed_platforms]) |
| 52 | +} |
| 53 | + |
| 54 | +# Build attestation is valid if there are no violations |
| 55 | +valid { |
| 56 | + count(deny) == 0 |
| 57 | +} |
| 58 | + |
| 59 | +# Generate an attestation statement |
| 60 | +attestation[result] { |
| 61 | + result := { |
| 62 | + "valid": valid, |
| 63 | + "builder_id": input.builder_id, |
| 64 | + "build_type": input.build_type, |
| 65 | + "source_repo": input.source_repo, |
| 66 | + "commit_hash": input.commit_hash, |
| 67 | + "build_timestamp": input.build_timestamp, |
| 68 | + "build_platform": input.build_platform, |
| 69 | + "timestamp": time.now_ns() |
| 70 | + } |
| 71 | +} |
0 commit comments