Skip to content

refactor(github): consolidate JWT generation#2541

Merged
chmouel merged 1 commit intotektoncd:mainfrom
theakshaypant:SRVKP-10952-ghapp-token-jwt-creation
Mar 9, 2026
Merged

refactor(github): consolidate JWT generation#2541
chmouel merged 1 commit intotektoncd:mainfrom
theakshaypant:SRVKP-10952-ghapp-token-jwt-creation

Conversation

@theakshaypant
Copy link
Copy Markdown
Member

@theakshaypant theakshaypant commented Mar 6, 2026

📝 Description of the Change

Move GitHub App JWT generation from app package to main provider for centralization. Update all call sites and tests.

👨🏻‍ Linked Jira

https://issues.redhat.com/browse/SRVKP-10952

🔗 Linked GitHub Issue

N/A

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

If you have used AI assistance, please provide the following details:

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

Important

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com

**💡You can use the script ./hack/add-llm-coauthor.sh to automatically add
these co-author trailers to your commits.

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the GitHub App authentication process by consolidating the JWT generation logic into the core GitHub provider. It also introduces a credential caching layer to minimize repeated Kubernetes API interactions when retrieving GitHub App IDs and private keys, thereby enhancing efficiency and streamlining the authentication workflow.

Highlights

  • Centralized JWT Generation: The GenerateJWT function for GitHub App authentication has been moved from the app subpackage to the main github provider package, centralizing the logic.
  • Credential Caching: A caching mechanism has been implemented to store GitHub App ID and private key credentials per namespace, reducing redundant Kubernetes API calls to fetch secrets.
  • Updated Call Sites and Tests: All existing call sites for GenerateJWT have been updated to use the new centralized function, and new unit and integration tests have been added to validate the caching functionality.
Changelog
  • pkg/cmd/tknpac/info/install.go
    • Updated import path for the GitHub provider.
    • Modified the call to GenerateJWT to use the centralized function in the main GitHub provider.
  • pkg/provider/github/app/token.go
    • Removed the GenerateJWT function and its associated JWTClaim struct.
    • Updated the GetAndUpdateInstallationID method to call the centralized GenerateJWT function.
  • pkg/provider/github/app/token_test.go
    • Adjusted test cases to invoke the GenerateJWT function from the main GitHub provider.
  • pkg/provider/github/github.go
    • Added a new GenerateJWT method to the Provider struct, encapsulating the JWT creation logic.
    • Introduced appCredentialsCache and cachedAppCredentials structs to manage credential caching.
    • Initialized the credentialsCache within the New() function for the GitHub provider.
  • pkg/provider/github/parse_payload.go
    • Implemented caching logic within GetAppIDAndPrivateKey to store and retrieve GitHub App credentials per namespace.
    • Added a comment explaining the caching behavior.
  • pkg/provider/github/parse_payload_test.go
    • Added TestGetAppIDAndPrivateKey_Caching to verify the credential caching mechanism.
    • Added TestTokenCreationFlow_Integration to test the end-to-end token creation flow with caching.
Activity
  • End-to-end tests were performed.
  • Manual testing was conducted.
  • AI assistance was utilized for generating unit/E2E tests and commit messages.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request consolidates the GitHub App JWT generation logic into the main provider package, improving code organization, and adds credential caching per namespace to optimize Kubernetes API calls. However, it preserves a critical SSRF and credential leak vulnerability in the fetchAppSlug function where a user-controlled header determines the target of an authenticated request. Additionally, the new caching mechanism lacks invalidation logic, leading to a medium-severity issue where rotated credentials may not be picked up until a process restart. The changes are otherwise well-implemented with good test coverage for the caching mechanism.

@theakshaypant
Copy link
Copy Markdown
Member Author

the new caching mechanism lacks invalidation logic, leading to a medium-severity issue where rotated credentials may not be picked up until a process restart.

Since the provider instance is short-lived (per webhook instance), we should be fine not having an invalidation logic.

@theakshaypant theakshaypant force-pushed the SRVKP-10952-ghapp-token-jwt-creation branch 2 times, most recently from b132280 to e4e3202 Compare March 9, 2026 05:01
@theakshaypant theakshaypant marked this pull request as ready for review March 9, 2026 05:01
@theakshaypant theakshaypant changed the title refactor(github): consolidate JWT generation and add caching refactor(github): consolidate JWT generation Mar 9, 2026
@chmouel chmouel force-pushed the SRVKP-10952-ghapp-token-jwt-creation branch from e4e3202 to 53eeeb3 Compare March 9, 2026 07:57
Copy link
Copy Markdown
Member

@chmouel chmouel left a comment

Choose a reason for hiding this comment

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

/lgtm

Move GitHub App JWT generation from app package to main provider
for centralization. Update all call sites and tests.

Jira: https://issues.redhat.com/browse/SRVKP-10952

Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
Assisted-by: Claude <noreply@anthropic.com>
@theakshaypant theakshaypant force-pushed the SRVKP-10952-ghapp-token-jwt-creation branch from 53eeeb3 to b8bfd3a Compare March 9, 2026 11:14
@chmouel chmouel merged commit 059c01a into tektoncd:main Mar 9, 2026
13 checks passed
@theakshaypant theakshaypant deleted the SRVKP-10952-ghapp-token-jwt-creation branch March 9, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants