Skip to content

Add possibility to set username for the git-resolver#9543

Open
MarcusElevait wants to merge 2 commits intotektoncd:mainfrom
MarcusElevait:fix-git-resolver-for-bitbucket-cloud
Open

Add possibility to set username for the git-resolver#9543
MarcusElevait wants to merge 2 commits intotektoncd:mainfrom
MarcusElevait:fix-git-resolver-for-bitbucket-cloud

Conversation

@MarcusElevait
Copy link

… git resolver

Changes

When using the git resolver with a private Bitbucket cloud repository, you need to consider two things:

  1. When using the git clone resolver the username must be set to "x-token-auth"
  2. When using the rest api the scm client need to use a username

Currently for the git clone resolver the username is always set to "git". For the rest api there is no username set at all.
With my changes you can define a username within the secret of the token, which is then used in the respective resolver.

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Username can be set for git-resolver

… git resolver

Prior to this commit, there was no possibility to configure a username for the git resolver, neither for clone nor for api.

Added the possibility to set the username via the token secret.
@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 10, 2026
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 10, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign abayer after the PR has been reviewed.
You can assign the PR to them by writing /assign @abayer in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 10, 2026
@MarcusElevait
Copy link
Author

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 10, 2026
Copy link
Member

@aThorp96 aThorp96 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @MarcusElevait!

I have a couple minor suggestions and two requests. The only blocking requests are to either remove or use the global git resolver config for the username field (I don't think it's necessary, personally, but not opposed to keeping it), since it's currently unused outside of tests, and to modify the test TestResolve to check that the username is propagated to the clientfunc and git request, respectively.

| `revision` | Git revision to checkout a file from. This can be commit SHA (SHA-1 or SHA-256), branch or tag. | `aeb957601cf41c012be462827053a21a420befca` `main` `v0.38.2` |
| `gitToken` | An optional secret name in the `PipelineRun` namespace to fetch the token from when doing opration with the `git clone`. When empty it will use anonymous cloning. | `secret-gitauth-token` |
| `gitTokenKey` | An optional key in the token secret name in the `PipelineRun` namespace to fetch the token from when using the `git clone`. Defaults to `token`. | `token` |
| `username` | An optional key in the token secret name in the `PipelineRun` namespace to fetch the username from. Defaults to `username`. | |
Copy link
Member

Choose a reason for hiding this comment

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

Please include an example value:

Suggested change
| `username` | An optional key in the token secret name in the `PipelineRun` namespace to fetch the username from. Defaults to `username`. | |
| `username` | An optional key in the token secret name in the `PipelineRun` namespace to fetch the username from. Defaults to `username`. | `username` |

Comment on lines -23 to -25
| `gitToken` | An optional secret name in the `PipelineRun` namespace to fetch the token from when doing opration with the `git clone`. When empty it will use anonymous cloning. | `secret-gitauth-token` |
| `gitTokenKey` | An optional key in the token secret name in the `PipelineRun` namespace to fetch the token from when using the `git clone`. Defaults to `token`. | `token` |
| `revision` | Git revision to checkout a file from. This can be commit SHA (SHA-1 or SHA-256), branch or tag. | `aeb957601cf41c012be462827053a21a420befca` `main` `v0.38.2` |
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for cleaning up this whitespace!

| `default-revision` | The default git revision to use if none is specified | `main` |
| `fetch-timeout` | The maximum time any single git clone resolution may take. **Note**: a global maximum timeout of 1 minute is currently enforced on _all_ resolution requests. | `1m`, `2s`, `700ms` |
| `default-url` | The default git repository URL to use for anonymous cloning if none is specified. | `https://github.com/tektoncd/catalog.git` |
| `scm-type` | The SCM provider type. Required if using the authenticated API with `org` and `repo`. | `github`, `gitlab`, `gitea`, `bitbucketcloud`, `bitbucketserver` |
Copy link
Member

Choose a reason for hiding this comment

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

I think the whitespace alignment for this section is now misaligned with this row

# my-secret-token should be created in the namespace where the
# pipelinerun is created and contain a GitHub personal access
# token in the token key of the secret.
# token in the token key of the secret and a username depending on the git provider.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, rewording this so it's clear "depending on the git provider" refers specifically to the username requirement

Suggested change
# token in the token key of the secret and a username depending on the git provider.
# token in the token key of the secret and, if required by the git provider, a username.

// APISecretKeyKey is the config map key for the containing the token within the token secret
APISecretKeyKey = "api-token-secret-key"
// APIUsernameSecretKey is the config map key containing the username within the token secret
APIUsernameSecretKey = "api-username-secret-key"
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be unused outside of the tests

token, ok := secret.Data[apiSecret.tokenKey]
if !ok {
err := fmt.Errorf("cannot get API token, key %s not found in secret %s in namespace %s", apiSecret.key, apiSecret.name, apiSecret.ns)
err := fmt.Errorf("cannot get API token, key %s not found in secret %s in namespace %s", apiSecret.tokenKey, apiSecret.name, apiSecret.ns)
Copy link
Member

Choose a reason for hiding this comment

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

Might need a codeQL exception here, this is a safe change flagged by regex. Renaming the variable would work too, since I don't like the idea of disabling this check on a log line

Comment on lines +777 to 779
if tc.config[tc.configIdentifer+APIUsernameSecretKey] != "" {
secretUsernameKey = tc.config[tc.configIdentifer+APIUsernameSecretKey]
}
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, since empty string is also the zero value we can just do this:

Suggested change
if tc.config[tc.configIdentifer+APIUsernameSecretKey] != "" {
secretUsernameKey = tc.config[tc.configIdentifer+APIUsernameSecretKey]
}
secretUsernameKey = tc.config[tc.configIdentifer+APIUsernameSecretKey]

Copy link
Member

Choose a reason for hiding this comment

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

Though this is the only place we reference the username key in the configmap so might not be needed at all

Copy link
Member

Choose a reason for hiding this comment

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

It looks like this adds support for testing that the usernameKey is allowed and ensures the testcase initializes the usernamekey when necessary, however it doesn't appear that the test if the username was given to the git provider or API. When the code in ResolveApiGit and ResolveGitClone that uses the username key is removed, the test still passes

Comment on lines +485 to +490
type authCredentials struct {
token []byte
username []byte
}

func (g *GitResolver) getAPIToken(ctx context.Context, apiSecret *secretCacheKey, key string) ([]byte, error) {
func (g *GitResolver) getAuthenticationCredentials(ctx context.Context, apiSecret *secretCacheKey, key string) (*authCredentials, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I appreciate the use of types here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants