Skip to content

feat: Feature/rego generator - #167

Open
Rohit-Singh43-1 wants to merge 6 commits into
ibm-hyper-protect:mainfrom
Rohit-Singh43-1:Feature/rego-generator
Open

feat: Feature/rego generator#167
Rohit-Singh43-1 wants to merge 6 commits into
ibm-hyper-protect:mainfrom
Rohit-Singh43-1:Feature/rego-generator

Conversation

@Rohit-Singh43-1

Copy link
Copy Markdown
Member

Description

Introduced a new cli parameter rego-generator.
Provides support of rego file generation and providing base64 rego policy
Implements the contract GenerateRegoPolicy() Public API

Related Issue

Fixes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactor (no functional changes)
  • CI/CD or build changes

Target Platform

  • HPVS (IBM Hyper Protect Virtual Servers for VPC)
  • CCRT (IBM Confidential Computing Container Runtime)
  • CCRV (IBM Confidential Computing Container Runtime for Red Hat Virtualization Solutions)
  • CCCO (IBM Confidential Computing Containers for Red Hat OpenShift Container Platform)
  • All platforms
  • Not platform-specific

Testing

  • make test passes
  • make fmt applied (no formatting changes needed)
  • New tests added for new functionality (if applicable)

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my code
  • I have added/updated GoDoc comments for public functions
  • I have updated documentation (README, docs/README.md) if needed
  • All new and existing tests pass (make test)
  • I have verified there are no breaking changes (or documented them above)

- New Flag created for supporting rego generation
- Added testcases and docs updated
@Rohit-Singh43-1 Rohit-Singh43-1 changed the title Feature/rego generator feat: Feature/rego generator Aug 20, 2026
Comment thread docs/README.md Outdated

| File | Content |
|------|---------|
| `policy.rego` | Plain OPA v1 Rego source |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any use of human readable file @Rohit-Singh43-1 ?
means as per requirement you need base64 file right

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if this file is needed can we create other flag example format flag
default to base64?

Comment thread docs/README.md Outdated
--in pod.yaml \
--out policy.rego
# Output:
# Successfully generated Rego policy: policy.rego

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel better if we create one more flag ex: format here to generate type of file as per requirement

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vikas-sharma24 for review ,we need 2 files base64 can directly copied to contract and nomal file your user to verify the details , For now we can go with once we mature wiith this feature we can remove human text files all together and only base64 will be handled

assert.Contains(t, policy, `quay\\.io/prometheus/busybox:latest`)
assert.Contains(t, policy, "allow_image(image_name)")
assert.Contains(t, policy, "allow_command(image_name, args)")
// HpcrText returns standard base64 (not the encrypted hyper-protect-basic prefix)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment


// TestProcess_WithInitContainer tests Process with pod containing init containers
func TestProcess_WithInitContainer(t *testing.T) {
podYAML := `apiVersion: v1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add one testcase with invalid kind

Comment thread samples/hpcc/sample-pod.yaml Outdated
apiVersion: v1
kind: Pod
metadata:
name: hpcc-workload-pod

@vikas-sharma24 vikas-sharma24 Aug 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to ccco instead of hpcc, check other references as well example (lables -> app)

@vikas-sharma24

Copy link
Copy Markdown
Member

@Rohit-Singh43-1 could you add some examples of the new command? Also resolve git conflicts

@Rohit-Singh43-1

Copy link
Copy Markdown
Member Author

`./contract-cli-s390x --help
Contract CLI automates contract generation and management for IBM Confidential Computing services.

Supports:

  • IBM Confidential Computing Container Runtime
  • IBM Confidential Computing Container Runtime for Red Hat Virtualization Solutions
  • IBM Confidential Computing Containers for Red Hat OpenShift Container Platform

Documentation: https://ibm-hyper-protect.github.io/contract-cli/

Usage:
contract-cli [flags]
contract-cli [command]

Available Commands:
base64 Encode input as Base64
base64-tgz Create Base64 tar archive of container configurations
contract-template Generate a contract template
decrypt Decrypt encrypted text in IBM Confidential Computing format
decrypt-attestation Decrypt encrypted attestation records
download-certificate Download encryption certificates
encrypt Generate signed and encrypted contract
encrypt-string Encrypt string in IBM Confidential Computing format
get-certificate Extract specific certificate version from download output
help Help about any command
image Get IBM Confidential Computing Container Runtime image details from IBM Cloud
initdata Gzip and Encoded initdata annotation
list-encryptioncert-versions List available encryption certificate versions
rego-generator Generate OPA Rego policy from Kubernetes pod YAML
sealed-secret Generate sealed secret for CCCO
sign-contract Sign an encrypted contract
validate-contract Validate contract schema
validate-encryption-certificate Validate encryption certificate
validate-network Validate network configuration schema

Flags:
-h, --help help for contract-cli
-v, --version version for contract-cli

Use "contract-cli [command] --help" for more information about a command.
[root@mystack1 test_sealed]# ./contract-cli-s390x rego-generator --help
Usage:
contract-cli rego-generator [flags]

Mandatory Flags:
--in Path to Kubernetes pod YAML file (use '-' for standard input)

Optional Flags:
--format Output format: 'base64' (default) prints/writes only the IBM CC base64 policy, 'text' prints/writes only the plain Rego policy, 'both' produces both
--help help for rego-generator
--out Path to save the generated output (stem used for file names; prints to stdout if not specified)
./contract-cli-s390x rego-generator --in persona/rb_possgress.yaml --format both --out rb_possgress
Successfully generated Rego policy: rb_possgress.rego
Successfully generated Rego policy (base64): rb_possgress_base64

l`

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