Skip to content

feat(github): add glob pattern support for token scope repos#2386

Merged
chmouel merged 1 commit intotektoncd:mainfrom
theakshaypant:SRVKP-10030-feat-support-glob-in-github_app_token_scope_repos
Jan 14, 2026
Merged

feat(github): add glob pattern support for token scope repos#2386
chmouel merged 1 commit intotektoncd:mainfrom
theakshaypant:SRVKP-10030-feat-support-glob-in-github_app_token_scope_repos

Conversation

@theakshaypant
Copy link
Copy Markdown
Member

📝 Description of the Change

Add support for glob patterns when specifying repositories for GitHub App token scoping in both global and repository-level configurations. Users can now use patterns like "myorg/*" to match multiple repos instead of listing each one explicitly.

For global config (secret-github-app-scope-extra-repos), glob patterns are expanded by listing all repositories where the GitHub App is installed. Results are cached to avoid repeated API calls when multiple patterns are specified.

For repository-level config (github_app_token_scope_repos), glob patterns are matched against Repository CRDs in the same namespace, maintaining the existing namespace isolation requirement.

Both exact matches and glob patterns can be combined. Invalid glob patterns are validated early and return clear error messages.

👨🏻‍ Linked Jira

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

🔗 Linked GitHub Issue

N/A

🚀 Type of Change

  • 🐛 Bug fix (fix:)
  • ✨ New feature (feat:)
  • 💥 Breaking change (feat!:, fix!:)
  • 📚 Documentation update (docs:)
  • ⚙️ Chore (chore:)
  • 💅 Refactor (refactor:)
  • 🔧 Enhancement (enhance:)
  • 📦 Dependency update (deps:)

🧪 Testing Strategy

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

PAC global config

akpant@akpant-thinkpadp1gen7:~/code/tekton-pac$ kg cm pipelines-as-code -o yaml | grep extra-repos
  secret-github-app-scope-extra-repos: '*'

Repo CR:

akpant@akpant-thinkpadp1gen7:~/code/tekton-pac$ kg repo akshay-pac-test-repo -n default -o yaml 
apiVersion: pipelinesascode.tekton.dev/v1alpha1
kind: Repository
metadata:
  name: akshay-pac-test-repo
  namespace: default
  ...
spec:
  settings:
    github_app_token_scope_repos:
    - theakshaypant/*
  url: https://github.com/theakshaypant/akshay-pac-test-repo

Controller logs (added logging after

  • creation of token
  • finding a matching repo in namespace
  • finding a matching repo with global wildcard)
akpant@akpant-thinkpadp1gen7:~/code/tekton-pac$ klf pipelines-as-code-controller-6d596b9db-544j4 | grep 10030
{"level":"info","ts":"2026-01-10T09:53:38.867Z","logger":"pipelinesascode","caller":"github/scope.go:77","msg":"10030 - Namespace repo permission to: theakshaypant/akshay-pac-test-repo","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}
{"level":"info","ts":"2026-01-10T09:53:38.868Z","logger":"pipelinesascode","caller":"github/scope.go:77","msg":"10030 - Namespace repo permission to: theakshaypant/webhook-test","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}
{"level":"info","ts":"2026-01-10T09:53:39.234Z","logger":"pipelinesascode","caller":"github/github.go:687","msg":"10030 - Glob repo permission to: theakshaypant/books-go","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}
{"level":"info","ts":"2026-01-10T09:53:39.234Z","logger":"pipelinesascode","caller":"github/github.go:687","msg":"10030 - Glob repo permission to: theakshaypant/akshay-pac-test-repo","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}
{"level":"info","ts":"2026-01-10T09:53:39.234Z","logger":"pipelinesascode","caller":"github/github.go:687","msg":"10030 - Glob repo permission to: theakshaypant/webhook-test","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}
{"level":"info","ts":"2026-01-10T09:53:39.234Z","logger":"pipelinesascode","caller":"github/github.go:687","msg":"10030 - Glob repo permission to: theakshaypant/pogo-mcp","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}
{"level":"info","ts":"2026-01-10T09:53:41.357Z","logger":"pipelinesascode","caller":"github/github.go:666","msg":"10030 - Was able to get all the necessary tokens","commit":"fe5bab4-dirty","provider":"github","event-id":"e72e9a6c-ec77-11f0-9e7d-0a3186135045","event-sha":"c4fef65cae96b00f72374825e005b45fdeb927a8","event-type":"push","source-repo-url":"https://github.com/theakshaypant/akshay-pac-test-repo","target-branch":"refs/heads/main"}

🤖 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

@theakshaypant
Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @theakshaypant, 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 significantly enhances the flexibility of GitHub App token scoping by introducing glob pattern support. This allows users to define repository access for GitHub Apps using wildcard patterns, such as "myorg/*", rather than listing each repository individually. The change applies to both global and repository-level configurations, improving manageability and reducing configuration overhead for projects with many repositories. It also includes robust validation for glob patterns to ensure correct usage.

Highlights

  • Glob Pattern Support: Introduced support for glob patterns (e.g., "myorg/*") in GitHub App token scoping configurations.
  • Dual Configuration Application: Glob patterns are now supported in both global (secret-github-app-scope-extra-repos) and repository-level (github_app_token_scope_repos) settings.
  • Global Scope Expansion: For global configurations, glob patterns are expanded by listing all repositories where the GitHub App is installed, with results being cached for efficiency.
  • Repository-Level Matching: For repository-level configurations, glob patterns are matched against existing Repository CRDs within the same namespace.
  • Validation and Error Handling: Invalid glob patterns are now validated early, providing clear error messages to the user.
  • Combined Usage: Users can combine exact repository names with glob patterns in their configurations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 introduces support for glob patterns in repository scoping for GitHub App tokens, a valuable feature for managing permissions across multiple repositories. The implementation covers both global and repository-level configurations and includes corresponding documentation and test updates.

My review has identified a few areas for improvement. The documentation for repository-level globbing could be more precise to avoid user confusion. There's also a fragile glob detection mechanism in CreateToken that could be made more robust to handle edge cases correctly. Additionally, there are minor improvements to be made in error handling and documentation examples for consistency. Overall, these are great changes that enhance the flexibility of token scoping.


You can use the `Repository` custom resource to scope the generated GitHub token to a list of repositories.
The repositories can be public or private, but must reside in the same namespace as the repository with which the `Repository` resource is associated.
You can specify repositories using exact names or glob patterns (e.g., `myorg/*` to match all repositories under an organization which have the GitHub app installed).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The description of how glob patterns work for repository-level configuration is slightly misleading. It currently states that it matches all repositories where the app is installed, which is true for the global configuration. For repository-level configuration, matching is restricted to Repository CRDs within the same namespace. Clarifying this distinction will help users understand the feature correctly.

Suggested change
You can specify repositories using exact names or glob patterns (e.g., `myorg/*` to match all repositories under an organization which have the GitHub app installed).
You can specify repositories using exact names or glob patterns (e.g., `myorg/*` to match all repositories that are defined as `Repository` CRs in the same namespace).


```console
failed to scope GitHub token as repo owner1/project1 does not exist in namespace test-repo
failed to scope GitHub token as repo with pattern owner1/project1 does not exist in namespace test-repo
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The example error message is inconsistent with the Repository CR example provided earlier. The CR uses the glob pattern owner1/*, but the error message refers to owner1/project1. To avoid confusion, the error message should reflect the pattern that failed to match.

Suggested change
failed to scope GitHub token as repo with pattern owner1/project1 does not exist in namespace test-repo
failed to scope GitHub token as repo with pattern owner1/* does not exist in namespace test-repo

Comment on lines +670 to +672
// We can skip error check here as all the glob compilation has been checked
// before this method is called.
reposToScope, _ := glob.Compile(repoPattern)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Ignoring a potential error from glob.Compile with the blank identifier _ is risky, even if you assume the pattern has been pre-validated. It's better practice to handle the error defensively. This makes the code more robust and helps catch unexpected issues during development or future refactoring.

reposToScope, err := glob.Compile(repoPattern)
	if err != nil {
		// This should not happen since we have validated the pattern before, but being defensive.
		return fmt.Errorf("BUG: previously validated glob pattern %q failed to compile: %w", repoPattern, err)
	}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah probably a good idea to add the error in the event namespace of the user

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 introduces support for glob patterns when scoping GitHub App tokens, which is a great enhancement for flexibility. The changes cover both global and repository-level configurations, along with corresponding documentation and test updates.

My review focuses on improving robustness, efficiency, and documentation clarity. I've identified a potential panic due to an unhandled error, an opportunity to optimize token creation by avoiding redundant API calls, and a point of confusion in the updated documentation. Addressing these points will make the feature more resilient and easier to use.

func (v *Provider) expandGlobAndAddRepoIDs(ctx context.Context, repoPattern string, cache *[]*github.Repository) error {
// We can skip error check here as all the glob compilation has been checked
// before this method is called.
reposToScope, _ := glob.Compile(repoPattern)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Ignoring the error returned by glob.Compile can lead to a panic. If repoPattern is an invalid glob, glob.Compile will return a nil Glob object and an error. The subsequent call to reposToScope.Match() on line 684 would then cause a nil pointer dereference.

While the current call sites in scope.go pre-validate the glob patterns, this function is exported and could be called from other places in the future without this validation. It's safer to handle the error explicitly to prevent panics.

	reposToScope, err := glob.Compile(repoPattern)
	if err != nil {
		return fmt.Errorf("invalid glob pattern %q: %w", repoPattern, err)
	}


You can use the `Repository` custom resource to scope the generated GitHub token to a list of repositories.
The repositories can be public or private, but must reside in the same namespace as the repository with which the `Repository` resource is associated.
You can specify repositories using exact names or glob patterns (e.g., `myorg/*` to match all repositories under an organization which have the GitHub app installed).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The explanation for glob patterns in repository-level configuration is slightly misleading. It states that it matches 'all repositories under an organization which have the GitHub app installed', which is how the global configuration works.

However, for repository-level configuration, glob patterns are matched against Repository CRDs that exist in the same namespace.

To avoid confusion, I suggest clarifying that the matching happens within the namespace's defined repositories.

Suggested change
You can specify repositories using exact names or glob patterns (e.g., `myorg/*` to match all repositories under an organization which have the GitHub app installed).
You can specify repositories using exact names or glob patterns (e.g., `myorg/*` to match all repositories defined as `Repository` CRDs in the same namespace).

)
listURLs := map[string]string{}
listURLs := []string{}
repoListToScopeToken := []string{}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The repoListToScopeToken slice can accumulate duplicate repository names. This can happen if a repository is specified in the global configuration and also matches a glob pattern in the repository-level configuration, or if multiple glob patterns match the same repository.

While uniqueRepositoryID will eventually deduplicate the repository IDs, CreateToken will still perform redundant Repositories.Get API calls for each duplicate entry.

To improve efficiency and avoid unnecessary API calls, consider using a map as a set to collect unique repository names before converting it to a slice at the end.

continue
}
// May or may not be a glob
if _, err := glob.Compile(configValueS); err != nil {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Global config glob is compiled for early exit

Comment on lines +81 to +82
if !globMatchFound {
msg := fmt.Sprintf("failed to scope GitHub token as repo with pattern %s does not exist in namespace %s", repo.Spec.Settings.GithubAppTokenScopeRepos[i], ns)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To keep the non-matching behaviour similar, an error is returned if repo config globs (or exact names) do not match any repo CR in the anmespace.


for _, r := range repository {
// Check if this is a glob pattern
if strings.ContainsAny(r, "*?[") {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The repository list still contains globs coming from the global config which are matched first.

return nil
}

func (v *Provider) listAppRepos(ctx context.Context) ([]*github.Repository, error) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This method lists all repos that the PAC application is installed on.

Comment on lines +682 to +687
for _, repo := range *cache {
repoFullName := repo.GetFullName()
if reposToScope.Match(repoFullName) {
v.RepositoryIDs = uniqueRepositoryID(v.RepositoryIDs, repo.GetID())
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No error if the global config pattern does not match any repos the app is installed on

continue
}

split := strings.Split(r, "/")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All global non-glob and namespace matched repos flow remains unchanged

Add support for glob patterns when specifying repositories for GitHub
App token scoping in both global and repository-level configurations.
Users can now use patterns like "myorg/*" to match multiple repos
instead of listing each one explicitly.

For global config (secret-github-app-scope-extra-repos), glob patterns
are expanded by listing all repositories where the GitHub App is
installed. Results are cached to avoid repeated API calls when multiple
patterns are specified.

For repository-level config (github_app_token_scope_repos), glob
patterns are matched against Repository CRDs in the same namespace,
maintaining the existing namespace isolation requirement.

Both exact matches and glob patterns can be combined. Invalid glob
patterns are validated early and return clear error messages.

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

Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
@theakshaypant theakshaypant force-pushed the SRVKP-10030-feat-support-glob-in-github_app_token_scope_repos branch from dbf7b97 to 55820ee Compare January 14, 2026 05:10
@pipelines-as-code
Copy link
Copy Markdown

pipelines-as-code bot commented Jan 14, 2026

🔍 PR Lint Feedback

Note: This automated check helps ensure your PR follows our contribution guidelines.

⚠️ Items that need attention:

🤖 AI attribution

The following commits lack an explicit AI attribution footer:

  • 55820ee feat(github): add glob pattern support for token scope repos

If no AI assistance was used for a commit, you can ignore this warning.
Otherwise add an Assisted-by: or Co-authored-by: footer referencing the AI used.


ℹ️ Next Steps

  • Review and address the items above
  • Push new commits to update this PR
  • This comment will be automatically updated when issues are resolved
🔧 Admin Tools (click to expand)

Automated Issue/Ticket Creation:

  • /issue-create - Generate a GitHub issue from this PR content using AI
  • /jira-create - Create a SRVKP Jira ticket from this PR content using AI

⚠️ Important: Always review and edit generated content before finalizing tickets/issues.
The AI-generated content should be used as a starting point and may need adjustments.

These commands are available to maintainers and will post the generated content as PR comments for review.

🤖 This feedback was generated automatically by the PR CI system

@pipelines-as-code pipelines-as-code bot added documentation Improvements or additions to documentation feature New feature or request github labels Jan 14, 2026
Copy link
Copy Markdown
Member Author

@theakshaypant theakshaypant Jan 14, 2026

Choose a reason for hiding this comment

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

Not very sure about this. Updating local env to run these tests.

@theakshaypant theakshaypant marked this pull request as ready for review January 14, 2026 08:08
@chmouel
Copy link
Copy Markdown
Member

chmouel commented Jan 14, 2026

/test go-testing

@chmouel
Copy link
Copy Markdown
Member

chmouel commented Jan 14, 2026

I spent some time on it, I don't see any security issues, with what we are doing here. The first globbing should always match..

We are bypassing webhook repo validation in here tho, I don't think we should enforce it to keep the flexibility but we need to document it

@chmouel
Copy link
Copy Markdown
Member

chmouel commented Jan 14, 2026

that go-testing error is weird, does not happen on that PR #2363 for example

@chmouel
Copy link
Copy Markdown
Member

chmouel commented Jan 14, 2026

while invesigating this i figured a potential issue that is related in #2395

@theakshaypant
Copy link
Copy Markdown
Member Author

/retest

@theakshaypant
Copy link
Copy Markdown
Member Author

that go-testing error is weird, does not happen on that PR #2363 for example

Passed on retest

@chmouel chmouel merged commit 18413b1 into tektoncd:main Jan 14, 2026
7 of 11 checks passed
@theakshaypant theakshaypant deleted the SRVKP-10030-feat-support-glob-in-github_app_token_scope_repos branch January 15, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feature New feature or request github

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants