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 return secret token in the Oauth API #538

Merged
merged 1 commit into from
Aug 17, 2023
Merged

Do not return secret token in the Oauth API #538

merged 1 commit into from
Aug 17, 2023

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Aug 4, 2023

What does this PR do?

  • Remove the personalAccessTokenManager.get() call from the OAuth API getToken() method. The OAuth API must not know anything about PAT secrets. It should get tokens only by requesting an SCM provider OAuth API.
  • Fix validating the Bitbucket-Server PAT method by requesting user instead of requesting.

This prevents the code execution going to a recursive loop: bitbucketServerApiClient.getPersonalAccessToken() calls oauthApi.getToken() which referred to personalAccessTokenManager.getToken() which validated the token by calling scmPersonalAccessTokenFetcher.getScmUsername() -> bitbucketServerApiClient.getPersonalAccessToken().

Screenshot/screencast of this PR

What issues does this PR fix or reference?

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

How to test this PR?

  1. Setup bitbucket-server oauth
  2. Start a workspace from the bitbucket-server repo to initiate the OAuth exchange.
  3. Go to dashboard -> User preferences -> Personal Access Tokens tab and add a new bitbucket-server token. You can use a random string for the token input.

See: the token creation is rejected, but no backend errors appear.

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.

throw new UnauthorizedException(
"OAuth token for user " + subject.getUserId() + " was not found");
} catch (IOException | ScmConfigurationPersistenceException | ScmCommunicationException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That snippet above was add as a part of #408
Could you check if that functionality still works?

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, I have checked the revoke token functionality and it works fine.

@vinokurig
Copy link
Contributor Author

/retest

Comment on lines -162 to -167
Optional<PersonalAccessToken> tokenOptional =
personalAccessTokenManager.get(subject, provider.getEndpointUrl());
if (tokenOptional.isPresent()) {
PersonalAccessToken accessToken = tokenOptional.get();
return newDto(OAuthToken.class).withToken(accessToken.getToken());
}
Copy link
Member

Choose a reason for hiding this comment

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

@vinokurig why have we got PAT as part of OAuth flow in general and now removing it?

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 believe this was added by a mistake.

Copy link
Contributor

@dmytro-ndp dmytro-ndp left a comment

Choose a reason for hiding this comment

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

I was able to continue working with Eclipse Che after executing of step 3:

  1. Che Setup bitbucket-server oauth
    Start a workspace from the bitbucket-server repo to initiate the OAuth exchange.
    Go to dashboard -> User preferences -> Personal Access Tokens tab and add a new bitbucket-server token. You can use a random string for the token input.

Screenshot from 2023-08-15 18-03-03

There was no "backend is not available" error [1] observed.

@vinokurig : could you please prepare backport PR to 7.72.x branch for review to make the fix available in DS 3.8.0?

[1] https://issues.redhat.com/browse/CRW-4351

@openshift-ci
Copy link

openshift-ci bot commented Aug 17, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dmytro-ndp, ibuziuk, tolusha, 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 f5a70d0 into main Aug 17, 2023
4 checks passed
@vinokurig vinokurig deleted the CRW-4351 branch August 17, 2023 13:29
@devstudio-release
Copy link

Build 3.9 :: server_3.x/197: Console, Changes, Git Data

vinokurig added a commit that referenced this pull request Aug 17, 2023
Remove the personalAccessTokenManager.get() call from the OAuth API getToken() method. The OAuth API must not know anything about PAT secrets. It should get tokens only by requesting an SCM provider OAuth API.
Fix validating the Bitbucket-Server PAT method by requesting user instead of requesting.
This prevents the code execution going to a recursive loop: bitbucketServerApiClient.getPersonalAccessToken() calls oauthApi.getToken() which referred to personalAccessTokenManager.getToken() which validated the token by calling scmPersonalAccessTokenFetcher.getScmUsername() -> bitbucketServerApiClient.getPersonalAccessToken().
@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.9 :: server_3.x/197: SUCCESS

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

@devstudio-release
Copy link

Build 3.9 :: update-digests_3.x/3954: Console, Changes, Git Data

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.9 :: get-sources-rhpkg-container-build_3.x/3898: FAILURE

devspaces-operator-bundle : 3.x :: Failed in : BREW:BUILD/STATUS:UNKNOWN
FAILURE:; copied to quay

@devstudio-release
Copy link

Build 3.9 :: server_3.x/198: Console, Changes, Git Data

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.9 :: get-sources-rhpkg-container-build_3.x/3924: FAILURE

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

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