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

fix: respect authentication.skip.paths properly #9224

Merged
merged 3 commits into from Jun 27, 2022

Conversation

agavra
Copy link
Contributor

@agavra agavra commented Jun 24, 2022

Description

fixes #9206 by respecting the authentication.skip.paths in KsqlAuthorizationProviderHandler.java

Testing done

spun up CFK with MTLS and RBAC enabled on the normal endpoints. see relevant portion of configuration:

    authentication.skip.paths=/chc*,/heartbeat,/lag
    bootstrap.servers=kafka.operator-feyrhf.svc.cluster.local:9073
    config.providers=file
    config.providers.file.class=org.apache.kafka.common.config.provider.FileConfigProvider
    confluent.metadata.basic.auth.user.info=${file:/mnt/secrets/ksqldb-mds-client/bearer.txt:username}:${file:/mnt/secrets/ksqldb-mds-client/bearer.txt:password}
    confluent.metadata.bootstrap.server.urls=https://kafka.operator-feyrhf.svc.cluster.local:8090
    confluent.metadata.http.auth.credentials.provider=BASIC
    confluent.metadata.ssl.truststore.location=/mnt/sslcerts/truststore.jks
    confluent.metadata.ssl.truststore.password=${file:/mnt/sslcerts/jksPassword.txt:jksPassword}
    ksql.authentication.plugin.class=io.confluent.ksql.security.VertxBearerOrBasicAuthenticationPlugin
    ksql.heartbeat.enable=true
    ksql.lag.reporting.enable=true
    ksql.query.pull.enable.standby.reads=true
    ksql.security.extension.class=io.confluent.ksql.security.KsqlConfluentSecurityExtension
    ksql.streams.num.standby.replicas=1
    sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required metadataServerUrls="https://kafka.operator-feyrhf.svc.cluster.local:8090" username="${file:/mnt/secrets/ksqldb-mds-client/bearer.txt:username}" password="${file:/mnt/secrets/ksqldb-mds-client/bearer.txt:password}";
    sasl.login.callback.handler.class=io.confluent.kafka.clients.plugins.auth.token.TokenUserLoginCallbackHandler
    sasl.mechanism=OAUTHBEARER
    security.protocol=SASL_SSL
    ssl.enabled.protocols=TLSv1.2
    ssl.key.password=${file:/mnt/sslcerts/jksPassword.txt:jksPassword}
    ssl.keystore.location=/mnt/sslcerts/keystore.jks
    ssl.keystore.password=${file:/mnt/sslcerts/jksPassword.txt:jksPassword}
    ssl.truststore.location=/mnt/sslcerts/truststore.jks
    ssl.truststore.password=${file:/mnt/sslcerts/jksPassword.txt:jksPassword}

setting up unit testing for this is nigh impossible and the fix is blocking production users

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@agavra agavra requested a review from a team as a code owner June 24, 2022 22:25
@agavra agavra changed the base branch from master to 6.2.x June 24, 2022 22:26
@agavra agavra changed the base branch from 6.2.x to 6.0.x June 24, 2022 22:30
}

@Override
public void handle(final RoutingContext routingContext) {

final String path = routingContext.normalisedPath();

if (KSQL_AUTHENTICATION_SKIP_PATHS.contains(path)) {
if (unauthenticatedpaths.matcher(path).matches()) {
Copy link
Member

Choose a reason for hiding this comment

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

Oh wow, so AUTHENTICATION_SKIP_PATHS_CONFIG was not taken into account at all before.

Copy link
Member

@pgaref pgaref left a comment

Choose a reason for hiding this comment

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

Thanks for the FIX @agavra !
Changes LGTM

@pgaref
Copy link
Member

pgaref commented Jun 24, 2022

This should also land to 7.0.x etc right?

@cadonna
Copy link
Member

cadonna commented Jun 27, 2022

@agavra Thanks a lot for the fix!
While I see that unit testing the whole setup is hard, I do not understand why unit testing AuthenticationPluginHandler#getAuthorizationSkipPaths() and KsqlAuthorizationProviderHandler#handle() should be hard. Could you clarify?

@cadonna
Copy link
Member

cadonna commented Jun 27, 2022

This should also land to 7.0.x etc right?

@pgaref Once this PR is merged to 6.0.x, we need to pint merge the commit so that it will bubble up to all <major>.<minor>.x branches including 7.0.x and finally end up on master. See https://confluentinc.atlassian.net/wiki/spaces/QERM/pages/69009670/Release+Branches+and+Tags for more details about CPs branching strategy.

@agavra
Copy link
Contributor Author

agavra commented Jun 27, 2022

@cadonna there are no existing tests for these classes - I will add tests for AuthenticationPluginHandler#getAuthorizationSkipPaths() but tests for KsqlAuthorizationProviderHandler#handle() require a lot of mocking, and to be honest, won't add any meaningful coverage.

EDIT: I see what you mean about testing handle. I'll test that to make sure it picks up the right skip paths.

Copy link
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

@agavra Thanks for the update!

I have two comments regarding the tests.

final Pattern skips = AuthenticationPluginHandler.getAuthorizationSkipPaths(configs);

// Then:
assertThat(skips.matcher("/heartbeat").matches(), is(true));
Copy link
Member

Choose a reason for hiding this comment

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

Why not also verify for /lags?
Could you also add a negative case, like /shouldnotbefound?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not also verify for /lags?

that doesn't add any coverage, I'm ensuring that what is added in the config is able to skip

Could you also add a negative case, like /shouldnotbefound?

Sure I'll add a negative test

Copy link
Member

@cadonna cadonna Jun 27, 2022

Choose a reason for hiding this comment

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

that doesn't add any coverage, I'm ensuring that what is added in the config is able to skip

I cannot follow. Why does verifying for /lag not add any coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding /lag in the config list makes sure that the regex works when you have multiple components - I'm not sure why checking that it works for /lag adds any coverage beyond checking for /heartbeat (basically it uses the same exact code path to check for /lag as it does to check for /heartbeat)

Copy link
Member

Choose a reason for hiding this comment

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

The additional verification would check that the code works for all entries in the config. The code could not consider the other entry. Unit test should not only test the current code but they should also ensure that future refactorings of the code do not change the intended behavior.

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 suppose I can see your point :) I'll add it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

private RoutingContext routingContext;

@Test
public void shouldRespectServerAuthSkipPathsConfig() {
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add a case where authentication is not skipped?

@agavra agavra merged commit 4c33edd into confluentinc:6.0.x Jun 27, 2022
@agavra agavra deleted the fix-skip-paths branch June 27, 2022 18:38
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.

Unable to skip basic authentication for specified paths in ksqldb-server
4 participants