Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BED-5436): Constraint violations in LinkWellKnownGroups during ingestion #1190

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neumachen
Copy link
Contributor

@neumachen neumachen commented Mar 4, 2025

Description

This PR fixes an issue where the LinkWellKnownGroups function encountered graph DB constraint violations during ingestion. The function failed when attempting to create well-known group nodes with SIDs existing in the database but with different node types.

The fix modifies the getOrCreateWellKnownGroup function to:

  1. Only filter by ObjectID when looking up nodes, not by kind
  2. Add the Group kind to existing nodes if it's missing
  3. Update the node to ensure it has the correct properties

Motivation and Context

This PR addresses: BED-5436

During ingestion, users encountered errors when the LinkWellKnownGroups function attempted to run. The specific error was a Neo4j constraint violation (Neo.ClientError.Schema.ConstraintValidationFailed) because nodes with the same SID but different types already existed in the database. This could happen due to previous incomplete or incorrect ingestions.

The solution ensures that SID linking will work correctly even when nodes with the same SID but different types already exist, preventing constraint violations and allowing ingestion to complete successfully.

How Has This Been Tested?

Added comprehensive tests that verify the behavior with various node scenarios:

  • Normal scenario with no pre-existing nodes
  • Pre-existing node without Group kind
  • Pre-existing node with different kind (constraint violation scenario)
  • Pre-existing node with Group kind already

Tests are run against Neo4j and PostgreSQL databases to ensure compatibility across supported database types.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

@neumachen neumachen closed this Mar 4, 2025
@neumachen neumachen deleted the bug/bed-5436 branch March 4, 2025 17:08
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2025
@neumachen neumachen restored the bug/bed-5436 branch March 4, 2025 17:13
@neumachen neumachen reopened this Mar 4, 2025
@neumachen neumachen changed the title refactor(ad): Improve node handling and add comprehensive test covera… fix(BED-5436): Constraint violations in LinkWellKnownGroups during ingestion Mar 4, 2025
@neumachen neumachen force-pushed the bug/bed-5436 branch 3 times, most recently from 73c4912 to 4d0130a Compare March 4, 2025 21:56
This commit fixes an issue where the LinkWellKnownGroups function was
encountering graph DB constraint violations during ingestion. The errors occurred
when attempting to create well-known group nodes with SIDs that already existed
in the database but with different node types.

The root cause was in the getOrCreateWellKnownGroup function, which was
filtering nodes by both ObjectID and the Group kind. When a node with the
matching ObjectID existed but didn't have the Group kind, the function would
try to create a new node with the same ObjectID, causing a constraint violation.

The fix modifies the getOrCreateWellKnownGroup function to:
1. Only filter by ObjectID when looking up nodes, not by kind
2. Add the Group kind to existing nodes if it's missing
3. Update the node to ensure it has the correct properties

This approach ensures that:
- We don't attempt to create duplicate nodes with the same ObjectID
- Existing nodes are properly enhanced with the Group kind when needed
- We avoid constraint violations by working with existing nodes

Additional changes:
- Added comprehensive tests to verify the behavior with various node scenarios
- Fixed formatting in FixWellKnownNodeTypes

This change ensures that SID linking will no longer error when it encounters
nodes with different types than expected, addressing the reported constraint
violation errors during ingestion.

Fixes: [BED-5436](https://specterops.atlassian.net/browse/BED-5436)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant