Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e6ca38c
Add Dharmic principles (Ahimsa, Satya, Dharma) for AI governance
kmadan Apr 7, 2025
b0e2308
feat: Implement NIST AI RMF policies
kmadan Jun 29, 2025
811436c
feat: Implement India AI governance policy
kmadan Jun 29, 2025
35bb882
feat: Implement Brazil AI governance policy
kmadan Jun 29, 2025
e44426b
docs: Add disclaimers to all policy READMEs
kmadan Jun 29, 2025
e2f3dda
feat(education): add education industry policies
kmadan Jun 30, 2025
384ab03
fix(rego): correct syntax for linter
kmadan Jun 30, 2025
eef119d
fix(rego): correct syntax for linter
kmadan Jun 30, 2025
0704563
fix(rego): correct syntax for linter
kmadan Jun 30, 2025
96ba41a
fixed linting errors
kmadan Jun 30, 2025
042aa67
ci: trigger new workflow run with custom folder exclusion
kmadan Jun 30, 2025
9fed15d
fix: resolve regal lint violations in NIST policies
kmadan Jun 30, 2025
ca976e6
fix: resolve unsafe variable errors in NIST test files
kmadan Jun 30, 2025
38a851f
fix: resolve remaining regal lint violations
kmadan Jun 30, 2025
7056774
fix: resolve final regal lint violations
kmadan Jun 30, 2025
21c6f86
fix: resolve final non-loop-expression warning in ferpa_compliance
kmadan Jun 30, 2025
0d996df
fix: resolve messy-rule violation in ferpa_compliance
kmadan Jun 30, 2025
e70565a
fix: resolve final non-loop-expression violation
kmadan Jun 30, 2025
2c85f45
fix: resolve non-loop-expression by moving boolean check before loop
kmadan Jun 30, 2025
4e454f5
fix: apply opa fmt with -w flag to update file in place
kmadan Jun 30, 2025
2475c39
test: verify GPG signing is working
kmadan Jun 30, 2025
0fb5e4b
test: verify GPG signing with GitHub email
kmadan Jun 30, 2025
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
5 changes: 3 additions & 2 deletions .github/workflows/opa-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ jobs:
regal version

- name: Run OPA Check
run: opa check .
run: opa check --ignore custom/ .
working-directory: ${{ github.workspace }}

- name: Run Regal Lint
run: regal lint .
run: regal lint --ignore-files custom/ .
working-directory: ${{ github.workspace }}
# CI trigger
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ ENV/
# Logs
*.log


# Local configuration
.env

# Custom policies - excluded from PRs to origin repo
custom/
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ repos:
hooks:
- id: opa-check
name: OPA Policy Check
entry: opa check .
entry: opa check --ignore custom/ .
language: system
pass_filenames: false
files: \.rego$
exclude: ^custom/

- id: regal-lint
name: Regal Lint
entry: regal lint .
entry: regal lint --ignore-files custom/ .
language: system
pass_filenames: false
files: \.rego$
exclude: ^custom/
83 changes: 83 additions & 0 deletions GEMINI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# General Principles
1. Use poetry for python package management, not pip
1.1 Use commands like: poetry run python, poetry add, poetry update
2. Do not make more changes than are asked for - be conservative and surgical
3. Confirm with me, your senior partner, always when in any doubt about the next steps
4. You may ask me to run any commands and share outputs with you, or to make manual changes if you are unable to accomplish these reliably yourself
5. Always wear a worlds best senior programmer hat and critique and review your own design and plan at least once for elegance, DRY, KISS and explainability. Present it to me.
6. Do not exceed 600 lines per file
7. While working in a project with multiple git repositories, always ensure you are in the correct git repository for the current task - esp if you are changing directories
8. When the specific chat or working session context starts getting too long, suggest updating your memory, creating a github issue, and continuing in a fresh session
9. When unable to authenticate to an enabled integration such as JIRA or Confluence, stop and ask me to check authentication.

# Gemini Workspace Context: AI Governance Policies (Rego)

This repository contains a collection of Rego policies for AI governance and risk management. The policies are organized into a clear, hierarchical structure to ensure consistency and ease of navigation.

## Core Principles

1. **Structure is Key:** All policies are organized by domain, version, and category. Adherence to this structure is mandatory.
2. **Rego is the Standard:** All policies are written in the Rego language (`.rego`).
3. **Testing is Required:** Every new policy must be accompanied by a corresponding test file.
4. **Metadata is Essential:** Every policy file must include standardized metadata annotations.
5. **Traceability is Mandatory:** The source of every policy must be documented.

## How to Add a New Policy

Follow these steps to add a new policy to the repository.

### 1. Directory Structure

All policies reside within a specific directory structure. When adding a new policy, place it in the appropriate location:

`{domain}/{version}/{category}/{policy_name}.rego`

- **`{domain}`**: The top-level domain for the policy (e.g., `global`, `industry_specific`, `international`).
- **`{version}`**: The version of the policy set (e.g., `v1`).
- **`{category}`**: The specific risk or functional area the policy addresses (e.g., `fairness`, `student_data_privacy`).
- **`{policy_name}.rego`**: The name of the policy file, using snake_case (e.g., `unbiased_automated_grading.rego`).

### 2. Policy File Requirements

Every `.rego` file must include the following:

- **Package Declaration:** The package name must match the directory path.
```rego
package industry_specific.education.v1.student_data_privacy
```

- **Metadata Annotations:** Include a title, description, version, and a reference to the source.
```rego
# @title Detailed FERPA Compliance
# @description This policy evaluates data access requests against FERPA.
# @version 1.1
# @source https://www.ecfr.gov/current/title-34/subtitle-A/part-99
```

- **Default Rule:** Define a default behavior (usually `deny` or `not compliant`).

- **Clear Deny Messages:** If a policy check fails, it should return a clear, informative message using `deny[msg]`.

### 3. Source and Disclaimer README

At the appropriate directory level (e.g., `/international/eu_ai_act/v1/`), you must include a `README.md` file that contains:

- **Source Information:** A link to the official government or organizational policy that the Rego files are based on.
- **Disclaimer:** A standard disclaimer.

**Example `README.md`:**
```markdown
# EU AI Act Policies (Version 1)

The policies in this directory are based on the official text of the EU AI Act.

**Source:** [Link to the official EU AI Act text]

**Disclaimer:** These policies are provided for informational purposes only and do not constitute legal advice. They are intended to represent the requirements of the EU AI Act in the Rego policy language but have not been certified by any regulatory body.
```

### 4. Testing

- For every `my_policy.rego` file, you must create a corresponding `my_policy_test.rego` in the same directory.
- Tests should cover both `allow`/`compliant` and `deny`/`non-compliant` scenarios.
- Use mock `input` data to simulate realistic policy evaluation scenarios.
133 changes: 133 additions & 0 deletions HANDOFF_SESSION_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# GOPAL Policy Builder - Session Handoff Notes

## Current Status

**PR #10**: https://github.com/Principled-Evolution/gopal/pull/10
- **Title**: "feat: Add new international and industry-specific AI policies with custom folder exclusion"
- **Status**: Open, CI checks still failing
- **Branch**: `opa-policy-builder` in `gopal-argen` fork
- **Latest Commits**: 13 commits, +1,338 βˆ’410 lines

## βœ… Completed Work

### 1. Custom Folder Exclusion (COMPLETED)
- βœ… Removed `custom/` from git tracking with `git rm -r --cached custom/`
- βœ… Added `custom/` to `.gitignore`
- βœ… Updated CI workflow (`.github/workflows/opa-ci.yaml`) to exclude custom folder
- βœ… Updated pre-commit hooks (`.pre-commit-config.yaml`) to exclude custom folder
- βœ… Enhanced README.md with custom folder documentation
- βœ… Verified custom folder exclusion works locally

### 2. Policy Implementations (COMPLETED)
- βœ… **Brazil AI Governance**: Bill 2338/2023 compliance, risk-based approach
- βœ… **India Digital Policy**: NITI Aayog framework, core pillars implementation
- βœ… **NIST AI RMF**: AI 600-1 framework with Govern/Map/Measure/Manage
- βœ… **Education Policies**: Academic integrity, student privacy, fairness, safety

### 3. Major Regal Lint Fixes (COMPLETED)
- βœ… Fixed `messy-rule` violations by grouping `allow` rules together
- βœ… Fixed `default-over-else` violations in Brazil and India policies
- βœ… Fixed `with-outside-test-context` violations in NIST orchestrator
- βœ… Fixed `test-outside-test-package` violations by renaming test packages
- βœ… Fixed unsafe variable errors in test files with proper imports

## βœ… Final Fixes Applied (Session 2)

### Issues Resolved:

1. **βœ… `default-over-else` violations** - RESOLVED in previous session
- All NIST policy files were already fixed

2. **βœ… `test-outside-test-package` violations** - RESOLVED in previous session
- All NIST test files were already properly renamed

3. **βœ… `opa-fmt` violations** - RESOLVED in current session
- Fixed import order in all NIST test files
- Applied proper formatting to satisfy opa fmt requirements

4. **βœ… `non-loop-expression` violation** - RESOLVED in current session
- Extracted student opt-out check into helper function in ferpa_compliance.rego
- Avoided direct field access in rule to eliminate performance warning

5. **βœ… `rule-length` violation** - RESOLVED in current session
- Refactored long test rule in ai_600_1_test.rego into helper function and smaller tests

## 🎯 Current Status (Session 2 Update)

### βœ… All Critical Issues Resolved:

1. **βœ… Major regal lint violations fixed**:
- `default-over-else`: Already resolved in previous session
- `test-outside-test-package`: Already resolved in previous session
- `opa-fmt`: Fixed import order in all NIST test files
- `non-loop-expression`: Fixed ferpa_compliance.rego performance warning
- `rule-length`: Refactored long test rule with helper function

2. **βœ… Latest commit pushed**: Final fix for last remaining lint violation

3. **⏳ CI Status**: Progressive improvement across multiple runs
- Run #28: 6 violations (opa-fmt + rule-length + non-loop-expression)
- Run #29: 1 violation (non-loop-expression only)
- Run #30: 2 violations (non-loop-expression + messy-rule)
- Latest fix: Moved helper function to resolve messy-rule violation

### Verification Commands:

```bash
# Test locally before pushing
opa check --ignore custom/ .
regal lint --ignore-files custom/ .

# Test specific problematic files
regal lint international/nist/v1/manage/manage.rego
regal lint international/nist/v1/manage/manage_test.rego
```

## πŸ“ Key Files to Focus On

### NIST Policies (need default-over-else fixes):
- `international/nist/v1/manage/manage.rego`
- `international/nist/v1/measure/measure.rego`
- `international/nist/v1/govern/governance.rego`
- `international/nist/v1/map/map.rego`

### NIST Test Files (need package fixes):
- `international/nist/v1/manage/manage_test.rego`
- `international/nist/v1/measure/measure_test.rego`
- `international/nist/v1/govern/governance_test.rego`
- `international/nist/v1/map/map_test.rego`
- `international/nist/v1/ai_600_1/ai_600_1_test.rego`

### Education Policy:
- `industry_specific/education/v1/student_data_privacy/ferpa_compliance.rego`

## 🎯 Success Criteria

The session is complete when:
1. βœ… `opa check --ignore custom/ .` passes (PASSING)
2. βœ… `regal lint --ignore-files custom/ .` shows 0 critical violations (SHOULD BE FIXED)
3. ⏳ GitHub CI checks pass on PR #10 (PENDING - waiting for latest run)
4. βœ… Custom folder remains excluded from git tracking (CONFIRMED)

## πŸ” Debugging Notes

- The fixes were applied but may not have taken effect due to git conflicts or overwriting
- The CI might be running on an older commit - check the latest commit hash
- Some test files might have been reverted during manual changes mentioned in supervisor notes

## πŸ“‹ Repository Context

- **Workspace**: `/home/kapil/Projects/gopal-argen`
- **Current Branch**: `opa-policy-builder`
- **Remote Fork**: `Principled-Evolution/gopal-argen`
- **Upstream Repo**: `Principled-Evolution/gopal`
- **PR URL**: https://github.com/Principled-Evolution/gopal/pull/10

## πŸ’‘ Quick Win Strategy

1. Start by checking current file contents to see if fixes were lost
2. Re-apply the most critical fixes (default-over-else in NIST policies)
3. Test locally before pushing
4. Push and monitor CI status

The foundation work is solid - just need to resolve these final linting issues to get the CI passing.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ gopal/
β”‚ β”œβ”€β”€ aiops/ # AI Operations policies
β”‚ β”œβ”€β”€ cost/ # Cost management policies
β”‚ └── corporate/ # Corporate internal policies
β”œβ”€β”€ custom/ # Custom policy categories
β”œβ”€β”€ custom/ # Custom policy categories (local only, excluded from PRs)
└── helper_functions/ # Shared utility functions for policies
```

Expand All @@ -41,7 +41,7 @@ Policies are organized in a modular structure to allow for clear separation of c
2. **International Policies**: Requirements from specific regulatory frameworks
3. **Industry-Specific Policies**: Requirements specific to industry verticals
4. **Operational Policies**: Requirements related to operational aspects
5. **Custom Policies**: User-defined policy categories
5. **Custom Policies**: User-defined policy categories (local development only)

## Versioning

Expand All @@ -58,6 +58,36 @@ Gopal is designed to work seamlessly with [AICertify](https://github.com/princip

Gopal can also be used independently with any OPA-compatible system. The policies follow standard OPA patterns and can be evaluated using the OPA CLI or API.

## Custom Policies

The `custom/` directory is provided for local development of organization-specific policies. This directory is:

- **Excluded from git tracking** - Custom policies are not included in commits or PRs to the origin repository
- **Ignored by CI/CD** - Custom policies do not affect the build or linting processes
- **Local development only** - Allows organizations to develop proprietary policies alongside the standard GOPAL policies

To create custom policies:

1. Create your policy structure under `custom/your_category/v1/`
2. Follow the same naming conventions as standard policies
3. Use the package name `custom.your_category.v1.policy_name`
4. Include comprehensive tests and documentation

Example structure:
```
custom/
β”œβ”€β”€ my_org/
β”‚ β”œβ”€β”€ v1/
β”‚ β”‚ β”œβ”€β”€ compliance/
β”‚ β”‚ β”‚ β”œβ”€β”€ policy.rego
β”‚ β”‚ β”‚ └── policy_test.rego
β”‚ β”‚ └── security/
β”‚ β”‚ β”œβ”€β”€ policy.rego
β”‚ β”‚ └── policy_test.rego
```

**Note**: Custom policies remain local to your development environment and are not shared with the broader GOPAL community.

## Development

### Pre-commit Hooks
Expand Down
Loading