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

[Broker/Proxy] Prevent invalid broker or proxy configuration for authorization #9746

Merged

Conversation

lhotari
Copy link
Member

@lhotari lhotari commented Feb 27, 2021

Fixes #9709

Motivation

Enabling authorization without enabling authentication leads to inconsistent behavior.

In some parts of the code, authorization is enforced only when both authorization is enabled and authentication is enabled. In a few places, it's enforced if authorization is enabled without checking for authentication.

To prevent misleading behavior, it's better to check at startup time that authentication is enabled when authorization is enabled.

There's also changes to make Pulsar configuration more consistent in tests by resetting the configuration in the cleanup method.

Modifications

  • check the configuration before starting the Pulsar broker or Pulsar proxy
  • fix AuthorizationTest where authentication configuration was missing
    • add the necessary authentication configuration for the test
  • reset Pulsar configuration in MockedPulsarServiceBaseTest.internalCleanup method
    • this helps prevent inconsistent state in tests. Currently Pulsar configuration is inconsistent since it depends on the execution of previous test methods. Some test methods mutate the configuration and the next test method will use the configuration unless it's resetted explicitly.

About the fix to flaky test AuthorizationTest.simple

This change fixes the flaky test #9709, but it remains unclear why the test was passing in some cases.
It seems that the test is picking up state from some other test run. There are interesting observations in PR #9740 about the reasons why it passes in some cases.
Some effort was put into checking if the usage of Jersey / JAX RS @Context annotation on the PulsarWebResource's httpRequest field could be causing some concurrency issue, but that verification didn't reveal issues.

@315157973
Copy link
Contributor

/pulsarbot run-failure-checks

@lhotari lhotari marked this pull request as draft March 1, 2021 05:11
@lhotari lhotari force-pushed the lh-prevent-invalid-authorization-config branch from 50997e3 to e5a0811 Compare March 1, 2021 14:21
@lhotari lhotari marked this pull request as ready for review March 1, 2021 14:45
@lhotari
Copy link
Member Author

lhotari commented Mar 1, 2021

/pulsarbot run-failure-checks

@lhotari lhotari force-pushed the lh-prevent-invalid-authorization-config branch 2 times, most recently from 27247b4 to 9d08f62 Compare March 2, 2021 18:38
@lhotari
Copy link
Member Author

lhotari commented Mar 3, 2021

/pulsarbot run-failure-checks

@lhotari lhotari marked this pull request as draft March 4, 2021 20:47
@lhotari
Copy link
Member Author

lhotari commented Mar 4, 2021

I'll check the test failures tomorrow.

### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.
@lhotari lhotari force-pushed the lh-prevent-invalid-authorization-config branch from a8b0929 to 70ccd3d Compare March 5, 2021 08:56
@lhotari lhotari marked this pull request as ready for review March 5, 2021 08:58
@lhotari
Copy link
Member Author

lhotari commented Mar 5, 2021

/pulsarbot run-failure-checks

1 similar comment
@lhotari
Copy link
Member Author

lhotari commented Mar 5, 2021

/pulsarbot run-failure-checks

@lhotari lhotari mentioned this pull request Mar 5, 2021
@lhotari lhotari requested a review from merlimat March 5, 2021 17:48
@merlimat merlimat merged commit dfa81d9 into apache:master Mar 5, 2021
mlyahmed pushed a commit to mlyahmed/pulsar that referenced this pull request Mar 7, 2021
…9746)

### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.
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.

Flaky-test: AuthorizationTest.simple
4 participants