Skip to content

fix: match regolibrary memory defaults in C-0004, C-0269 and C-0271 - #216

Merged
matthyx merged 2 commits into
kubescape:mainfrom
sapnasingh4852-source:fix/215-memory-bounds
Dec 3, 2026
Merged

matthyx merged 2 commits into
kubescape:mainfrom
sapnasingh4852-source:fix/215-memory-bounds

Conversation

@sapnasingh4852-source

@sapnasingh4852-source sapnasingh4852-source commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #215.

The bundle set memoryRequestMin 0.125Gi, memoryLimitMin 0.25Gi and 4Gi maxima, while regolibrary's default-config-inputs.json sets both minima to "0" and leaves the maxima empty. The Rego rules for C-0269 and C-0271 only check that the field is set, so a 64Mi request or a 128Mi limit passed Rego and failed CEL.

Changes:

  • configuration/basic-control-configuration.yaml and the test default now use a 0 minimum and an empty maximum, matching the Rego defaults.
  • The maximum comparisons treat "" as no upper bound. The minimum comparison is unchanged; 0 turns it into a presence check.
  • test-resources/memory-range-control-configuration.yaml keeps the old bounded values, and the range-dependent tests opt into it.
  • New pass cases cover the parity fixtures: 64Mi request with 128Mi limit (C-0004), 64Mi request (C-0269), 128Mi limit (C-0271), and a 5Gi/6Gi deployment above the former maximum.

Before / after

kubectl, minikube and docker are not available on this machine, so the minikube suite stays with CI. The comparison below runs one command on both trees: it reads controls/C-XXXX/policy.yaml and test-resources/default-control-configuration.yaml from the given commit and evaluates them with the Kubernetes CEL library the API server uses (k8s.io/apiserver/pkg/cel/library.Quantity and Lists) against the same generated objects.

control object main 894e34b this PR c6eb418
C-0004 pod, request 64Mi + limit 128Mi denied allowed
C-0269 pod, request 64Mi denied allowed
C-0271 pod, limit 128Mi denied allowed
C-0004 deployment, request 5Gi + limit 6Gi denied allowed

Denied means every validation expression returned false. With memory-range-control-configuration.yaml the bounded checks still deny the out-of-range values: C-0004 request 64Mi, C-0004 5Gi/6Gi and C-0271 limit 4.1Gi all return false. Only the unbounded default changes.

This takes option 2 from the issue: the bundle follows the Rego defaults, and enforcing a range stays opt-in through the ControlConfiguration. Moving regolibrary to the tighter bounds instead would be the reverse change in regolibrary; happy to switch if maintainers prefer option 1.

Summary by CodeRabbit

  • Bug Fixes
    • Default memory request and limit checks now require the fields to be set without imposing an upper bound. Configured minimum and maximum thresholds continue to be enforced when provided.
  • Documentation
    • Clarified the default memory validation behavior and how to configure a bounded range.
  • Tests
    • Added coverage for default unbounded memory values and for configured memory ranges, including Pod, Deployment, init-container, and resize cases.

The bundle set memoryRequestMin 0.125Gi, memoryLimitMin 0.25Gi and 4Gi
maxima, while regolibrary defaults the minima to 0 and leaves the maxima
empty. The Rego rules therefore pass a 64Mi request or a 128Mi limit that
the CEL policies rejected.

Relax the shipped parameters to the Rego defaults and treat an empty
maximum as no upper bound. Keep the bounded values in a separate test
template so the range checks stay covered.

Signed-off-by: sapnasingh4852-source <sapnasingh4852-source@users.noreply.github.com>
An empty maximum means no upper bound. State the shipped 0 minimum and
empty maximum so readers know that only field presence is enforced by
default.

Signed-off-by: sapnasingh4852-source <sapnasingh4852-source@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The memory controls now default to a minimum of zero and no maximum. Policy checks skip maximum comparisons when the configured maximum is empty. Tests and documentation cover the defaults and explicitly configured memory ranges.

Changes: Memory control defaults and validation

