Skip to content

feat(entities): Implement ENTITY_ORGANIZATION for Github Providers #6356

Open
Jaydeep869 wants to merge 9 commits intomindersec:mainfrom
Jaydeep869:feat/organization-entity-5377
Open

feat(entities): Implement ENTITY_ORGANIZATION for Github Providers #6356
Jaydeep869 wants to merge 9 commits intomindersec:mainfrom
Jaydeep869:feat/organization-entity-5377

Conversation

@Jaydeep869
Copy link
Copy Markdown
Contributor

Description

This PR fully implements ENTITY_ORGANIZATION to act as a proper target for evaluation rules and effectively unblocks the 2FA checking mechanics highlighted in #3842.

As per recent discussions with @evankanderson, rather than introducing custom endpoints or manual administration routines, this integration relies natively on the new generic entity properties architecture and auto registers organizations fully in the background directly after a user successfully installs the Github Provider app.

Key Changes

  • Database & Protobufs:
    • Altered Postgres entities enum via a new migration (000117_organization_entity.up.sql) to include the 'organization' value.
    • Added ENTITY_ORGANIZATION = 9 natively within minder.proto.
  • Generic Entity Engine Integration:
    • Implemented an OrganizationFetcher within github/properties that queries Github's API to construct properties.Properties mapping the is_user and avatar_url fields correctly.
    • Implemented OrganizationValidator for reliable validation logic and registered ENTITY_ORGANIZATION in service.go.
  • Asynchronous Auto Registration LifeCycle:
    • Hooked an auto deployment execution in CreateGitHubAppProvider to publish a MinderEvent to the TopicQueueReconcileEntityAdd Watermill queue synchronously upon provider registration. The control plane natively handles this via background reconcile pipelines.
  • Database Backfill:
    • Executed a programmatic hook (backfill_organizations.go) linked through the migrate up procedure to automatically traverse all existing user/database providers and populate any orphaned organization links via transaction safety upon startup.
  • Testing Adjustments:
    • Safely exposed *db.Provider as a third return value payload originating from CreateGitHubAppWithoutInvitation and rebuilt all the testing mocks appropriately matching the expectation logic.

Related Issues

Testing Performed

  • Code generation executed successfully (make buf, make sqlc, make mock).
  • Ran unit tests locally (make test-silent), fixing broken mock signatures.
  • Verified migration runs cleanly with make run-docker.

Implements ENTITY_ORGANIZATION relying entirely on the new generic entity architecture to solve mindersec#5377 and unblock 2FA checks. Includes property fetcher, validator, and async Watermill organization auto-registration upon GitHub App installation.

Also implements a backfill migration to synthesize missing organization associations for existing providers.
@Jaydeep869 Jaydeep869 requested a review from a team as a code owner April 13, 2026 13:41
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 13, 2026

Coverage Status

coverage: 60.566% (-0.01%) from 60.578% — Jaydeep869:feat/organization-entity-5377 into mindersec:main

- Addresses exhaustive switch cases missed in initial entity setup
- Fixes cyclomatic complexity warning in processAppCallback by extracting error handling
- Fixes gh provider initialization panic by adding support for organization in RegisterEntity
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 this sets up the lifecycle operations for (GitHub) organization entities, but it doesn't actually enable writing rules or profiles that enforce policies on organizations. I think that's fine, but it would be good to indicate the remaining work in the PR description as well as what is implemented.

Have you tested this end-to-end in a local minder instance? If not, I can try to do that in the next few days.

Comment thread cmd/server/app/backfill_organizations.go Outdated
Comment thread cmd/server/app/backfill_organizations.go Outdated
EntityID: ent.ID,
Key: properties.PropertyName,
Value: propBytes,
})
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.

Can this use some common code with providers/github/properties/organization.go?

Comment thread internal/controlplane/handlers_oauth.go Outdated
}

if dbProv != nil {
login := strings.TrimPrefix(dbProv.Name, string(db.ProviderClassGithubApp)+"-")
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.

Even if we don't end up adding a method to fetch the current organization name given the ID, we should at least centralize the name mangling in a function where we can add it later if needed. Ideally, that function would be a part of the GitHub provider.


var confErr providers.ErrProviderInvalidConfig
_, err = s.ghProviders.CreateGitHubAppProvider(ctx, *token, stateData, installationID, state)
dbProv, err := s.ghProviders.CreateGitHubAppProvider(ctx, *token, stateData, installationID, state)
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.

Since the only time the return value from CreateGitHubAppProvider is used is in a unit test, it should be easy to change that to return a provider facet or some other struct which can be used to resolve any provider properties we need. (Currently, it seems like mostly the org name, but possibly other data in the future.)

Comment thread internal/entities/service/validators/organization.go Outdated
Comment thread internal/providers/github/properties/organization.go Outdated
Comment thread internal/providers/github/properties/organization.go Outdated
result[properties.OrgPropertyAvatarURL] = *user.AvatarURL
}
if user.Company != nil {
result[properties.OrgPropertyCompany] = *user.Company
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.

Company appears to be null for a large number of orgs; I'm not sure how it's normally set.

Comment thread pkg/profiles/util.go
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'm marking this PR as "request changes" (has 10+ pending comments) to help track which outstanding PRs need maintainer action vs contributor action.

Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@Jaydeep869
Copy link
Copy Markdown
Contributor Author

Hi @evankanderson! Thanks for the insightful and deep review. I really appreciate it. I apologize for the massive delay in circling back to this. I’ve been incredibly busy knocking out my end semester exams.

I have pushed up a fresh commit that tackles all of your feedback.

@evankanderson
Copy link
Copy Markdown
Member

Hi @evankanderson! Thanks for the insightful and deep review. I really appreciate it. I apologize for the massive delay in circling back to this. I’ve been incredibly busy knocking out my end semester exams.

I have pushed up a fresh commit that tackles all of your feedback.

No problem, I've had quite a backlog as well.

@evankanderson
Copy link
Copy Markdown
Member

I think you may need to rename your migration file, as we had another 000117 for adding a Rego version to the ruletypes table.

Jaydeep869 added 3 commits May 1, 2026 01:45
Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@Jaydeep869 Jaydeep869 force-pushed the feat/organization-entity-5377 branch from 330e396 to 34c66c2 Compare May 1, 2026 00:07
Jaydeep869 added 2 commits May 1, 2026 05:53
Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@Jaydeep869
Copy link
Copy Markdown
Contributor Author

Hey @evankanderson, can you review it now

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.

Add a organization entity

3 participants