Skip to content

Add Azure DevOps Server support#754

Merged
vinokurig merged 3 commits intomainfrom
che-23306
Mar 13, 2025
Merged

Add Azure DevOps Server support#754
vinokurig merged 3 commits intomainfrom
che-23306

Conversation

@vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Jan 20, 2025

What does this PR do?

Depends on eclipse-che/che-dashboard#1313

Screenshot/screencast of this PR

What issues does this PR fix or reference?

fixes eclipse-che/che#23306

How to test this PR?

  1. Deploy che with the pull request image: quay.io/eclipse/che-server:pr-754.
  2. In the Dev azure Server instance create a personal access token with full access.
  3. Create a personal access token, use the Organization input to enter the Collection name.
  4. Start a workspace from an azure devops server repository with a devfile.

See: workspace starts with the devfile resolve.

PR Checklist

As the author of this Pull Request I made sure that:

Release Notes

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@vinokurig vinokurig marked this pull request as draft January 20, 2025 14:40
@vinokurig vinokurig force-pushed the che-23306 branch 2 times, most recently from 259113e to 4c865ce Compare January 21, 2025 12:58
@vinokurig vinokurig marked this pull request as ready for review January 21, 2025 13:35
@vinokurig
Copy link
Contributor Author

/retest

1 similar comment
@vinokurig
Copy link
Contributor Author

/retest

}

public AzureDevOpsUrl withServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
Copy link
Contributor

Choose a reason for hiding this comment

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

When use set serverUrl, then hostname is null, which is used later in getRepositoryLocation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hostName does not rely on serverUrl, we set it independently:

return new AzureDevOpsUrl()
.withHostName(
url.startsWith("git@ssh.") ? azureDevOpsScmApiEndpointHost : URI.create(url).getHost())

if (!isValidScmServerUrl(params.getScmProviderUrl())) {
LOG.debug("not a valid url {} for current fetcher ", params.getScmProviderUrl());
return Optional.empty();
if (OAUTH_PROVIDER_NAME.equals(params.getScmProviderName())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we refactor this fuction?
For instance, move if (OAUTH_PROVIDER_NAME.equals(params.getScmProviderName())) { before if (!isValidScmServerUrl(params.getScmProviderUrl())) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to check if the token belongs to Azure DevOps SAAS or Server first. The isValidScmServerUrl function name is a bit misleading, so I renamed it.

azureDevOpsApiClient.getUserWithPAT(
personalAccessToken.getToken(), personalAccessToken.getScmOrganization());
return new GitUserData(user.getDisplayName(), user.getEmailAddress());
if (personalAccessToken.getScmProviderUrl().equals("https://dev.azure.com")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have AzureDevOps class for contants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

} catch (ScmUnauthorizedException e) {
return true;
// the error message is a JSON if it is a response from Gitlab.
return e.getMessage().startsWith("{");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this changes in context of azure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to specify the unauthorized exception as Azure also returns an unauthorized exception in this case.

Copy link
Member

Choose a reason for hiding this comment

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

what is the response from Azure in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the json validation check to a separate private function, enhanced the check with JSON parser and updated the Javadoc.


private Optional<Matcher> getPatternMatcherByUrl(String url) {
String host = URI.create(url).getHost();
Matcher matcher = compile(format(azureDevOpsPatternTemplate, host)).matcher(url);

Check failure

Code scanning / CodeQL

Regular expression injection High

This regular expression is constructed from a
user-provided value
.
This regular expression is constructed from a
user-provided value
.
This regular expression is constructed from a
user-provided value
.
if (matcher.matches()) {
return Optional.of(matcher);
} else {
matcher = compile(format(azureSSHDevOpsPatternTemplate, host)).matcher(url);

Check failure

Code scanning / CodeQL

Regular expression injection High

This regular expression is constructed from a
user-provided value
.
This regular expression is constructed from a
user-provided value
.
This regular expression is constructed from a
user-provided value
.
if (matcher.matches()) {
return Optional.of(matcher);
} else {
matcher = compile(format(azureSSHDevOpsServerPatternTemplate, host)).matcher(url);

Check failure

Code scanning / CodeQL

Regular expression injection High

This regular expression is constructed from a
user-provided value
.
This regular expression is constructed from a
user-provided value
.
This regular expression is constructed from a
user-provided value
.
@vinokurig vinokurig closed this Feb 5, 2025
@vinokurig vinokurig deleted the che-23306 branch February 5, 2025 14:01
@vinokurig vinokurig restored the che-23306 branch February 5, 2025 14:01
@vinokurig vinokurig reopened this Feb 5, 2025
@vinokurig vinokurig force-pushed the che-23306 branch 2 times, most recently from 80c8b96 to 12721bc Compare February 6, 2025 12:00
@vinokurig vinokurig marked this pull request as draft February 7, 2025 08:43
@vinokurig vinokurig force-pushed the che-23306 branch 4 times, most recently from cfaf300 to 95d556a Compare February 10, 2025 08:40
@vinokurig vinokurig force-pushed the che-23306 branch 2 times, most recently from 2e1f709 to 3531467 Compare February 10, 2025 10:53
Comment on lines -115 to +120
return true;
// Some Git providers e.g. Azure Devops Server, may return unauthorized exception on invalid
// API request, but Gitlab API returns unauthorized error message in JSON format, so to be
// sure that the URL belongs to Gitlab, we need to check if the error message is a valid
// JSON.
return isJsonValid(e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

@vinokurig I'm a bit lost with Gitlab change in general.
Could you clarify why are we changing AbstractGitlabUrlParser.java in the context of the Azure TFS onboarding? How come GitLab flow is affected by the Azure Devops Server ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we resolve a factory url we iterate over provider implementations and check if the url corresponds to any known implemented provider.
In the Gitlab implementation, when we resolve a public Gitlab Server repo url but neither oauth is configured nor a PAT is added, we use the isApiRequestRelevant()function:
The function extracts the server url from the repository url and with this server url we make a test Gitlab Server API call. The idea is: if the test api call returns unauthorised error, it means that the extracted server url is a Gitlab Server url and we treat the repository url as a Gitlab Server url.

The problem is that Azure Devops Server Api returns unauthorized response on any invalid API request, so when we iterate the Azure repo url through the Gitlab implementation, the url is tested by the isApiRequestRelevant()function and according to the response status it becomes a Gitlab url.

To be able to distinguish the unauthorized response of Azure Devops Server url and Gitlab Server url, we check the error message format, if it is in JSON format, we can assume that the url is a Gitlab repo, but if the error message is a plain text, we continue the iteration because the url is an Azure Devops Server repo.

Copy link
Member

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

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

@artaleks9 @dmytro-ndp folks, please provide your approval before merging as well. Looks like Gitlab test is failing right now (please make sure that all PR checks are merged before we merge)

@openshift-ci openshift-ci bot added lgtm and removed lgtm labels Feb 28, 2025
@openshift-ci
Copy link

openshift-ci bot commented Mar 3, 2025

@vinokurig: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/v14-gitlab-with-oauth-setup-flow 7681e71 link true /test v14-gitlab-with-oauth-setup-flow

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@dmytro-ndp
Copy link
Contributor

dmytro-ndp commented Mar 4, 2025

@vinokurig : after the review of this feature demo, I can admit that adding extraheader under the [http] section manually, with need to encode the personal access token and enter it in the 'Import Git Config' text area of User Preferences, could be a challenge for regular user.
Do you think it's possible to get rid of this step by reusing existing Personal Access Token entered on the 'User Preferences > Personal Access Token' page?

@vinokurig
Copy link
Contributor Author

vinokurig commented Mar 4, 2025

@dmytro-ndp
That's a good point, we have discussed it with @ibuziuk and decided to keep the manual flow to be sure that this logic will not break the factory flow with other providers. Since we are adding authorization header to all git requests we want user to be aware of that and if something goes wrong, the user will be able to revert the header.
When we are sure that this is safe we will add a mechanism that will automatically add the configuration to the workspace gitconfig.

@SkorikSergey
Copy link
Contributor

@vinokurig : hello
FYI:

verification of eclipse-che/che#23306 issue fix up has been passed.

See test details below:

Test scenario to check eclipse-che/che#23306 issue:

  1. Deploy che with the pull request image: quay.io/eclipse/che-server:pr-754.
  2. In the Dev azure Server instance create a personal access token with full access.
  3. Create a personal access token, use the Organization input to enter the Collection name.
  4. Change gitconfig according to documentation
  5. Start a workspace from an azure devops server repository with a devfile.
  6. Create new file and commit changes to new brach.
  7. Push changes and check them on Azure Server test repo page.

@openshift-ci
Copy link

openshift-ci bot commented Mar 12, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ibuziuk, SkorikSergey, vinokurig

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

@SkorikSergey
Copy link
Contributor

SkorikSergey commented Mar 12, 2025

@vinokurig After adding token according to this documentation I have also started workspace from private repo GitHub Enterprise Server(OAuth accepted). Workspace started successfully but project was not cloned. After removing token from gitconfig works as expected.
Selection_101
Selection_099

@ibuziuk
Copy link
Member

ibuziuk commented Mar 12, 2025

@vinokurig I think we should at very least mention this caveat in the docs

@vinokurig vinokurig merged commit 870aed1 into main Mar 13, 2025
26 of 28 checks passed
@vinokurig vinokurig deleted the che-23306 branch March 13, 2025 07:20
@devspacesbuild
Copy link

Build 3.20 :: server_3.x/389: Console, Changes, Git Data

@devspacesbuild
Copy link

@devspacesbuild
Copy link

@vinokurig vinokurig mentioned this pull request Mar 13, 2025
9 tasks
@devspacesbuild
Copy link

Build 3.20 :: get-sources-rhpkg-container-build_3.x/9021: FAILURE

server : 3.x :: Failed in 66972204 : BREW:BUILD/STATUS:UNKNOWN
FAILURE:; copied to quay

vinokurig added a commit that referenced this pull request Mar 13, 2025
Fix the build failure caused by merging #754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Microsoft Azure DevOps Server (TFS)

6 participants