Layer / File(s) Summary
Set memory defaults and bounded test configuration
configuration/basic-control-configuration.yaml, test-resources/default-control-configuration.yaml, test-resources/memory-range-control-configuration.yaml
The default memory minimums change to zero and maximums become empty. A separate fixture defines bounded memory values for range tests.
Skip unset maximum checks
controls/C-0004/policy.yaml, controls/C-0269/policy.yaml, controls/C-0271/policy.yaml
Each policy skips its memory maximum comparison when the corresponding setting is empty.
Verify and document memory ranges
controls/C-0004/tests.json, controls/C-0269/tests.json, controls/C-0271/tests.json, docs/policies-based-on-kubescape-controls/*
Tests cover default unbounded values and explicitly configured range checks. The documentation describes the defaults and how to configure a range.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: nym01, matthyx

Merge Risk: Minimal · up to c6eb4

This change aligns the memory control defaults with the Rego behavior, so the default policies check only that the memory fields are present. Users who want range enforcement can configure it explicitly. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the memory defaults in C-0004, C-0269, and C-0271 are changed to match regolibrary. The raw summary and objectives confirm that minimums become "0" and maximums become…
Linked Issues check Passed [#215] The issue asks that CEL and Rego agree on memory request/limit workloads for C-0004, C-0269, and C-0271. The issue leaves open which side changes. The PR takes option 2 and relaxes the bundle t…
Out of Scope Changes check Passed All changed paths relate to the memory control parity objective from #215:
- Shipped defaults: basic-control-configuration.yaml and test-resources/default-control-configuration.yaml.
- Policy expressi…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: the memory defaults in C-0004, C-0269, and C-0271 are changed to match regolibrary. The raw summary and objectives confirm that minimums become "0" and maximums become empty, with range enforcement moved to an opt-in template. The title is specific and accurate, and it uses the conventional fix: prefix.

Full details: Linked Issues check

Explanation

[#215] The issue asks that CEL and Rego agree on memory request/limit workloads for C-0004, C-0269, and C-0271. The issue leaves open which side changes. The PR takes option 2 and relaxes the bundle to the Rego defaults.

Evidence at head c6eb418:

  • configuration/basic-control-configuration.yaml and test-resources/default-control-configuration.yaml: memoryRequestMin and memoryLimitMin are "0", and the maxima are "" (empty). This matches the regolibrary defaults named in the issue.
  • controls/C-0004/policy.yaml (confirmed by diff): the memoryRequestMax and memoryLimitMax comparisons run only when the setting is non-empty (params.settings.memoryRequestMax == "" || ...). The min comparison is unchanged. A min of "0" makes it a presence check, so 64Mi requests and 128Mi limits pass by default.
  • controls/C-0269/policy.yaml and controls/C-0271/policy.yaml: the same empty-max guard is applied to the request and limit maxima (per the change summaries).
  • Tests: C-0004, C-0269, and C-0271 tests.json add default-range pass cases for 64Mi/128Mi, 5Gi/6Gi, and a 128Mi limit. Range-dependent failure cases now use test-resources/memory-range-control-configuration.yaml, which keeps bounded values (0.25–4Gi limits, 0.125–4Gi requests).
  • Docs for C-0004, C-0269, and C-0271 state the new defaults and how to enforce a range.

The three issue-listed workloads (C-0004 pod_pass, workload-exceeded, workload-milli-suffix; C-0269 pod_pass; C-0271 pod_pass) are covered by the new or updated test cases. Range enforcement stays available through ControlConfiguration. The #180 scope is not included, as the issue requests.

Limitation: the minikube suite was not run in this review. The verdict relies on the diff, the test definitions, and the PR's reported CEL evaluation. CI execution is not verified here.

Full details: Out of Scope Changes check

Explanation

All changed paths relate to the memory control parity objective from #215:

  • Shipped defaults: basic-control-configuration.yaml and test-resources/default-control-configuration.yaml.
  • Policy expressions: controls/C-0004, C-0269, and C-0271 policy.yaml. Each change adds an empty-maximum guard and does not alter other validation logic.
  • Tests: tests.json files for C-0004, C-0269, and C-0271. These add parity pass cases and attach the bounded template to range-dependent cases.
  • Documentation: the three control docs describe the new defaults and range opt-in.
  • test-resources/memory-range-control-configuration.yaml: a new bounded fixture that supports the range-dependent tests. Its non-memory settings (runtime, registry, label, and similar) are supporting values that let the fixture load as a full ControlConfiguration. The summary shows docker.io and gcr.io entries in registry and image lists. These entries are fixture data, not behavior changes to shipped policies. This is a reasonable reading of a test fixture, but the full file was not read in this review.

No change was found that is unrelated to the memory-range objective.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb408749-a4b9-43d9-b81b-17eabeedf3de
Commits

Reviewing files that changed from the base of the PR and between 894e34b and c6eb418.

Files selected for processing: 12

  • configuration/basic-control-configuration.yaml
  • controls/C-0004/policy.yaml
  • controls/C-0004/tests.json
  • controls/C-0269/policy.yaml
  • controls/C-0269/tests.json
  • controls/C-0271/policy.yaml
  • controls/C-0271/tests.json
  • docs/policies-based-on-kubescape-controls/kubescape-c-0004-deny-resources-with-memory-limit-or-request-not-set.md
  • docs/policies-based-on-kubescape-controls/kubescape-c-0269-deny-resources-with-memory-request-not-set.md
  • docs/policies-based-on-kubescape-controls/kubescape-c-0271-deny-resources-with-memory-limit-not-set.md
  • test-resources/default-control-configuration.yaml
  • test-resources/memory-range-control-configuration.yaml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@matthyx matthyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes (one policy blocker). Reviewed head c6eb418 against main.

Blocker – missing Before/After proof (project policy). The description lists verification steps, but there is no same-command/same-input comparison on main vs this PR. Please add the failing-then-passing output, e.g. the new pass cases (C-0004 64Mi/128Mi, C-0269 64Mi, C-0271 128Mi, 5Gi/6Gi deployment) rejected on main and accepted here, or the TestRegoCELParity known-gap output from #215 before/after.

Question (non-blocking, needs a maintainer): #215 explicitly asks maintainers to choose between (1) moving regolibrary defaults to the bundle's bounds or (2) relaxing the bundle. No maintainer decision is on the issue; the PR takes option 2. Please confirm option 2 before merge, since it weakens the default memory bounds for existing users.

Findings: the change itself looks sound. Max comparisons skip on ""; 0 min reduces to a presence check; defaults match regolibrary default-config-inputs.json; bounded values are kept in memory-range-control-configuration.yaml with the range tests opted in; docs are updated. No duplicate or superseded PRs found (related merged: #160, #198, #79; none rejected). Author has 1 open PR. No existing reviews.

CI: green on this commit (test-all-policies, test-policy-expressions, DCO, GitGuardian, FOSSA, CodeRabbit; main-policy-automation run succeeded). I did not run the minikube suite locally; the review was static.

Once the Before/After proof is added and option 2 is confirmed, this is ready to approve.

@sapnasingh4852-source

Copy link
Copy Markdown
Contributor Author

added the before/after proof to the description at c6eb418.

no cluster here. same command on both trees: policy.yaml and test-resources/default-control-configuration.yaml from each commit, evaluated with the k8s apiserver cel library against the same objects.

C-0004 pod 64Mi/128Mi denied on main 894e34b, allowed here
C-0269 pod 64Mi denied on main 894e34b, allowed here
C-0271 pod 128Mi denied on main 894e34b, allowed here
C-0004 deployment 5Gi/6Gi denied on main 894e34b, allowed here
range template still denies 64Mi request, 5Gi/6Gi and a 4.1Gi limit

on option 2: defaults now match regolibrary default-config-inputs.json, min 0 and empty max. cel no longer rejects values rego accepts. a range stays opt-in through ControlConfiguration. option 1 would change rego for existing users instead. can you confirm option 2 or should i flip the pr to option 1.

@matthyx matthyx moved this to Needs Reviewer in KS PRs tracking Dec 3, 2026

@matthyx matthyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed head c6eb418: Before/After table is now in the description and matches the diff; CI is green; no blockers remain. Option 2 (relax the bundle to the Rego defaults, range opt-in) is a reasonable resolution of #215; a maintainer can still veto it before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

Memory request/limit policies fail workloads that the Rego controls pass (C-0004, C-0269, C-0271)

2 participants