Skip to content

chore(jans-cedarling): reduce PolicyStore visibility from pub to pub(crate)#14624

Open
olehbozhok wants to merge 8 commits into
mainfrom
jans-cedarling-14614
Open

chore(jans-cedarling): reduce PolicyStore visibility from pub to pub(crate)#14624
olehbozhok wants to merge 8 commits into
mainfrom
jans-cedarling-14614

Conversation

@olehbozhok

@olehbozhok olehbozhok commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Prepare


Description

Target issue

closes #14614

Implementation Details

Goal: reduce PolicyStore visibility from pub to pub(crate).

PolicyStore was exported publicly (re-exported via bindings in lib.rs), but nothing outside the crate needs it. Making it pub(crate) first required removing the public API surface that referenced it and the dead code that kept unused fields/methods "live".

Steps

  1. Drop the public re-export — removed pub use crate::common::policy_store::PolicyStore; from the bindings module in lib.rs.

  2. Remove dead PolicyStore surface so nothing external depends on it:

    • Deleted unused fields name, description, cedar_version.
    • Deleted the unused apply_default_entities_limits() method (which in turn removed the semver::Version and DefaultEntitiesLimits dependencies, plus the default_entities_limits enforcement path and related legacy-store/manager helpers and tests).
  3. Downgrade visibilityPolicyStorepub(crate). Applied the same narrowing to closely coupled types now crate-internal: TrustedIssuer, PoliciesContainer, and their methods.

  4. Simplify schema lookup exposed by the cleanup — get_entity_schema returned (type_name, type_schema) but every caller discarded the schema half; replaced with get_entity_type_name returning only the name. Call sites in build_ctx.rs updated. This also let unused Attribute variant payloads (String, Long, Boolean, Set, Extension) become fieldless.

  5. Cleanup — final commit resolves clippy warnings surfaced by the removals.

Net: no behavioral change; PolicyStore and its coupled types are now crate-private, and the compiler enforces the removed surface stays unused.


Test and Document the changes

  • Static code analysis has been run locally and issues have been fixed
  • Relevant unit and integration tests have been added/updated
  • Relevant documentation has been updated if any (i.e. user guides, installation and configuration guides, technical design docs etc)

Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with docs: to indicate documentation changes or if the below checklist is not selected.

  • I confirm that there is no impact on the docs due to the code changes in this PR.

Summary by CodeRabbit

  • Bug Fixes
    • Improved entity reference resolution for entity and shared-entity attributes by consistently deriving the target entity type during schema lookup.
    • Missing or invalid entity identifiers now follow the required/optional contract consistently.
  • Changes
    • Updated Cedar JSON schema handling (entity type-name resolution; action “applies_to” now supports context-only; simplified attribute shapes and required handling for primitive types).
    • Legacy policy-store metadata fields (name/description/Cedar version) are now ignored during loading.
  • Tests
    • Refreshed JSON schema and policy-store fixtures/expected error messages to match the updated parsing behavior.

…te)`

Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
Drop dead code from cedar schema parsing and policy store:

- Simplify CedarSchemaJson to only track entity type names via a
  HashSet instead of parsing full EntityType/EntityShape; replace
  get_entity_schema with get_entity_type_name (callers only used the
  name). Delete entity_type.rs.
- Drop the unused `required` field from Attribute variants and the
  unused Attribute::is_required(). Collapse Set/Extension to unit
  variants since their payloads were never read.
- Remove unused principalTypes/resourceTypes from action AppliesTo.
- Remove never-called default entity size validation
  (validate_default_entities and related error/limit code); the
  count limit check is retained.
- Remove unused name/description/cedar_version fields from PolicyStore
  and the associated cedar version parsing helpers.

Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
Follow-up to the schema/policy-store cleanup so the crate passes
`cargo clippy --all-targets -- -D warnings`:

- build_expr: match unit Attribute variants (String/Long/Boolean/Set/
  Extension) without struct-pattern braces.
- cedar_json: deserialize entityTypes via a MapAccess visitor that
  collects only keys, avoiding a HashMap with a zero-sized value type.
- default_entities: match the explicit InvalidParentUid variant instead
  of a wildcard in test assertions; remove the now-unused from_hashmap
  test helper.
- attribute: restrict the test-only constructor helpers to pub(crate).

Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
@olehbozhok olehbozhok self-assigned this Jul 24, 2026
@mo-auto

mo-auto commented Jul 24, 2026

Copy link
Copy Markdown
Member

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 59c2666e-a3ab-4d34-8446-65f25f774de5

📥 Commits

Reviewing files that changed from the base of the PR and between f1568db and c2bde4d.

📒 Files selected for processing (1)
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs

📝 Walkthrough

Walkthrough

Changes

Cedar schema and authorization

Layer / File(s) Summary
Simplified schema models and deserialization
jans-cedarling/cedarling/src/common/cedar_schema/...
Entity schemas now retain type names, attributes use reduced variants, action fields are narrowed, and related tests are updated.
Entity reference integration
jans-cedarling/cedarling/src/authz/build_ctx.rs, jans-cedarling/cedarling/src/entity_builder/build_expr.rs
Authorization resolves entity type names through the new schema API and matches the simplified attribute variants.

Policy-store and API boundaries

Layer / File(s) Summary
Legacy policy-store conversion cleanup
jans-cedarling/cedarling/src/common/policy_store/...
Legacy policy stores no longer parse or populate name, description, or Cedar-version metadata; version parsing and default-entity limit application are removed.
Internal visibility and entity validation cleanup
jans-cedarling/cedarling/src/common/default_entities*, jans-cedarling/cedarling/src/lib.rs
Internal entity APIs become crate-visible, entity parse warnings and validation paths are reduced, and the PolicyStore binding re-export is removed.

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested labels: kind-enhancement

Suggested reviewers: haileyesus2433, dagregi

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several large refactors go beyond #14614, including cedar schema/attribute/entity-type rewrites, default-entity changes, and legacy-store cleanup. Split the unrelated cleanup into separate PRs, or document why each refactor is required to make PolicyStore internal.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: reducing PolicyStore visibility from pub to pub(crate).
Description check ✅ Passed The PR description matches the template: target issue, implementation details, testing status, and the no-doc-impact confirmation are present.
Linked Issues check ✅ Passed The PR satisfies #14614 by making PolicyStore pub(crate), removing the lib.rs re-export, and narrowing internal fields/types as suggested.
Docstring Coverage ✅ Passed Docstring coverage is 95.24% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jans-cedarling-14614

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

Comment @coderabbitai help to get the list of available commands.

@mo-auto mo-auto added comp-jans-cedarling Touching folder /jans-cedarling kind-dependencies Pull requests that update a dependency file labels Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs (1)

13-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Field visibility not narrowed along with struct visibility. Both Action/AppliesTo and CedarSchema were changed from pub to pub(crate) in this PR, but their fields were left pub instead of also being narrowed — the same fix pattern applies to all three sites.

  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs#L13-L19: change pub applies_to: AppliesTo, to pub(crate) applies_to: AppliesTo,.
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs#L33-L36: change pub context: Option<Attribute>, to pub(crate) context: Option<Attribute>,.
  • jans-cedarling/cedarling/src/common/cedar_schema/mod.rs#L14-L18: change pub schema, pub json, pub validator_schema to pub(crate).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs` around
