Skip to content
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

add alternate azure git repo urls to credentials for submodules #372

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

brettfo
Copy link
Contributor

@brettfo brettfo commented Oct 21, 2024

When a job is started with the azure provider, git_source credentials are provided for the dev.azure.com domain and that URL is ultimately used to clone the repo.

If a repo has a submodule and specifies the URL with the dev.azure.com format, everything is OK because the credentials are properly injected by the proxy, but there is an alternate format that's not handled: org.visualstudio.com/DefaultCollection/project/_git/repo and if a submodule clone is attempted with that URL, it's not detected as being functionally the same as the other URL and a 401 is returned, possibly making the job fail due to missing sources.

This PR adds the alternate org.visualstudio.com credentials.

A manual test was performed, first with the old behavior ensuring the 401 and again with the new behavior ensuring a correct 200 when cloning the submodule.

@brettfo brettfo requested a review from a team as a code owner October 21, 2024 23:02
input.Credentials = append(input.Credentials, model.Credential{
"type": "git_source",
"host": "dev.azure.com",
"username": "x-access-token",
"password": "$LOCAL_AZURE_ACCESS_TOKEN",
})
if len(input.Job.CredentialsMetadata) > 0 {
// Add the metadata since the next section will be skipped.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment is incorrect; the next section is not skipped and the CredentialsMetadata is correctly updated. The test has been modified to verify this.

for _, cred := range input.Credentials {
if cred["type"] != "git_source" && cred["type"] != "nuget_feed" {
t.Errorf("expected credentials to be either git_source or nuget_feed, got %s", cred["type"])
}
}

// Validate NuGet feeds
Copy link
Contributor Author

@brettfo brettfo Oct 21, 2024

Choose a reason for hiding this comment

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

This behavior is unchanged, but was not explicitly tested.

expectedGitCredentials := []string{
"dev.azure.com|org|$LOCAL_AZURE_ACCESS_TOKEN",
"dev.azure.com|x-access-token|$LOCAL_AZURE_ACCESS_TOKEN",
"org.visualstudio.com|x-access-token|$LOCAL_AZURE_ACCESS_TOKEN",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new URL that's added to the credentials.

actualCredentialsMetadataHosts = append(actualCredentialsMetadataHosts, host)
}

expectedGitCredentalsMetadataHosts := []string{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what the unnecessary deleted code did, just adding explicit verification here.

@jakecoffman jakecoffman added this pull request to the merge queue Oct 22, 2024
Merged via the queue into main with commit daf68a9 Oct 22, 2024
73 checks passed
@jakecoffman jakecoffman deleted the dev/brettfo/azure-git-urls branch October 22, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants