Skip to content

Add support for mTLS to GitHub App transport #1860

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abhijith-darshan
Copy link

If ca.crt or caFile is available in the GitHub App secret, a tls config with user provided certs is appended to system cert pool and passed to the underlying GitHub App transport.

closes #1858

@abhijith-darshan abhijith-darshan marked this pull request as ready for review August 4, 2025 15:23
obj.GetName(), obj.GetNamespace(), cache.OperationReconcile))
}

username, password, err := github.GetCredentials(ctx, opts...)
if len(opts.CAFile) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I just realized that we are using .spec.secretRef for certs that apply to the communication with Git via HTTPS, and here we are using the same certs also for hitting the GitHub API to get a token. Does this make sense in all cases? Could you need a custom CA/client cert only for getting the token, but if you use the same CA/cert for the Git HTTPS communication it would not work?

Copy link
Member

@matheuscscp matheuscscp Aug 4, 2025

Choose a reason for hiding this comment

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

Also, where does client cert authentication apply exactly? If you're using a GitHub App to authenticate, would client cert authentication still make any sense? For example, would you need the client cert authentication just for getting a GitHub App token from the API?

Copy link
Author

@abhijith-darshan abhijith-darshan Aug 4, 2025

Choose a reason for hiding this comment

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

Hi @matheuscscp

I just realized that we are using .spec.secretRef for certs that apply to the communication with Git via HTTPS, and here we are using the same certs also for hitting the GitHub API to get a token. Does this make sense in all cases? Could you need a custom CA/client cert only for getting the token, but if you use the same CA/cert for the Git HTTPS communication it would not work?

Also, where does client cert authentication apply exactly? If you're using a GitHub App to authenticate, would client cert authentication still make any sense? For example, would you need the client cert authentication just for getting a GitHub App token from the API?

So TLDR; It is needed for all cases, all endpoints, including git protocol need the ca.crt as it is a global GitHub Enterprise configuration.

So POST request to api/v3/app/installations/INSTALLATION_ID/access_tokens needs ca.crt

Also it makes it easier in flux to only specify the ca.crt in one place and re-use it to fetch installation token and for rest of the git checkout commands.

Let me try to summarize the scenario -

So for on-premise / hybrid cloud scenario GitHub normally recommends this as a Security Hardening feature.

https://docs.github.com/en/[email protected]/admin/configuring-settings/hardening-security-for-your-enterprise/configuring-tls#uploading-a-custom-tls-certificate

  • Enterprise instances that implement the hardening, require ca.crt (Custom / Company RootCA) to be presented for all API endpoints of GitHub... including for git protocols.

  • This is not limited to just GitHub App, but also applicable to PAT and SSH.

  • But when running in containers you either need to have these certs in the image you build, or provide the ca.crt in the tls.Config of the API calls you make.

  • source-controller was already handling this for PAT based auth / SSH scenarios but not for GitHub App.

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense to me. I'll confirm this is ok in the dev meeting tomorrow and get back here 👍

Copy link
Author

Choose a reason for hiding this comment

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

Ok thank you 🙏

Copy link
Member

Choose a reason for hiding this comment

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

This needs to be documented, but if you set certs in the secretRef they must apply all calls no matter the scope.

Copy link
Author

Choose a reason for hiding this comment

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

This needs to be documented, but if you set certs in the secretRef they must apply all calls no matter the scope.

@stefanprodan - there are references to certificate authority usage here in the docs.

https://fluxcd.io/flux/components/source/gitrepositories/#https-certificate-authority

Should I add a bullet point under GitHub provider section here?

https://fluxcd.io/flux/components/source/gitrepositories/#github

Copy link
Member

Choose a reason for hiding this comment

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

Yeap we need to mention there the certs key as optional

this commit ensures that if ca.crt or caFile is available in the github app secret, a tls config with user provided certs is appended to system cert pool and passed to the underlying http transport

Signed-off-by: abhijith-darshan <[email protected]>

(chore): update target URL for TLSConfigFromSecret

this commit ensures that the target URL for runtime/secrets.TLSConfigFromSecret has the scheme and host

Signed-off-by: abhijith-darshan <[email protected]>

(chore): adds test scenarios

this commit adds test scenarios for mTLS GitHub app in reconcile source auth strategy

Signed-off-by: abhijith-darshan <[email protected]>
username, password, err := github.GetCredentials(ctx, opts...)
if len(opts.CAFile) > 0 {
targetURL := fmt.Sprintf("%s://%s", u.Scheme, u.Host)
tlsConfig, err := secrets.TLSConfigFromSecret(ctx, secret, targetURL, secrets.WithSystemCertPool())
Copy link
Member

Choose a reason for hiding this comment

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

Nice 👍

@stefanprodan stefanprodan changed the title [source-controller]: Add support for mTLS to GitHub App transport Add support for mTLS to GitHub App transport Aug 6, 2025
@stefanprodan stefanprodan added area/git Git related issues and pull requests area/security Security related issues and pull requests labels Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/git Git related issues and pull requests area/security Security related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accept Custom Certificate for GitHub App authentication to private Git repositories in source-controller
4 participants