lines 13 - 19, The fields of the crate-visible schema types still expose public
visibility. In
jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs:13-19,
narrow Action.applies_to to pub(crate); in
jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs:33-36,
narrow the Action/AppliesTo context field to pub(crate); and in
jans-cedarling/cedarling/src/common/cedar_schema/mod.rs:14-18, narrow
CedarSchema.schema, CedarSchema.json, and CedarSchema.validator_schema to
pub(crate).

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs`:
- Around line 101-107: Update the doc comment for
CedarSchema::get_entity_type_name to describe resolving and returning the
qualified entity type name, including the default_namespace lookup behavior,
rather than merely checking whether the type exists. Leave the separate
entity_type_exists helper documentation and implementation unchanged.

In `@jans-cedarling/cedarling/src/common/policy_store.rs`:
- Line 49: Narrow the visibility of all currently public fields in PolicyStore
to pub(crate), or private where no external callers require access. Also
restrict DefaultEntities::inner to the most restrictive visibility supported by
its callers; update both affected definitions without changing their behavior.

---

Outside diff comments:
In `@jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs`:
- Around line 13-19: The fields of the crate-visible schema types still expose
public visibility. In
jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs:13-19,
narrow Action.applies_to to pub(crate); in
jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs:33-36,
narrow the Action/AppliesTo context field to pub(crate); and in
jans-cedarling/cedarling/src/common/cedar_schema/mod.rs:14-18, narrow
CedarSchema.schema, CedarSchema.json, and CedarSchema.validator_schema to
pub(crate).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0110f6ec-32a2-435b-97ae-9769431210d7

📥 Commits

Reviewing files that changed from the base of the PR and between c0e9a57 and c03b0d4.

📒 Files selected for processing (14)
  • jans-cedarling/cedarling/src/authz/build_ctx.rs
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/action.rs
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/attribute.rs
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/entity_type.rs
  • jans-cedarling/cedarling/src/common/cedar_schema/mod.rs
  • jans-cedarling/cedarling/src/common/default_entities.rs
  • jans-cedarling/cedarling/src/common/default_entities_limits.rs
  • jans-cedarling/cedarling/src/common/policy_store.rs
  • jans-cedarling/cedarling/src/common/policy_store/legacy_store/mod.rs
  • jans-cedarling/cedarling/src/common/policy_store/legacy_store/test.rs
  • jans-cedarling/cedarling/src/common/policy_store/manager.rs
  • jans-cedarling/cedarling/src/entity_builder/build_expr.rs
  • jans-cedarling/cedarling/src/lib.rs
💤 Files with no reviewable changes (4)
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json/entity_type.rs
  • jans-cedarling/cedarling/src/lib.rs
  • jans-cedarling/cedarling/src/common/policy_store/manager.rs
  • jans-cedarling/cedarling/src/common/policy_store/legacy_store/mod.rs

Comment thread jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs Outdated
Comment thread jans-cedarling/cedarling/src/common/policy_store.rs
Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
…DefaultEntities

Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
@coderabbitai coderabbitai Bot added the kind-enhancement Issue or PR is an enhancement to an existing functionality label Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs (1)

218-229: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the crate assertion helper and describe this structural comparison.

This compares nested schema structures; use test_utils::assert_eq and add a message explaining that only entity type names are retained.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs` around lines
218 - 229, Update the structural comparison in the CedarSchemaJson test to use
the crate’s test_utils::assert_eq helper instead of the standard assertion, and
provide a message stating that only entity type names are retained.

Sources: Coding guidelines, Learnings

jans-cedarling/cedarling/src/common/default_entities.rs (1)

1228-1237: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add diagnostic messages to the warning-content assertions.

  • jans-cedarling/cedarling/src/common/default_entities.rs#L1228-L1237: add messages to the entry_id equality and serialized-value assertions.
  • jans-cedarling/cedarling/src/common/default_entities.rs#L1319-L1329: add equivalent messages for each warning in the loop.

As per coding guidelines, “All assertions must include a descriptive message explaining what is being tested.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jans-cedarling/cedarling/src/common/default_entities.rs` around lines 1228 -
1237, Add descriptive diagnostic messages to the entry_id equality and
value-content assertions in the DefaultEntityWarning match at
jans-cedarling/cedarling/src/common/default_entities.rs lines 1228-1237. Add
equivalent messages to each assertion inside the warning loop at lines
1319-1329, explaining the expected warning content being validated.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs`:
- Around line 218-229: Update the structural comparison in the CedarSchemaJson
test to use the crate’s test_utils::assert_eq helper instead of the standard
assertion, and provide a message stating that only entity type names are
retained.

In `@jans-cedarling/cedarling/src/common/default_entities.rs`:
- Around line 1228-1237: Add descriptive diagnostic messages to the entry_id
equality and value-content assertions in the DefaultEntityWarning match at
jans-cedarling/cedarling/src/common/default_entities.rs lines 1228-1237. Add
equivalent messages to each assertion inside the warning loop at lines
1319-1329, explaining the expected warning content being validated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0e8786e9-61b3-4c9e-8da8-3109f2600da9

📥 Commits

Reviewing files that changed from the base of the PR and between c03b0d4 and 34703f6.

📒 Files selected for processing (3)
  • jans-cedarling/cedarling/src/common/cedar_schema/cedar_json.rs
  • jans-cedarling/cedarling/src/common/default_entities.rs
  • jans-cedarling/cedarling/src/common/policy_store.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 24, 2026
Removing the required `name` field from PolicyStore also removed the
"missing required field 'name'" validation gate. Malformed policy store
fixtures now surface the next parse error instead, so the stale
expectations no longer match.

- Rust: drop the missing-name case from test_invalid_policy_store_entry;
  the schema and policies cases still assert their required-field errors.
- Python: point the base64/utf8/schema error cases at the actual decode
  and schema-parse messages now returned.

Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 24, 2026
Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
jans-cedarling/cedarling/src/common/policy_store.rs (2)

235-235: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Run rustfmt on the constructor signature.

This line exceeds the repository’s 100-character Rust limit. Let rustfmt wrap the arguments while preserving the configured indentation.

As per coding guidelines, Rust files must use the project rustfmt settings with a maximum line width of 100 characters.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jans-cedarling/cedarling/src/common/policy_store.rs` at line 235, Run rustfmt
on the PolicyStore constructor signature in new, using the repository’s
configured 100-character width and indentation settings; preserve the
constructor’s behavior and arguments.

Source: Coding guidelines


713-725: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add descriptive messages to the new test assertions.

All added assert! and assert_eq! calls should explain what is being verified so failures are actionable.

As per coding guidelines, all assertions must include a descriptive message explaining what is being tested.

Also applies to: 727-749, 752-781

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jans-cedarling/cedarling/src/common/policy_store.rs` around lines 713 - 725,
Add descriptive failure messages to every newly added assert! and assert_eq! in
annotations_map_merges_policies and the additional tests at the referenced
locations, stating the expected behavior each assertion verifies. Keep the
existing test logic and expected values unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@jans-cedarling/cedarling/src/common/policy_store.rs`:
- Line 235: Run rustfmt on the PolicyStore constructor signature in new, using
the repository’s configured 100-character width and indentation settings;
preserve the constructor’s behavior and arguments.
- Around line 713-725: Add descriptive failure messages to every newly added
assert! and assert_eq! in annotations_map_merges_policies and the additional
tests at the referenced locations, stating the expected behavior each assertion
verifies. Keep the existing test logic and expected values unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8c7ec6cb-64b8-4f0f-b2ba-c2976ff2f58a

📥 Commits

Reviewing files that changed from the base of the PR and between 7c86797 and f1568db.

📒 Files selected for processing (2)
  • jans-cedarling/cedarling/src/common/policy_store.rs
  • jans-cedarling/cedarling/src/lib.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 24, 2026
Signed-off-by: Oleh Bozhok <6554798+olehbozhok@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-jans-cedarling Touching folder /jans-cedarling kind-dependencies Pull requests that update a dependency file kind-enhancement Issue or PR is an enhancement to an existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(jans-cedarling): reduce PolicyStore visibility from pub to pub(crate)

2 participants