8000 [BB-508] sync with github app by Bencheng21 · Pull Request #67 · ConductorOne/baton-github · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[BB-508] sync with github app #67

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

Merged
merged 9 commits into from
May 23, 2025
Merged

[BB-508] sync with github app #67

merged 9 commits into from
May 23, 2025

Conversation

Bencheng21
Copy link
Contributor

Customer wants to get rid of the service account and use github app instead.

This PR adds the option to sync via the GitHub App.
Today, we use the personal access token to access resources that a user is granted to.
In github app, it's not the same story, since.
installation token is pinned to an organization, that means different organizations using the same app should have different installation tokens and one installation tokens from one org cannot access the other repository.

Unfortunately, an installation access token can by design only access a single account (GitHub user or organization account). There cannot be a single token that has access across multiple organizations.

see here

Test.

image image

The results are consistent with what we get when using a personal access token.

How to configure.

Install the GitHub App on your organizations.

Copy the private key and App ID.

Update the configuration with these two values.

Followup.

Intallation token expires in 1 hour, if the syn process takes more than 1 hour, we should refresh the token.

@Bencheng21 Bencheng21 force-pushed the BB508_single_client branch from cd868e6 to 7ff46b6 Compare May 21, 2025 21:04
@Bencheng21 Bencheng21 changed the title Bb508 single client [BB-508] sync with github app May 21, 2025
8000
syncSecrets = field.BoolField(
"sync-secrets",
field.WithDescription(`Whether to sync secrets or not`),
)
installationID = field.StringField(
Copy link
Contributor

Choose a reason for hiding this comment

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

func (gh *GitHub) validateAppCredentials(ctx context.Context) (annotations.Annotations, error) {
orgLogins := gh.orgs
if len(orgLogins) > 1 {
return nil, fmt.Errorf("github-connector: Only one GitHub organization is allowed per group")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: what does "per group" mean here? should we say something like "Only one GitHub organization is allowed when authenticating with a github app"?

Copy link
Contributor Author

How about Only one GitHub organization should be specified?

syncSecrets = field.BoolField(
"sync-secrets",
field.WithDescription(`Whether to sync secrets or not`),
)
fieldRelationships = []field.SchemaFieldRelationship{
field.FieldsMutuallyExclusive(
Copy link
Contributor
@laurenleach laurenleach May 22, 2025

Choose a reason for hiding this comment

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

nit: maybe we should also add FieldsAtLeastOneUsed(accessTokenField, appPrivateKeyPath) since we removed the field.WithRequired(true) from accessTokenField

Comment on lines 450 to 455
for orgName := range o.orgs {
installation, resp, err = findInstallation(ctx, o.appClient, orgName)
if err != nil {
return nil, "", nil, fmt.Errorf("github-connector: failed to fetch installations: %w", err)
}
}
Copy link
Contributor
@laurenleach laurenleach May 22, 2025

Choose a reason for hiding this comment

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

why do we have to do this? can't we get the org from o.orgs

@@ -384,7 +417,7 @@ func (o *orgResourceType) Revoke(ctx context.Context, grant *v2.Grant) (annotati
return nil, nil
}

func orgBuilder(client *github.Client, orgCache *orgNameCache, orgs []string, syncSecrets bool) *orgResourceType {
func orgBuilder(client, appClient *github.Client, orgCache *orgNameCache, orgs []string, syncSecrets bool) *orgResourceType {
orgMap := make(map[string]struct{}) 8000

for _, o := range orgs {
Copy link
Contributor Author
@Bencheng21 Bencheng21 May 22, 2025

Choose a reason for hiding this comment

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

@laurenleach Replied your comment:
We need org ID to construct org resources, that's why we need to call findInstallation() in order to get org id.
o.orgs only has org name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. this is better.

orgCache: orgCache,
syncSecrets: syncSecrets,
}
}

func (o *orgResourceType) listOrganizationsFromAppInstallations(
Copy link
Contributor

Choose a reason for hiding this comment

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

we can just return 1 resource for this

@Bencheng21 Bencheng21 merged commit 62f9455 into main May 23, 2025
2 checks passed
@Bencheng21 Bencheng21 deleted the BB508_single_client branch May 23, 2025 17:00
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.

2 participants
0