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

Added authorization checks for BrokerService's JSON RPC methods #11092

Merged
merged 1 commit into from
Sep 7, 2018

Conversation

sleshchenko
Copy link
Member

What does this PR do?

Adds authorization checks for BrokerService's JSON RPC methods. Only user who has run permission is allowed to call broker/result and broker/statusChanged workspace related methods.

What issues does this PR fix or reference?

#11080

Release Notes

N/A

Docs PR

N/A

@sleshchenko sleshchenko added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/task Internal things, technical debt, and to-do tasks to be performed. labels Sep 6, 2018
@sleshchenko sleshchenko self-assigned this Sep 6, 2018
Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

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

Looks good!
Please, take a look at my inlined comments.


@AfterMethod
public void tearDown() {
EnvironmentContext.reset();

Choose a reason for hiding this comment

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

I would add operations that would throw some custom exception when unexpected permissions check is executed in tests. This would ensure that there are no similar bugs in the code and tests at the same time. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I'll do it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try to implement what you suggested but it fails

...
public class BrokerServicePermissionFilterTest {
  ...

  @BeforeMethod
  public void setUp() {
    EnvironmentContext.getCurrent().setSubject(subject);
    when(subject.hasPermission(any(), any(), any())).thenThrow(new IllegalArgumentException());
    permissionFilter = new BrokerServicePermissionFilter();
  }

...
  @Test(
      dataProvider = "coveredMethods",
      expectedExceptions = ForbiddenException.class,
      expectedExceptionsMessageRegExp =
          "User doesn't have the required permissions to the specified workspace")
  public void shouldThrowExceptionIfUserDoesNotHaveRunPermission(String method) throws Exception {

    // !!!!!!!!!!!!!!!!
    //  java.lang.IllegalArgumentException is thrown here

    // given
    when(subject.hasPermission(eq(WorkspaceDomain.DOMAIN_ID), eq("ws123"), eq(WorkspaceDomain.RUN)))
        .thenReturn(false);

    // when
    permissionFilter.doAccept(
        method, DtoFactory.newDto(BrokerResultEvent.class).withWorkspaceId("ws123"));
  }
  ...
}

So, looks like mockito make invocation method on defining new method behavior

    when(subject.hasPermission(eq(WorkspaceDomain.DOMAIN_ID), eq("ws123"), eq(WorkspaceDomain.RUN)))
        .thenReturn(false);

And java.lang.IllegalArgumentException is thrown since there is defined behavior for any values of parameters.

If you know how to implement it in another simple way - I'll be happy to do it.

Choose a reason for hiding this comment

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

ok

@@ -305,7 +305,9 @@ private void configureMultiUserMode(
if (OpenShiftInfrastructure.NAME.equals(infrastructure)
|| KubernetesInfrastructure.NAME.equals(infrastructure)) {
install(new ReplicationModule(persistenceProperties));

bind(

Choose a reason for hiding this comment

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

Can you elaborate why this is specific to the infra implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because BrokerService is kubernetes specific component that is bound only for Kubernetes and OpenShift infrastructures. Does it make sense?

Choose a reason for hiding this comment

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

yes, not sure it should be really specific to the k8s in general, but I'm fine with that for the time being

@sleshchenko
Copy link
Member Author

ci-test

@riuvshin
Copy link
Contributor

riuvshin commented Sep 6, 2018

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:11092
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@sleshchenko
Copy link
Member Author

Maven build is failed because of build error in Che Dockerfiles :: Theia module that is not changed in my PR. Will rerun tests again

@sleshchenko
Copy link
Member Author

ci-test

@riuvshin
Copy link
Contributor

riuvshin commented Sep 6, 2018

ci-test build report:
Build details
Test report
selenium tests report data
docker image: eclipseche/che-server:11092
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@sleshchenko sleshchenko merged commit 6a6c7f7 into eclipse-che:master Sep 7, 2018
@sleshchenko sleshchenko deleted the brokerServiceFilter branch September 7, 2018 04:06
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Sep 7, 2018
@benoitf benoitf added this to the 6.11.0 milestone Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/task Internal things, technical debt, and to-do tasks to be performed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants