OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

Feature Request: Support for Custom Properties in Policy Rule Conditions

Open m0hitbansal opened this issue 8 months ago • 7 comments

Is your feature request related to a problem? Please describe. I am frustrated by the current limitation of the Policy engine where Rule conditions can only evaluate a predefined set of entity attributes. Currently, if we have Custom Properties defined on an Entity (e.g., a "Data Sensitivity" dropdown or a "Department Owner" field on a Table), we cannot reference these properties within the SpEL expression of a Policy Rule.

This forces us to create overly broad roles or manually manage access via Tags, rather than using the powerful attribute-based access control (ABAC) that OpenMetadata aims to provide.

Describe the solution you'd like I would like the OpenMetadata Policy engine to expose Custom Properties within the SpEL evaluation context.

Specifically:

Allow the resource object in a Rule condition to access its custom properties (e.g., resource.customProperties.get('propertyName')).

Ideally, provide a helper method to simplify the syntax, such as matchCustomProperty('propertyName', 'value').

Ensure that when a Rule is being validated or saved, the UI/Backend recognizes these custom fields as valid variables.

m0hitbansal avatar Mar 25 '26 18:03 m0hitbansal

hi sir I’ve reviewed the issue and have an idea for the fix. I’d like to work on this. Please assign it to me.

jatinmasaram avatar Apr 04 '26 10:04 jatinmasaram

Hi @m0hitbansal @harshach ! I'd love to work on this feature — could you assign it to me? Thanks!

david-mamani avatar Apr 09 '26 02:04 david-mamani

@m0hitbansal please can you assign this issue so I can take forward a chance.

Esvanth avatar Apr 09 '26 10:04 Esvanth

Hi @pmbrull @harshach 👋

Submitted a fix in PR #27218

Implemented all three requested features:

  • getCustomProperties() — exposes entity custom properties as Map<String, Object> in SpEL context
  • matchCustomProperty('propertyName', 'value') — convenient boolean helper for policy rule conditions
  • FIELD_EXTENSION is now fetched during entity resolution so custom properties are loaded from DB

Policy rules can now use: matchCustomProperty('dataSensitivity', 'PII') resource.customProperties.get('department') == 'Finance'

mohitjeswani01 avatar Apr 09 '26 21:04 mohitjeswani01

Hi @m0hitbansal, I'd like to take this one in the hackathon. I've reviewed the open PRs (#27033, #27218) - both attempt the same approach but have correctness gaps:

  • #27033 always adds FIELD_EXTENSION to fetched fields (breaks entity types where supportsExtension == false), and uses instanceof Map on entity.getExtension() which is actually a Jackson ObjectNode - so it returns empty even when properties exist. The bot comments capture this, but haven't been addressed since Apr 4.
  • #27218 is closer but uses bare @Function annotations on the new helpers. Function.java requires name/input/description/examples (no defaults), and ExpressionValidator builds its allow-list from annotation.name() - so the new helpers won't pass parseExpression validation, won't appear in the UI's /policies/functions dropdown, and the new tests will fail once CI runs.

My plan:

  • Add getCustomProperties() to ResourceContextInterface (default empty map), implement in ResourceContext with lazy caching, gate the FIELD_EXTENSION field-add on entityRepository.isSupportsExtension(), and convert via JsonUtils.convertValue(...).
  • Add three properly-annotated SpEL helpers on RuleEvaluator: matchCustomProperty(name, value), matchAnyCustomProperty(name, values...), hasCustomProperty(name). Full @Function metadata so they auto-appear in the rule editor.
  • Unit tests through parseExpression (validates the allow-list path), plus an integration test that creates a custom property, attaches a policy with matchCustomProperty, and asserts the authorization decision end-to-end.

Please assign me if no one is actively addressing the above.

0xharp avatar Apr 15 '26 19:04 0xharp

Hi @m0hitbansal , I'd like to work on this. My approach: locate the SpEL evaluation context builder in the policy/authorization service, expose the entity's customProperties map on the resource object, and add a helper method matchCustomProperty('name', 'value') for clean rule syntax. Will also check if the frontend rule condition validator needs updating. Can you assign this to me?

DivyDeshmukh avatar Apr 15 '26 21:04 DivyDeshmukh

Thank you everyone for your interest in this issue, but it has been assigned. We will reopen this issue if necessary

PubChimps avatar Apr 16 '26 00:04 PubChimps