Skip to content

Conversation

@Bencheng21
Copy link
Contributor

@Bencheng21 Bencheng21 commented May 20, 2025

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 changed the base branch from main to update-batonsdk May 20, 2025 00:55
Comment on lines 41 to 48
func ValidateConfig(cfg *Github) error {
apiKey := cfg.GetString(accessTokenField.FieldName)
appKey := cfg.GetString(appIDField.FieldName)
if len(apiKey) == 0 && len(appKey) == 0 {
return fmt.Errorf("api-key or app-privatekey is missing")
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Base automatically changed from update-batonsdk to main May 20, 2025 15:58
}
return gitHubApp{
appJWTClient: client,
appInstallationClient: installationsClient,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if many organizations are using the same app, they should have different tokens and clients.

@Bencheng21 Bencheng21 requested a review from laurenleach May 20, 2025 16:53
Comment on lines +24 to +27
appPrivateKey = field.StringField(
"app-privatekey",
field.WithDescription("The private key used to connect to the GitHub App"),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to have it use the file instead of taking it as a string

Comment on lines +55 to +61
if len(o.appClients) != 0 {
var ok bool
client, ok = o.appClients[oID]
if !ok {
return "", fmt.Errorf("organization: %d doesn't exist", oID)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if its okay to cache like this, we generally don't rely on state like this, I think there can be times when we resume a sync

@Bencheng21 Bencheng21 closed this May 27, 2025
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