Skip to content

feat(dar): Policy Agent governance workflow node for Data Access Requests - #28269

Merged
yan-3005 merged 10 commits into
mainfrom
ram/policy-agent-dar
May 25, 2026
Merged

yan-3005 merged 10 commits into
mainfrom
ram/policy-agent-dar

Conversation

@yan-3005

@yan-3005 yan-3005 commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements the PolicyAgent automated task node in the Data Access Request (DAR) governance workflow. This PR contains the OpenMetadata-side scaffolding — the Collate-specific implementation lives in the openmetadata-collate repo.

What's in this PR

Node factory extensibility (NodeFactory + NodeFactoryRegistry)

  • NodeFactoryRegistry — new extension point that allows Collate (or any downstream) to register additional node types without modifying NodeFactory directly
  • NodeFactory delegates to registered factories before falling back to its own switch — zero changes needed in OpenMetadata when Collate adds new node types

PolicyAgent node scaffolding

  • policyAgentTaskDefinition.json — JSON schema for the policyAgentTask node subtype: waitForCompletion, timeoutSeconds, inputNamespaceMap
  • nodeSubType.json — policyAgentTask added to the NodeSubType enum
  • NodeFactory — POLICY_AGENT_TASK case wired (stub; concrete impl registered by Collate via NodeFactoryRegistry)

Workflow definition update

  • DataAccessRequestTaskWorkflow.json — base workflow updated; Collate overrides this with the full PolicyAgent node wiring

Schema

  • databasePolicyConfig.json — columns: string[] field added for ColumnLevel access requests; accessType and requestedAccess enums aligned with dataAccessRequestPayload.json

Self-approval prevention for workflow-managed tasks

  • SetApprovalAssigneesImpl — when a task is workflow-managed (taskWorkflowManaged=true) and the only reviewer is the task creator, the creator is now correctly excluded from assignees and the task is left unassigned (assignees=[]). hasAssignees remains true for managed tasks regardless of assignee count, so no task is lost. Previously the creator was always re-added when the list emptied, defeating the self-approval guard for managed tasks.

Tests

  • NodeFactoryTest — covers POLICY_AGENT_TASK dispatch; adds @AfterEach cleanup to prevent singleton pollution across test classes
  • NodeFactoryRegistryTest — covers custom factory registration and fallback behaviour
  • CreateTaskTest — covers availableTransitions population from transitionMetadata
  • SetApprovalAssigneesImplTest — added testSelfApprovalPrevention_workflowManagedTaskRemovesCreatorAndLeavesTaskUnassigned covering the workflow-managed self-approval case

Depends on / related

Test plan

  • NodeFactoryRegistryTest — custom factory registered, dispatched, fallback to built-in
  • NodeFactoryTest — POLICY_AGENT_TASK dispatches correctly; singleton cleanup prevents cross-test pollution
  • CreateTaskTest — availableTransitions built from transitionMetadata on node config
  • SetApprovalAssigneesImplTest — workflow-managed self-approval prevention leaves assignees empty and hasAssignees=true
  • Schema builds clean: mvn -pl openmetadata-spec clean install -DskipTests
  • Backend builds clean: mvn -pl openmetadata-service clean package -DskipTests

🤖 Generated with Claude Code


Summary by Gitar

  • Governance migration:
    • Added addCreateTaskRuleToDataConsumerPolicy to MigrationUtil to backfill the Create operation rule for the task resource in DataConsumerPolicy.
    • Integrated this migration step into both mysql and postgres v200 migration paths to ensure existing installations support task creation.
  • Self-approval logic:
    • Updated SetApprovalAssigneesImpl to add debug logging for workflow-managed tasks when the creator is removed to prevent self-approval.

This will update automatically on new commits.

@yan-3005
yan-3005 requested a review from a team as a code owner May 19, 2026 15:20
Copilot AI review requested due to automatic review settings May 19, 2026 15:20
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@yan-3005 yan-3005 added the safe to test Add this label to run secure Github workflows on PRs label May 19, 2026

Copilot AI 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.

Pull request overview

Adds scaffolding for a new PolicyAgent automated task node in the Data Access Request (DAR) governance workflow, plus a new workflow node factory extension point so downstream distributions (e.g., Collate) can plug in node implementations without modifying OSS NodeFactory.

Changes:

  • Introduces NodeFactoryRegistry and routes POLICY_AGENT_TASK creation through it (Collate-provided implementation).
  • Extends schemas/specs for policyAgentTask (node subtype + node definition) and updates DAR-related policy config schema (accessType/requestedAccess + columns + duration).
  • Updates UI workflow builder mappings/icons for the new node subtype and adjusts task due-date handling based on ISO-8601 duration for granted tasks (with tests).

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
openmetadata-ui/src/main/resources/ui/src/utils/NodeIconUtils.tsx Adds icon selection for PolicyAgentTask nodes.
openmetadata-ui/src/main/resources/ui/src/generated/governance/workflows/elements/nodeSubType.ts Adds PolicyAgentTask to generated NodeSubType enum.
openmetadata-ui/src/main/resources/ui/src/constants/WorkflowBuilder.constants.ts Adds workflow-builder type/label mapping for PolicyAgentTask.
openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedPanel/TaskPanelHeader.tsx Adds “granted” styling state for task status badge.
openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedPanel/feed-panel-header.less Adds CSS styling for the “granted” status badge.
openmetadata-spec/src/main/resources/json/schema/metadataIngestion/policyagentconfig/databasePolicyConfig.json Replaces privilege with accessType/requestedAccess, adds columns + duration, updates required fields.
openmetadata-spec/src/main/resources/json/schema/governance/workflows/elements/nodeSubType.json Adds policyAgentTask to the workflow NodeSubType enum schema.
openmetadata-spec/src/main/resources/json/schema/governance/workflows/elements/nodes/automatedTask/policyAgentTaskDefinition.json Introduces schema for the policyAgentTask automated node definition.
openmetadata-spec/src/main/resources/json/schema/api/governance/createWorkflowDefinition.json Allows workflow definitions to reference the new policyAgentTask node schema.
openmetadata-spec/src/main/java/org/openmetadata/schema/governance/workflows/elements/WorkflowNodeDefinitionInterface.java Registers PolicyAgentTaskDefinition as a Jackson subtype (policyAgentTask).
openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTaskTest.java Adds unit tests for duration-based due date resolution/parsing.
openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/NodeFactoryTest.java Adds tests asserting POLICY_AGENT_TASK delegates to the registry.
openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/NodeFactoryRegistryTest.java Adds tests for registry singleton and registration behavior.
openmetadata-service/src/main/resources/json/data/governance/workflows/DataAccessRequestTaskWorkflow.json Removes the DAR workflow seed JSON (entire file deleted).
openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java Computes “effective due date” from ISO-8601 duration when status becomes Granted.
openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/NodeFactoryRegistry.java Adds singleton registry for external node factory extensions.
openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/NodeFactory.java Routes POLICY_AGENT_TASK creation through NodeFactoryRegistry with a Collate-only fallback error.

LOG.warn("No workflow node factory registered for subtype: {}", subType);
return Optional.empty();
}
return Optional.of(ext.create(nodeDefinition, config, workflowDefinitionName));
Comment on lines +745 to +750
try {
return LocalDate.now(ZoneOffset.UTC)
.plus(Period.parse(duration))
.atStartOfDay(ZoneOffset.UTC)
.toInstant()
.toEpochMilli();
Comment on lines +46 to +55
@Test
@Order(3)
void testCreateReturnsEmptyForUnregisteredSubtype() {
// POLICY_AGENT_TASK is not registered in OSS — the handler lives in Collate.
Optional<NodeInterface> result =
NodeFactoryRegistry.getInstance()
.create(NodeSubType.POLICY_AGENT_TASK, null, null, "TestWorkflow");

assertTrue(result.isEmpty());
}
Comment on lines +200 to +204
// ---- resolveEffectiveDueDate ----

@Test
void testResolveEffectiveDueDatePreservesRequestedDueDateForNonGrantedStatus() {
Long requested = 999L;
Comment on lines +60 to +73
void testPolicyAgentTaskThrowsWhenRegistryReturnsEmpty() {
// Simulate no Collate handler registered: replace with a registry that produces empty.
// We can't clear the singleton, so we verify the orElseThrow contract by replacing
// the registered extension with one that mimics an absent registration.
NodeFactoryRegistry registry = NodeFactoryRegistry.getInstance();

// Temporarily point POLICY_AGENT_TASK to a handler that throws to exercise
// the IllegalStateException contract of NodeFactory.createNode().
registry.register(
NodeSubType.POLICY_AGENT_TASK,
(def, cfg, name) -> {
throw new IllegalStateException(
"policyAgentTask is a Collate-only feature — handler not registered");
});
@github-actions

Copy link
Copy Markdown
Contributor

✅ TypeScript Types Auto-Updated

The generated TypeScript types have been automatically updated based on JSON schema changes in this PR.

…and CreateTask

- Use Optional.ofNullable instead of Optional.of in NodeFactoryRegistry so a
  null return from an extension produces the meaningful orElseThrow error
  instead of a cryptic NPE
- Fix Period-based duration in parseMillisFromIso8601Duration to use
  ZonedDateTime instead of LocalDate so month/year durations (e.g. P1M)
  preserve the time-of-day rather than snapping to midnight

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings May 19, 2026 15:40

Copilot AI 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.

Pull request overview

Copilot reviewed 16 out of 24 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

openmetadata-service/src/main/resources/json/data/governance/workflows/DataAccessRequestTaskWorkflow.json:1

  • This workflow definition JSON appears to be removed. OSS bootstrapping/tests reference DataAccessRequestTaskWorkflow (e.g., DataAccessRequest form schema + integration tests) and expect it to be seeded on startup; deleting this file will break DAR lifecycle in OSS unless it is replaced by another workflow definition with the same name.

Comment on lines +745 to +749
try {
return ZonedDateTime.now(ZoneOffset.UTC)
.plus(Period.parse(duration))
.toInstant()
.toEpochMilli();
Comment on lines +46 to +55
@Test
@Order(3)
void testCreateReturnsEmptyForUnregisteredSubtype() {
// POLICY_AGENT_TASK is not registered in OSS — the handler lives in Collate.
Optional<NodeInterface> result =
NodeFactoryRegistry.getInstance()
.create(NodeSubType.POLICY_AGENT_TASK, null, null, "TestWorkflow");

assertTrue(result.isEmpty());
}
Comment on lines +39 to +45
@BeforeEach
void registerPolicyAgentStub() {
// Register a no-op stub so POLICY_AGENT_TASK tests are independent of whether
// NodeFactoryRegistryTest has already run in this JVM.
NodeFactoryRegistry.getInstance()
.register(NodeSubType.POLICY_AGENT_TASK, (def, cfg, name) -> STUB);
}
Comment on lines +59 to +74
@Test
void testPolicyAgentTaskThrowsWhenRegistryReturnsEmpty() {
// Simulate no Collate handler registered: replace with a registry that produces empty.
// We can't clear the singleton, so we verify the orElseThrow contract by replacing
// the registered extension with one that mimics an absent registration.
NodeFactoryRegistry registry = NodeFactoryRegistry.getInstance();

// Temporarily point POLICY_AGENT_TASK to a handler that throws to exercise
// the IllegalStateException contract of NodeFactory.createNode().
registry.register(
NodeSubType.POLICY_AGENT_TASK,
(def, cfg, name) -> {
throw new IllegalStateException(
"policyAgentTask is a Collate-only feature — handler not registered");
});

LOG.info("Registering workflow node factory for subtype: {}", subType);
extensions.put(subType, extension);
}

Comment on lines +56 to +62
"columns": {
"description": "List of column names requested when accessType is ColumnLevel.",
"type": "array",
"items": {
"type": "string"
}
},
@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 63%
63.17% (65635/103887) 43.9% (35996/81992) 46.59% (10559/22661)

@github-actions

github-actions Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (17 flaky)

✅ 4184 passed · ❌ 0 failed · 🟡 17 flaky · ⏭️ 90 skipped

Shard Passed Failed Flaky Skipped
✅ Shard 1 299 0 0 4
🟡 Shard 2 786 0 4 11
🟡 Shard 3 780 0 7 8
🟡 Shard 4 812 0 1 12
🟡 Shard 5 771 0 2 47
🟡 Shard 6 736 0 3 8
🟡 17 flaky test(s) (passed on retry)
  • Features/BulkImport.spec.ts › Database (shard 2, 1 retry)
  • Features/IncidentManager.spec.ts › Complete Incident lifecycle with table owner (shard 2, 1 retry)
  • Features/KnowledgeCenter.spec.ts › Article mentions in description should working for Knowledge Center (shard 2, 1 retry)
  • Features/KnowledgeCenterTextEditor.spec.ts › Rich Text Editor - Text Formatting (shard 2, 1 retry)
  • Features/KnowledgeCenterTextEditor.spec.ts › Rich Text Editor - Text Formatting (shard 3, 1 retry)
  • Features/OntologyExplorerCardinality.spec.ts › CUSTOM relation type with sourceMax=1 and no targetMax should produce "1" → "M" (shard 3, 1 retry)
  • Features/OntologyExplorerCardinality.spec.ts › stats reflect the cardinality-typed edges in the relation count (shard 3, 1 retry)
  • Features/OntologyExplorerE2E.spec.ts › switching back from Hierarchy to Overview restores stats (shard 3, 2 retries)
  • Features/OntologyExplorerE2E.spec.ts › toggling edge labels off and back on leaves the graph and cardinality map intact (shard 3, 2 retries)
  • Features/RTL.spec.ts › Verify Following widget functionality (shard 3, 1 retry)
  • Features/Table.spec.ts › Table pagination with sorting should works (shard 3, 1 retry)
  • Pages/DataContractsSemanticRules.spec.ts › Validate Description Rule Is_Set (shard 4, 1 retry)
  • Pages/Entity.spec.ts › User as Owner with unsorted list (shard 5, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard 5, 2 retries)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/ServiceListing.spec.ts › should render the service listing page (shard 6, 1 retry)
  • Pages/Users.spec.ts › Create and Delete user (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

…ackfill DataConsumerPolicy Create rule

- SetApprovalAssigneesImpl: add else branch to log when workflow-managed
  task creator is removed and task left unassigned (addresses Gitar review)
- v200 migration: add addCreateTaskRuleToDataConsumerPolicy to backfill the
  DataConsumerPolicy-CreateTask-Rule that was added to the seed JSON in
  #28044 but missing from the migration step for existing installations

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings May 22, 2026 11:09

Copilot AI 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.

Pull request overview

Copilot reviewed 27 out of 35 changed files in this pull request and generated 4 comments.

Comment on lines +88 to +89
label: 'Policy Enforcement',
displayLabel: 'Policy Enforcement',
Comment on lines +35 to +38
&.granted {
background-color: #e6fffb;
color: #13c2c2;
}
…xercise orElseThrow path

Use deregister() so NodeFactoryRegistry.create() returns Optional.empty() and
the orElseThrow supplier in NodeFactory.createNode fires — the actual contract
under test. The previous approach threw from inside the factory extension,
bypassing orElseThrow entirely.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@gitar-bot

gitar-bot Bot commented May 22, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 3 resolved / 3 findings

Implements the PolicyAgent governance workflow node and registry-based factory extensibility, while resolving singleton test pollution and adding critical self-approval prevention logs. Migration support for existing DataConsumerPolicy rules is also included with no outstanding issues.

✅ 3 resolved
✅ Bug: Singleton registry makes test classes order-dependent

📄 openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/NodeFactoryRegistryTest.java:48-55 📄 openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/NodeFactoryTest.java:39-45
NodeFactoryRegistryTest#testCreateReturnsEmptyForUnregisteredSubtype (Order 3) asserts that POLICY_AGENT_TASK is not registered in the singleton. However, NodeFactoryTest.@beforeeach unconditionally registers a stub for POLICY_AGENT_TASK. If the JUnit engine runs NodeFactoryTest before NodeFactoryRegistryTest, Order(3) will fail because the singleton already has the extension registered.

Since NodeFactoryRegistry is a static singleton with no unregister or reset method, there is no safe way to guarantee isolation across test classes.

Fix options:

  1. Add a package-private resetForTesting() method to NodeFactoryRegistry and call it in a @beforeeach in NodeFactoryRegistryTest.
  2. Use a different (unused) NodeSubType value in NodeFactoryRegistryTest Order(3) that is guaranteed unregistered.
✅ Edge Case: parseMillisFromIso8601Duration: "P14D" gives time-of-day precision but "P1M" snaps to start-of-day

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:739-753
When Duration.parse handles day-based strings like "P14D", the result is System.currentTimeMillis() + exact millis. When the Period fallback handles month/year strings like "P1M", the result is LocalDate.now().plus(period).atStartOfDay(), discarding the current time-of-day. This means a grant issued at 15:00 with "P14D" expires at ~15:00 in 14 days, but "P1M" expires at 00:00 on the target day — an inconsistency that could confuse users (access ending earlier than expected for month-based durations). Consider using LocalDateTime.now(ZoneOffset.UTC).plus(period) or Instant.now().plus(period) for the Period branch to maintain time-of-day consistency.

✅ Quality: Missing debug log for workflow-managed empty assignees case

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImpl.java:162-173
When assigneeList.isEmpty() && workflowManagedTask is true (the new intended path), the creator is removed and the list stays empty, but no LOG.debug is emitted. The other two branches both log their reasoning. Adding a log here would aid debugging of the new workflow-managed self-approval prevention path.

The later log at line 190 partially covers this (it will show hasAssignees=true, count=0), but the specific self-approval reason is lost.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@yan-3005
yan-3005 merged commit c4ffa51 into main May 25, 2026
69 checks passed
@yan-3005
yan-3005 deleted the ram/policy-agent-dar branch May 25, 2026 08:20

This branch was previously deployed

1 inactive deployment
test — 7b94bb09 Deployed May 22, 2026 by yan-3005 via playwright-ci-postgresql (5, 6) #48253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants