Skip to content

Enforced provider and projectID in db call#6303

Open
DharunMR wants to merge 1 commit intomindersec:mainfrom
DharunMR:Enforce-provider-and-projectID
Open

Enforced provider and projectID in db call#6303
DharunMR wants to merge 1 commit intomindersec:mainfrom
DharunMR:Enforce-provider-and-projectID

Conversation

@DharunMR
Copy link
Copy Markdown
Contributor

@DharunMR DharunMR commented Apr 8, 2026

Summary

This PR implements strict security boundaries for entity retrieval and property management by enforcing the Security Triple (EntityID, ProjectID, ProviderID) across the database and service layers.

Previously, certain database calls and service methods relied on incomplete identifiers, which theoretically could allow for cross-provider or cross-project data access if an ID was known. This refactor ensures that every entity-related operation is strictly bounded by both the project and the provider that owns the entity.

Key Changes:

  • Database Layer (SQL)
    Enforced Constraints: Updated GetEntityByID, GetEntityByName, and DeleteEntity queries in entities.sql to require project_id and provider_id. Property Security: Updated property-related queries (GetProperty, GetAllPropertiesForEntity, DeleteProperty) to utilize JOIN or USING clauses against entity_instances, ensuring property operations cannot bypass entity ownership boundaries. Optimized Flush Cache: Updated ListFlushCache to join with entity_instances, allowing background workers to retrieve the provider_id directly from the database without extra Go-side lookups.

  • Service Layer (Go)
    Property Service: Refactored EntityWithPropertiesByID and related methods to accept and validate the full Security Triple. Repository Service: Updated GetRepositoryById, GetRepositoryByName, and Delete methods to pass mandatory security parameters. EEA & Background Workers: Updated the Event Aggregator and reconcilers to use the ProviderID now provided by the enhanced flush cache queries.

  • API & Middleware
    Controlplane: Updated API handlers (Artifacts, Repositories, Profiles) to translate provider names from the request context into UUIDs via providerStore.GetByName to satisfy the new database constraints.

  • Fixes Enforce provider and project ID in GetEntityByID db call #4417

  • Fixes Enforce provider and project ID in EntityWithProperties in the properties service #4419

Testing

  • Test Suite

    Ran go test ./... (100% passing) to verify that the embedded database correctly respects the new project_id slices and that all handlers propagate context properly.
  • Manual Verification

    • Spun up the local environment using make run-docker.
    • Executed a manual SQL injection test via docker exec -it postgres_container psql.
    • Created a mock project, provider, and entity instance.
    • Verified that querying the exact entity UUID using the authorized project_id array returned the entity (1 row).
    • Verified that simulating a cross-tenant IDOR attack by querying the exact entity UUID with an unauthorized/different project_id array correctly returned 0 rows (Access Denied).

@DharunMR DharunMR requested a review from a team as a code owner April 8, 2026 08:22
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 8, 2026

Coverage Status

Coverage is 60.204%DharunMR:Enforce-provider-and-projectID into mindersec:main. No base build found for mindersec:main.

@DharunMR DharunMR changed the title Enforced provider and project in db call Enforced provider and projectID in db call Apr 8, 2026
Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

It looks like you may also have a merge conflict, but this looks good other than a few small comments -- I'd like to avoid adding remote (serial) lookups in loop contexts -- I didn't look in enough detail to know for sure here if that was happening..

Comment thread internal/db/entity_helpers.go Outdated
Comment thread internal/entities/handlers/strategies/entity/refresh_by_id.go Outdated
Comment thread internal/entities/properties/service/helpers.go Outdated
Comment thread internal/entities/service/service.go Outdated
@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch 2 times, most recently from 8e99b54 to 5c1b61d Compare April 10, 2026 06:52
Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

I think you just force-pushed to the wrong branch. :-/

Comment thread internal/db/entity_helpers.go Outdated
Comment thread internal/entities/handlers/strategies/entity/refresh_by_id.go Outdated
@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch from 5c1b61d to 6933e2f Compare April 10, 2026 07:01
@DharunMR
Copy link
Copy Markdown
Contributor Author

I think you just force-pushed to the wrong branch. :-/

Unfortunatly! now solved it

@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch 3 times, most recently from 1063a3e to d7067a1 Compare April 10, 2026 13:44
@DharunMR
Copy link
Copy Markdown
Contributor Author

@evankanderson i've verified the tests pass locally ,but fails ci

@DharunMR DharunMR requested a review from evankanderson April 10, 2026 15:41
Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

One small concern about duplicating getAuthorizedProjects logic twice, and some code that I think is functionally dead and should probably be removed.

}

ewp, err := ps.getEntityWithProperties(ctx, *ent, opts)
projects, err := ps.getAuthorizedProjects(ctx, ent.ProjectID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified that this is only called by getEntityInner, which is only called by the strategies in handlers/strategies/entity for handling updates of resources which were auto-created due to parent resources.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(In response to the question whether this was called in a loop)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had actually removed getAuthorizedProjects in my latest commit

Comment thread internal/entities/service/service.go Outdated
Comment thread internal/entities/service/service.go
Comment thread internal/entities/service/service.go Outdated
@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch 3 times, most recently from 676c0cb to 32fc7d8 Compare April 13, 2026 04:34
@DharunMR DharunMR requested a review from evankanderson April 13, 2026 04:47
@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch 3 times, most recently from d655ebe to 2c90a2a Compare April 13, 2026 05:23
@evankanderson
Copy link
Copy Markdown
Member

(This has a merge conflict again, sorry!)

@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch from 2c90a2a to 6699a36 Compare April 21, 2026 01:59
@DharunMR
Copy link
Copy Markdown
Contributor Author

(This has a merge conflict again, sorry!)

resolved it now

Signed-off-by: DharunMR <maddharun56@gmail.com>
@DharunMR DharunMR force-pushed the Enforce-provider-and-projectID branch from 6699a36 to 4a67fc4 Compare April 21, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce provider and project ID in EntityWithProperties in the properties service Enforce provider and project ID in GetEntityByID db call

3 participants