Skip to content

[CXH-2100] hard failure on getOrgBasePermission failure - #179

Open
kans wants to merge 2 commits into
mainfrom
kans/hard-fail-org-base-permission
Open

kans wants to merge 2 commits into
mainfrom
kans/hard-fail-org-base-permission

Conversation

@kans

@kans kans commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

now, with more faulting.

@kans
kans requested a review from a team July 22, 2026 17:42
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Connector PR Review: hard failure on getOrgBasePermission failure

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 7b8e75696a7d.
Review mode: full
View review run

Review Summary

Scanned the full PR diff for security and correctness. This change converts the previous silent fail-closed behavior (treating an absent default_repository_permission as none) into a hard PermissionDenied failure whenever direct-collaborators-only is enabled, plus an up-front Validate() probe (validateBasePermissionVisibility) on one confirmed-admin org in both the PAT and GitHub App credential paths. The behavior change is intentional, gated behind the opt-in direct-collaborators-only flag, and well covered by new and updated tests (connector_test.go, repository_test.go) that assert both the missing-field PermissionDenied error (with empty grants) and the base-permission none no-expansion path. The adminFound bool to firstAdminOrg refactor is correct, and the installation-token client (gh.client) is the right one to probe in App mode. No new issues found.

The prior suggestion about documenting the new credential requirement is partly addressed: the optimizeForLargeOrgs config description now states admin:org / Organization Administration read is required, but docs/connector.mdx:455-462 still does not mention it (D3), so that earlier finding stands and is not re-posted here.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

@github-actions github-actions Bot 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.

No blocking issues found.

@github-actions github-actions Bot 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.

No blocking issues found.

@luisina-santos luisina-santos changed the title hard failure on getOrgBasePermission failure [CXH-2100] hard failure on getOrgBasePermission failure Jul 23, 2026
@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

CXH-2100

Comment thread pkg/config/config.go
"and skipping per-team detail fetches. Recommended for large orgs.",
"and skipping per-team detail fetches. Recommended for large orgs. "+
"Requires the credential to be able to read the org's default repository permission "+
"(admin:org scope or the Organization Administration read permission); "+

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.

You updated this config-field description to require the credential to read the org's default_repository_permission (admin:org scope / Organization Administration read), and validation + syncs now hard-fail without it when direct-collaborators-only is on — that's the right call. The gap is that the customer-facing docs weren't updated to match: docs/connector.mdx (credential/scopes section, ~L455-462) still doesn't list this new requirement, so an operator reading the docs won't know they need org-owner visibility before enabling this mode. Worth syncing that requirement into the docs in this PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1. Also docs/connector.mdx:77 still says read::org is fine if you're not provisioning (plus the :: typo), docs/docs-info.md:113 says the same thing, and the Optimize section says repo access data is "equivalent". All of those need the admin:org note.

@FeliLucero1 FeliLucero1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Left a few notes. Logic looks right to me, main stuff is rebase + docs + a written-down rollout call on the ticket.

"context"
"testing"

"github.com/google/go-github/v69/github"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

heads up: this won't compile once merged. Main is on go-github v93 now (#197) and NewClient returns (client, err) there. After rebasing, just use newTestGitHubClient(t, mgh.Server()) and drop this import. I tried it locally: with that change tests + lint pass.

return nil, uhttp.WrapErrors(codes.PermissionDenied, "github-connector: credentials validation failed", err)
}

if err := gh.validateBasePermissionVisibility(ctx, firstAdminOrg); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nothing actually tests this wiring (or the one in validateAppCredentials). The tests only hit the helper directly, so if someone deletes this call everything stays green. Could we add a quick gh.Validate(ctx) test against the mock, with and without the field?

if org.GetDefaultRepoPermission() == "" {
err := fmt.Errorf(
"org %q did not return default_repository_permission; direct-collaborators-only requires it to sync org-member repo access correctly. "+
"Grant the credential org-owner visibility (admin:org scope, the GitHub App Organization Administration permission, "+

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do we know for sure "Organization Administration" read is enough for App / fine-grained tokens? GitHub's docs for GET /orgs/{org} only mention org owner + admin:org (classic), and neither permissions page lists the GET under Administration. If it's not enough, App tenants have no fix except turning the flag off. Worth checking once with a real installation token before we tell customers to do this.

"or fine-grained PAT organization Administration read access), or disable direct-collaborators-only",
orgLogin,
)
return uhttp.WrapErrors(codes.PermissionDenied, "github-connector: credentials validation failed", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: this check + the error text are basically copy-pasted in getOrgBasePermission, and the two use different prefixes (github-connector: vs baton-github:). Maybe a small shared errMissingBasePermission(org) helper using baton-github:?

// Org admins always have admin on all repos
adminEntitlementID := fmt.Sprintf("%s:%s:%s", resourceTypeOrg.Id, orgResID, orgRoleAdmin)
for _, perm := range repoAccessLevels {
return nil, nil, err

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this is the intended behavior, but it's a breaking change: with v0.45 Validate runs at the start of every sync, so affected tenants stop syncing until their credential changes. Also, #178 already gives DoorDash correct data (their base perm really is none), so this makes things worse for the customer who reported the bug. Can we get the list of affected tenants + a short rollout note into the PR body / CXH-2100 before merging? Michael's "what's the reason" question on the ticket is still unanswered.

Comment thread pkg/config/config.go
"and skipping per-team detail fetches. Recommended for large orgs. "+
"Requires the credential to be able to read the org's default repository permission "+
"(admin:org scope or the Organization Administration read permission); "+
"validation and syncs fail without it.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

config_schema.json still has the old description. Needs a make generate (after the rebase).

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.

4 participants