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

chore: Add an ability to manually configure bitbucket oAuth token #313

Merged
merged 10 commits into from
Jun 29, 2022

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Jun 10, 2022

Signed-off-by: Igor Vinokur ivinokur@redhat.com

What does this PR do?

Read user namespace oauth token before checking the oAuth configuration in case when user manually added a bitbucket oAuth secret to the user namespace.

Screenshot/screencast of this PR

What issues does this PR fix or reference?

eclipse-che/che#21189

How to test this PR?

  1. Deploy che with quay.io/ivinokur/che-server:next image.
  2. Deploy bitbucket server.
  3. Add a secret to the user namespace:
kind: Secret
apiVersion: v1
metadata:
  name: personal-access-token-<github/gitlab/bitbucket-server>
  namespace: <namespace name>
  labels:
    app.kubernetes.io/component: scm-personal-access-token
    app.kubernetes.io/part-of: che.eclipse.org
  annotations:
    che.eclipse.org/che-userid: <che user id>
    che.eclipse.org/scm-personal-access-token-name: <github/gitlab/bitbucket-server>
    che.eclipse.org/scm-userid: <github/gitlab/gitbucket-server user id>
    che.eclipse.org/scm-url: >-
      <github/gitlab/gitbucket-server endpoint Url>
    che.eclipse.org/scm-username: <github/gitlab/bitbucket-server username>
data:
  token: <base 64 encoded token>
type: Opaque

  1. Try to create a factory from the bitbucket server repo.

PR Checklist

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

Reviewers

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

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@vinokurig
Copy link
Contributor Author

@tolusha @ibuziuk please take a look

@@ -49,7 +49,6 @@ public String computeAuthorizationHeader(String userId, String requestMethod, St

@Override
public String getLocalAuthenticateUrl() {
throw new RuntimeException(
"The fallback noop authenticator cannot be used for authentication. Make sure OAuth is properly configured.");
return "Empty URL";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not to keep throwing RuntimeException ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid the exception when the NoopOAuthAuthenticator is used to create an API client with an empty authenticator:

@@ -57,9 +67,49 @@ public GitlabUrlParser(
}
}

private boolean userTokenExists(String url) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I can't easyaly combine this functions into one common, as they are located in separate maven modules.

vinokurig and others added 3 commits June 24, 2022 14:54
…rg/eclipse/che/api/factory/server/bitbucket/BitbucketURLParser.java

Co-authored-by: Anatolii Bazko <abazko@redhat.com>
…rg/eclipse/che/api/factory/server/bitbucket/BitbucketURLParser.java

Co-authored-by: Anatolii Bazko <abazko@redhat.com>
@@ -49,7 +49,6 @@ public String computeAuthorizationHeader(String userId, String requestMethod, St

@Override
public String getLocalAuthenticateUrl() {
throw new RuntimeException(
"The fallback noop authenticator cannot be used for authentication. Make sure OAuth is properly configured.");
return "Noop URL";
Copy link
Member

Choose a reason for hiding this comment

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

should be const. In general, why do we need a dummy implementation in the case if no Bitbucket Server
integration is configured? Could you please add more details in the Javadocs for this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be const.

This string is used only once, not sure we need a separate const for that.

In general, why do we need a dummy implementation in the case if no Bitbucket Server
integration is configured? Could you please add more details in the Javadocs for this class?

It is needed to initialise an empty BitbucketServerApiClient which returns false on isConnected() reqests. This is needed to check if bitbucket oAuth is configured or not. Updated the javadoc.

LOG.debug("not a valid url {} for current fetcher ", personalAccessToken.getScmProviderUrl());
return Optional.empty();
// If BitBucket oAuth is not configured check the manually added user namespace token.
HttpBitbucketServerApiClient apiClient =
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit lost in the flow, why are we trying to check the token if BitBucket server is not configured?

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 main idea of the PR is to be able to use manually added user namespace secrets with tokeen for the oAuth flow in case when oAuth is not configured by the admin.

@@ -57,9 +68,55 @@ public GitlabUrlParser(
}
}

private boolean isUserTokenExists(String repositoryUrl) {
Copy link
Member

Choose a reason for hiding this comment

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

grammatically it should be isUserTokenExist
also, since there is isPresent call, consider changing the name to isUserTokenPresent

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

@vinokurig vinokurig merged commit a47f115 into main Jun 29, 2022
@vinokurig vinokurig deleted the che-21189 branch June 29, 2022 08:17
@che-bot che-bot added this to the 7.50 milestone Jun 29, 2022
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