Skip to content

core(gitdns-fix): ensure that gitdns support token support works with all Git server providers - #8778

Merged
grouville merged 4 commits into
dagger:mainfrom
grouville:gitdns-multiprovider
Nov 6, 2024
Merged

grouville merged 4 commits into
dagger:mainfrom
grouville:gitdns-multiprovider

Conversation

@grouville

Copy link
Copy Markdown
Member

Bitbucket Cloud requires a specific auth format for Git operations using tokens, where the username must be 'x-token-auth'. This fixes token authentication for Bitbucket while maintaining compatibility with other Git providers like GitHub and GitLab, and Azure.

Context for Bitbucket Token Handling

Our implementation for Bitbucket Cloud authentication is based on the Repository Access Tokens Documentation, which specifically covers Git operations. While Bitbucket's HTTP Access Tokens Documentation suggests using Bearer authentication for some cases, this appears to only be working for to REST API calls (upon personal tests).

For Git operations, the documentation recommends using x-token-auth as the username, with the token as password, regardless of the token type. After testing both user tokens and repository tokens, I found that Bearer authentication did not work reliably for Git operations, leading my choice to always rely on that for bitbucket auth

@grouville
grouville force-pushed the gitdns-multiprovider branch 3 times, most recently from eda001a to 7883173 Compare October 29, 2024 17:01

@sipsma sipsma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should add a changelog for this, otherwise LGTM

Comment thread engine/sources/gitdns/source.go Outdated
if s.token {
dt = []byte("basic " + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("x-access-token:%s", dt))))

if strings.Contains(gs.src.Remote, "bitbucket.org") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: maybe we should just check the host here? e.g. we don't want to do this for something weird like [email protected]:jedevc/bitbucket.org

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.

thanks 🙏

Comment thread engine/sources/gitdns/source.go Outdated
Comment on lines +255 to +259
gs.auth = []string{
"-c", fmt.Sprintf("credential.helper=!f() { echo \"username=x-token-auth\"; echo \"password=%s\"; }; f", string(dt)),
"-c", "credential.https://bitbucket.org.username=x-token-auth",
"-c", "credential.useHttpPath=true",
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: I would apply the logic for detecting this in authSecretNames, and then extend authSecret to have a credhelper bool property. This keeps the logic decoupled, but also means that we don't end up trying to put AuthHeaderSecretss as passwords (we should only put the tokens there).

If this is called using an AuthHeader, we shouldn't be plugging the entire auth header in as a password - we should plug it in as a header as requested. It's only for the AuthToken that we want to apply the logic in this PR.

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.

agreed, updated 🙏

@jedevc jedevc added the needs/changelog Pull requests that require a changelog entry label Oct 30, 2024
@grouville
grouville force-pushed the gitdns-multiprovider branch from 7883173 to b4402bf Compare November 3, 2024 22:11
@grouville
grouville requested a review from jedevc November 3, 2024 22:25
@grouville grouville added this to the v0.14.0 milestone Nov 6, 2024
Guillaume de Rouville and others added 4 commits November 6, 2024 17:58
server providers

Bitbucket Cloud requires a specific auth format for Git operations using
tokens, where the username must be 'x-token-auth'. This fixes token
authentication for Bitbucket while maintaining compatibility with other
Git providers like GitHub and GitLab, and Azure.

Signed-off-by: Guillaume de Rouville <[email protected]>
As we realized that gitdns auth token implementation was breaking
against bitbucket, this commit adds a full integration test suite
against real providers:
- github
- gitlab
- bitbucket

Azure does not enable us to have a pat without a deadline, but this was
manually tested

Signed-off-by: Guillaume de Rouville <[email protected]>
Move the logic for determining authentication methods (Bitbucket credential helper) from getAuthToken to authSecretNames

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Guillaume de Rouville <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs/changelog Pull requests that require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants