Skip to content

feat(policy): add policy check command - #681

Merged
colek42 merged 9 commits into
in-toto:mainfrom
manzil-infinity180:feat/policy-check
Nov 12, 2025
Merged

colek42 merged 9 commits into
in-toto:mainfrom
manzil-infinity180:feat/policy-check

Conversation

@manzil-infinity180

Copy link
Copy Markdown
Member

What this PR does / why we need it

Description

swf (main) $ witness-dev policy check policy.json --verbose 
INFO    Validating policy: hellox.json               
INFO    Reading policy file...                       
INFO    Valid JSON structure                         
INFO    Policy expires: 2026-01-01T05:29:59+05:30    
INFO    Checking policy expiration...                
INFO    Policy valid until 2026-01-01 (65 days)      
INFO    Validating Rego policies...                  
INFO    Validated 0 Rego module(s)                   
INFO    Validating functionaries...                  
INFO    Validated 0 functionary root reference(s)    
INFO    Validating root certificates...              
INFO    Validated 0 root certificate(s)              
INFO    Policy validation successful!                
INFO    Summary:                                     
INFO    Total checks: 2                              
INFO    Passed: 2                                    
INFO    Failed: 0         
                           

swf (main) $ witness-dev policy check policy.json --quiet
swf (main) $ witness-dev policy check hellox.json        
INFO    Policy validation successful!                
INFO    Summary:                                     
INFO    Total checks: 2                              
INFO    Passed: 2                                    
INFO    Failed: 0                   

                 
swf (main) $ witness-dev policy check policy.json --json
{
  "valid": true,
  "checks_performed": 2,
  "checks_passed": 2,
  "policy_file": "hellox.json",
  "policy_expiration": "2026-01-01T05:29:59+05:30"
} 

$ witness-dev policy check policy.json   
ERROR   Policy validation failed                     
INFO    Rego Policy (1 error):                       
INFO    1. Rego module 'expected command' in step 'lint' is invalid: failed to parse Rego module: 2 errors occurred:
my_module.rego:3: rego_parse_error: `if` keyword is required before rule body
my_module.rego:3: rego_parse_error: `contains` keyword is required for partial set rules 
INFO    Location: steps.lint.attestations[].regopolicies 
INFO    Suggestion: Check Rego syntax. Common issues:
  - Missing 'package' declaration
  - Syntax errors in deny rules
  - Invalid comparison operators 
INFO    Summary:                                     
INFO    Total checks: 23                             
INFO    Passed: 22                                   
INFO    Failed: 1                                    
ERROR   policy validation failed with 1 error(s)     


swf (main) $ witness-dev policy check policy.json --verbose
INFO    Validating policy: policy.json               
INFO    Reading policy file...                       
INFO    Valid JSON structure                         
INFO    Policy expires: 2025-12-18T10:27:40+05:30    
INFO    Checking policy expiration...                
INFO    Policy valid until 2025-12-18 (51 days)      
INFO    Validating Rego policies...                  
INFO    Checking module 'expected command' in step 'lint'... 
INFO    Validated 1 Rego module(s)                   
INFO    Validating functionaries...                  
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'fmt' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'vet' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'lint' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'build-image' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'unit-test' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'sast' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'save-image' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'generate-sbom' 
INFO    Root 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' exists for step 'secret-scan' 
INFO    Validated 9 functionary root reference(s)    
INFO    Validating root certificates...              
INFO    Checking root certificate 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159'... 
INFO    Valid x509 certificate (CN=sigstore)         
INFO    Root certificate 'dcf166eebe7cbd9760947a88213d94e656349c647d439569dc76a275f05b7159' is valid 
INFO    Validated 1 root certificate(s)              
INFO    Validating timestamp authorities...          
INFO    Timestamp authority 'freetsa' is valid       
ERROR   Policy validation failed                     
INFO    Rego Policy (1 error):                       
INFO    1. Rego module 'expected command' in step 'lint' is invalid: failed to parse Rego module: 2 errors occurred:
my_module.rego:3: rego_parse_error: `if` keyword is required before rule body
my_module.rego:3: rego_parse_error: `contains` keyword is required for partial set rules 
INFO    Location: steps.lint.attestations[].regopolicies 
INFO    Suggestion: Check Rego syntax. Common issues:
  - Missing 'package' declaration
  - Syntax errors in deny rules
  - Invalid comparison operators 
INFO    Summary:                                     
INFO    Total checks: 23                             
INFO    Passed: 22                                   
INFO    Failed: 1                                    
ERROR   policy validation failed with 1 error(s)


swf (main) $ witness-dev policy check policy.json --verbose --json
{
  "valid": false,
  "errors": [
    {
      "category": "Rego Policy",
      "message": "Rego module 'expected command' in step 'lint' is invalid: failed to parse Rego module: 2 errors occurred:\nmy_module.rego:3: rego_parse_error: `if` keyword is required before rule body\nmy_module.rego:3: rego_parse_error: `contains` keyword is required for partial set rules",
      "suggestion": "Check Rego syntax. Common issues:\n  - Missing 'package' declaration\n  - Syntax errors in deny rules\n  - Invalid comparison operators",
      "location": "steps.lint.attestations[].regopolicies"
    }
  ],
  "checks_performed": 23,
  "checks_passed": 22,
  "policy_file": "policy.json",
  "policy_expiration": "2025-12-18T10:27:40+05:30"
}
ERROR   policy validation failed

Fixes #

Acceptance Criteria Met

  • Docs changes if needed
  • Testing changes if needed
  • All workflow checks passing (automatically enforced)
  • All review conversations resolved (automatically enforced)
  • DCO Sign-off

Special notes for your reviewer:

colek42 and others added 5 commits October 25, 2025 01:22
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
Adds a new `witness policy check` command to validate witness policy files.

Key features:
- Validates policy expiration, certificates (PEM, x509, CA status), and Rego syntax
- Checks functionary root references and timestamp authorities
- Supports --verbose, --quiet, and --json output modes
- Provides actionable error messages with fix suggestions and locations

Example:
  witness policy check policy.json
  witness policy check policy.json --verbose
  witness policy check policy.json --json

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
@manzil-infinity180
manzil-infinity180 changed the base branch from feat/policy-check to main October 27, 2025 18:56
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
@netlify

netlify Bot commented Oct 27, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for witness-project ready!

Name Link
🔨 Latest commit 2691cc1
🔍 Latest deploy log https://app.netlify.com/projects/witness-project/deploys/691404e6918a1a000834f633
😎 Deploy Preview https://deploy-preview-681--witness-project.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
@manzil-infinity180

Copy link
Copy Markdown
Member Author

Re-running the test will fix the failed e2e-test

@colek42
colek42 merged commit e10a919 into in-toto:main Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants