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

Do not validate bitbucket server token scopes #706

Merged
merged 1 commit into from
Jul 29, 2024
Merged

Do not validate bitbucket server token scopes #706

merged 1 commit into from
Jul 29, 2024

Conversation

vinokurig
Copy link
Contributor

What does this PR do?

BitBucket Server get token() API method does not work with PAT token. It returns unauthorised exception. Omit the BitBucket Server token skopes check because there is not other way to get the token scopes.

Screenshot/screencast of this PR

What issues does this PR fix or reference?

https://issues.redhat.com/browse/CRW-4560

How to test this PR?

  1. Configure BitBucket Server Oauth
  2. Start a workspace from the BitBucket Server repository url.
  3. Apply the authorization agreement.
    See workspace starts successfully, a new Personal Access Token item is created in the dashboard user preferences page.

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.

@vinokurig
Copy link
Contributor Author

/retest

@tolusha
Copy link
Contributor

tolusha commented Jul 23, 2024

From my understanding, if we won't validate scopes, then user might occur issue while using token with git operations.
BTW, We don't validate scopes for Azure Dev Ops as well, because of lack of API.

@vinokurig
Copy link
Contributor Author

@tolusha

From my understanding, if we won't validate scopes, then user might occur issue while using token with git operations.

We generate Oauth tokens with predefined list of scopes:

BitbucketPersonalAccessToken token =
bitbucketServerApiClient.createPersonalAccessTokens(tokenName, DEFAULT_TOKEN_SCOPE);

so there is no way user can have an Oauth token with another scopes. As for PATs, we do not validate scopes for BitBucket Server at all.

@artaleks9
Copy link
Contributor

Verified on Eclipse Che with quay.io/eclipse/che-server:pr-706 - the functionality works properly.

Comment on lines -182 to -196
// Token is added manually by a user without token id. Validate only by requesting user info.
if (isNullOrEmpty(params.getScmTokenId())) {
BitbucketUser user = bitbucketServerApiClient.getUser(params.getToken());
return Optional.of(Pair.of(Boolean.TRUE, user.getName()));
}
// Token is added by OAuth. Token id is available.
BitbucketPersonalAccessToken bitbucketPersonalAccessToken =
bitbucketServerApiClient.getPersonalAccessToken(
params.getScmTokenId(), params.getToken());
return Optional.of(
Pair.of(
DEFAULT_TOKEN_SCOPE.equals(bitbucketPersonalAccessToken.getPermissions())
? Boolean.TRUE
: Boolean.FALSE,
bitbucketPersonalAccessToken.getUser().getName()));
Copy link
Member

Choose a reason for hiding this comment

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

@vinokurig could BitBucket OAuth be affected by this change? why scope validation was in place before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could BitBucket OAuth be affected by this change?

I do not think so because the commit just simplifies the check, it does not add new requests or stuff like that.

why scope validation was in place before?

I believe this was copied from the GitHub token fetcher:

if (params.getScmTokenName() != null && params.getScmTokenName().startsWith(OAUTH_2_PREFIX)) {
Pair<String, String[]> pair = apiClient.getTokenScopes(params.getToken());
return Optional.of(
Pair.of(
containsScopes(pair.second, DEFAULT_TOKEN_SCOPES) ? Boolean.TRUE : Boolean.FALSE,
pair.first));

Copy link

openshift-ci bot commented Jul 25, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

@vinokurig vinokurig merged commit 370c40f into main Jul 29, 2024
28 checks passed
@vinokurig vinokurig deleted the CRW-4560 branch July 29, 2024 07:45
@devstudio-release
Copy link

Build 3.16 :: server_3.x/351: Console, Changes, Git Data

@devstudio-release
Copy link

Build 3.16 :: server_3.x/352: Console, Changes, Git Data

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.16 :: server_3.x/351: SUCCESS

Upstream sync done; /DS_CI/sync-to-downstream_3.x/7327 triggered

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.16 :: server_3.x/352: SUCCESS

Upstream sync done; /DS_CI/sync-to-downstream_3.x/7328 triggered

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.16 :: copyIIBsToQuay/2724: Console, Changes, Git Data

@devstudio-release
Copy link

Build 3.16 :: sync-to-downstream_3.x/7331: SUCCESS

Build container: devspaces-operator-bundle synced; /DS_CI/get-sources-rhpkg-container-build_3.x/7315 triggered; /job/DS_CI/job/dsc_3.x triggered;

@devstudio-release
Copy link

Build 3.16 :: operator-bundle_3.x/3365: SUCCESS

Upstream sync done; /DS_CI/sync-to-downstream_3.x/7331 triggered

@devstudio-release
Copy link

Build 3.16 :: dsc_3.x/1962: Console, Changes, Git Data

@devstudio-release
Copy link

Build 3.16 :: update-digests_3.x/7172: SUCCESS

Detected new images: rebuild operator-bundle
* server; /DS_CI/operator-bundle_3.x/3365 triggered

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.16 :: update-digests_3.x/7173: UNSTABLE

No new images detected: nothing to do!

@devstudio-release
Copy link

Build 3.16 :: dsc_3.x/1962: SUCCESS

3.16.0-CI

@devstudio-release
Copy link

Build 3.16 :: copyIIBsToQuay/2724: SUCCESS

3.16
arches = x86_64, s390x, ppc64le;
  * LATEST DS OPERATOR BUNDLE = <a href=https://quay.io/repository/devspaces/devspaces-operator-bundle?tab=tags>registry-proxy.engineering.redhat.com/rh-osbs/devspaces-operator-bundle:3.16-19
  * LATEST DWO OPERATOR BUNDLE = <a href=https://quay.io/repository/devworkspace/devworkspace-operator-bundle?tab=tags>registry-proxy.engineering.redhat.com/rh-osbs/devworkspace-operator-bundle:???
+ x86_64-rhel8 IIB(s) copied:
  + <a href=https://quay.io/devspaces/iib:3.16-v4.16-776943- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64>quay.io/devspaces/iib:3.16-v4.16-776943- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64
  + quay.io/devspaces/iib:3.16-v4.16-x86_64
  + <a href=https://quay.io/devspaces/iib:3.16-v4.15-777174- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64>quay.io/devspaces/iib:3.16-v4.15-777174- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64
  + quay.io/devspaces/iib:3.16-v4.15-x86_64
  + <a href=https://quay.io/devspaces/iib:3.16-v4.14-777173- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64>quay.io/devspaces/iib:3.16-v4.14-777173- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64
  + quay.io/devspaces/iib:3.16-v4.14-x86_64
  + <a href=https://quay.io/devspaces/iib:3.16-v4.13-777172- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64>quay.io/devspaces/iib:3.16-v4.13-777172- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64
  + quay.io/devspaces/iib:3.16-v4.13-x86_64
  + <a href=https://quay.io/devspaces/iib:3.16-v4.12-777171- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64>quay.io/devspaces/iib:3.16-v4.12-777171- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-x86_64
  + quay.io/devspaces/iib:3.16-v4.12-x86_64
+ ppc64le-rhel8 IIB(s) copied:
  + <a href=https://quay.io/devspaces/iib:3.16-v4.16-776943- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le>quay.io/devspaces/iib:3.16-v4.16-776943- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le
  + quay.io/devspaces/iib:3.16-v4.16-ppc64le
  + <a href=https://quay.io/devspaces/iib:3.16-v4.15-777174- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le>quay.io/devspaces/iib:3.16-v4.15-777174- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le
  + quay.io/devspaces/iib:3.16-v4.15-ppc64le
  + <a href=https://quay.io/devspaces/iib:3.16-v4.14-777173- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le>quay.io/devspaces/iib:3.16-v4.14-777173- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le
  + quay.io/devspaces/iib:3.16-v4.14-ppc64le
  + <a href=https://quay.io/devspaces/iib:3.16-v4.13-777172- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le>quay.io/devspaces/iib:3.16-v4.13-777172- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le
  + quay.io/devspaces/iib:3.16-v4.13-ppc64le
  + <a href=https://quay.io/devspaces/iib:3.16-v4.12-777171- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le>quay.io/devspaces/iib:3.16-v4.12-777171- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-ppc64le
  + quay.io/devspaces/iib:3.16-v4.12-ppc64le
+ s390x-rhel8 IIB(s) copied:
  + <a href=https://quay.io/devspaces/iib:3.16-v4.16-776943- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x>quay.io/devspaces/iib:3.16-v4.16-776943- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x
  + quay.io/devspaces/iib:3.16-v4.16-s390x
  + <a href=https://quay.io/devspaces/iib:3.16-v4.15-777174- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x>quay.io/devspaces/iib:3.16-v4.15-777174- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x
  + quay.io/devspaces/iib:3.16-v4.15-s390x
  + <a href=https://quay.io/devspaces/iib:3.16-v4.14-777173- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x>quay.io/devspaces/iib:3.16-v4.14-777173- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x
  + quay.io/devspaces/iib:3.16-v4.14-s390x
  + <a href=https://quay.io/devspaces/iib:3.16-v4.13-777172- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x>quay.io/devspaces/iib:3.16-v4.13-777172- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x
  + quay.io/devspaces/iib:3.16-v4.13-s390x
  + <a href=https://quay.io/devspaces/iib:3.16-v4.12-777171- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x>quay.io/devspaces/iib:3.16-v4.12-777171- /tmp/getIIBsForBundle.sh -t PROD_VER [OPTIONS]-s390x
  + quay.io/devspaces/iib:3.16-v4.12-s390x

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.

5 participants