Skip to content

Conversation

@denodo-research-labs
Copy link
Contributor

@denodo-research-labs denodo-research-labs commented Nov 3, 2025

Description

Bearer authentication for Nessie catalog is not working

Motivation and Context

Fixes the problem with Bearer authentication for Nessie catalog

Impact

Is not possible to connect to Nessie catalog using Bearer authentication

Test Plan

A new TestIcebergSystemTablesNessieWithBearerAuth class has been added. It extends TestIcebergSystemTablesNessie and re-runs those tests using Bearer authentication. The other Nessie tests are not duplicated, as this class sufficiently validates the authentication mechanism.

Test adapted from trinodb/trino#17725

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==
 
Iceberg Connector Changes
* Fix Bearer authentication with Nessie catalog.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 3, 2025

Reviewer's Guide

This PR enables Bearer authentication for the Nessie catalog by propagating the authentication type in the catalog factory, extending the testing infrastructure with a Keycloak test container and necessary dependencies, and adding an integration test that verifies the end-to-end Bearer auth flow.

Sequence diagram for Bearer authentication flow in Nessie catalog tests

sequenceDiagram
actor Tester
participant "TestIcebergSystemTablesNessieWithBearerAuth"
participant "KeycloakContainer"
participant "NessieContainer"
participant "IcebergNessieCatalogFactory"

Tester->>"TestIcebergSystemTablesNessieWithBearerAuth": Start test
"TestIcebergSystemTablesNessieWithBearerAuth"->>"KeycloakContainer": Request Bearer token
"KeycloakContainer"->>"KeycloakContainer": getAccessToken()
"KeycloakContainer"-->>"TestIcebergSystemTablesNessieWithBearerAuth": Return Bearer token
"TestIcebergSystemTablesNessieWithBearerAuth"->>"NessieContainer": Connect using Bearer token
"NessieContainer"->>"IcebergNessieCatalogFactory": Pass authentication type
"IcebergNessieCatalogFactory"->>"NessieContainer": Propagate nessie.authentication.type property
"NessieContainer"-->>"TestIcebergSystemTablesNessieWithBearerAuth": Connection established
Tester-->>"TestIcebergSystemTablesNessieWithBearerAuth": Test result
Loading

Entity relationship diagram for new Keycloak and Nessie container environment variables

erDiagram
KEYCLOAK_CONTAINER {
  KC_BOOTSTRAP_ADMIN_USERNAME string
  KC_BOOTSTRAP_ADMIN_PASSWORD string
  KC_HOSTNAME string
}
NESSIE_CONTAINER {
  QUARKUS_HTTP_PORT int
  NESSIE_VERSION_STORE_TYPE string
}
KEYCLOAK_CONTAINER ||--o| NESSIE_CONTAINER : "used for authentication"
Loading

Class diagram for new KeycloakContainer and related changes

classDiagram
class KeycloakContainer {
  +String DEFAULT_IMAGE
  +String DEFAULT_HOST_NAME
  +String DEFAULT_USER_NAME
  +String DEFAULT_PASSWORD
  +String MASTER_REALM
  +String ADMIN_CLI_CLIENT
  +int PORT
  +String SERVER_URL
  +KeycloakContainer_Builder builder()
  +String getUrl()
  +String getAccessToken()
  +void start()
}
class KeycloakContainer_Builder {
  +KeycloakContainer build()
}
KeycloakContainer <|-- KeycloakContainer_Builder
KeycloakContainer --|> BaseTestContainer
KeycloakContainer_Builder --|> BaseTestContainer_Builder
class NessieContainer {
  +ImmutableMap DEFAULT_ENV_VARS
}
NessieContainer --|> BaseTestContainer
Loading

File-Level Changes

Change Details Files
Add Keycloak client dependencies to testing infrastructure
  • Introduce dep.keycloak.client.version property
  • Add keycloak-admin-client dependency with exclusions
  • Add keycloak-client-common-synced dependency
presto-testing-docker/pom.xml
Refactor NessieContainer to centralize default environment variables
  • Extract DEFAULT_ENV_VARS constant
  • Update builder to reuse DEFAULT_ENV_VARS
presto-testing-docker/src/main/java/com/facebook/presto/testing/containers/NessieContainer.java
Support authentication type in IcebergNessieCatalogFactory
  • Add nessie.authentication.type property when authenticationType is present
presto-iceberg/src/main/java/com/facebook/presto/iceberg/nessie/IcebergNessieCatalogFactory.java
Introduce KeycloakContainer for test authentication server
  • Create new KeycloakContainer class with builder and setup logic
  • Implement getAccessToken method for retrieving bearer tokens
presto-testing-docker/src/main/java/com/facebook/presto/testing/containers/KeycloakContainer.java
Add integration test for Bearer authentication
  • Create TestIcebergSystemTablesNessieWithBearerAuth extending existing Nessie tests
  • Configure Nessie and Keycloak containers with OIDC env vars
  • Pass bearer token in iceberg.nessie.auth.bearer.token property
presto-iceberg/src/test/java/com/facebook/presto/iceberg/nessie/TestIcebergSystemTablesNessieWithBearerAuth.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `presto-testing-docker/src/main/java/com/facebook/presto/testing/containers/KeycloakContainer.java:102` </location>
<code_context>
+            RealmRepresentation masterRep = master.toRepresentation();
+            // change access token lifespan from 1 minute (default) to 1 hour
+            // to keep the token alive in case testcase takes more than a minute to finish execution.
+            masterRep.setAccessTokenLifespan(3600);
+            master.update(masterRep);
+            return keycloak.tokenManager().grantToken().getToken();
</code_context>

<issue_to_address>
**issue (bug_risk):** Changing the access token lifespan on every token request may have unintended side effects.

Setting the access token lifespan within getAccessToken() can cause race conditions in concurrent tests. It's better to configure this during container setup or initialization.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

RealmRepresentation masterRep = master.toRepresentation();
// change access token lifespan from 1 minute (default) to 1 hour
// to keep the token alive in case testcase takes more than a minute to finish execution.
masterRep.setAccessTokenLifespan(3600);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Changing the access token lifespan on every token request may have unintended side effects.

Setting the access token lifespan within getAccessToken() can cause race conditions in concurrent tests. It's better to configure this during container setup or initialization.

@denodo-research-labs denodo-research-labs marked this pull request as draft November 3, 2025 09:23
@denodo-research-labs denodo-research-labs force-pushed the bearer_authentication_nessie_catalog branch 3 times, most recently from 45f4a0b to f5c6fe6 Compare November 3, 2025 19:10
@tdcmeehan tdcmeehan self-assigned this Nov 3, 2025
@denodo-research-labs denodo-research-labs force-pushed the bearer_authentication_nessie_catalog branch from f5c6fe6 to 22c24b9 Compare November 6, 2025 16:58
@denodo-research-labs denodo-research-labs marked this pull request as ready for review November 6, 2025 18:14
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `presto-testing-docker/src/main/java/com/facebook/presto/testing/containers/KeycloakContainer.java:116-119` </location>
<code_context>
+            this.image = DEFAULT_IMAGE;
+            this.hostName = DEFAULT_HOST_NAME;
+            this.exposePorts = ImmutableSet.of(PORT);
+            this.envVars = ImmutableMap.of(
+                    "KC_BOOTSTRAP_ADMIN_USERNAME", DEFAULT_USER_NAME,
+                    "KC_BOOTSTRAP_ADMIN_PASSWORD", DEFAULT_PASSWORD,
+                    "KC_HOSTNAME", SERVER_URL);
+        }
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Setting KC_HOSTNAME to SERVER_URL may not match Keycloak's expected value.

KC_HOSTNAME should be set to just the hostname, not the full SERVER_URL. Use DEFAULT_HOST_NAME instead to avoid issues with Keycloak startup.
</issue_to_address>

### Comment 2
<location> `presto-iceberg/src/test/java/com/facebook/presto/iceberg/nessie/TestIcebergSystemTablesNessieWithBearerAuth.java:99` </location>
<code_context>
+    @Override
+    protected QueryRunner createQueryRunner()
</code_context>

<issue_to_address>
**suggestion (testing):** Suggestion to add negative test cases for invalid or expired Bearer tokens.

Please add tests for invalid and expired tokens to confirm authentication fails as expected.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +116 to +119
this.envVars = ImmutableMap.of(
"KC_BOOTSTRAP_ADMIN_USERNAME", DEFAULT_USER_NAME,
"KC_BOOTSTRAP_ADMIN_PASSWORD", DEFAULT_PASSWORD,
"KC_HOSTNAME", SERVER_URL);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Setting KC_HOSTNAME to SERVER_URL may not match Keycloak's expected value.

KC_HOSTNAME should be set to just the hostname, not the full SERVER_URL. Use DEFAULT_HOST_NAME instead to avoid issues with Keycloak startup.


queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", icebergProperties);

return queryRunner;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Suggestion to add negative test cases for invalid or expired Bearer tokens.

Please add tests for invalid and expired tokens to confirm authentication fails as expected.

@denodo-research-labs denodo-research-labs force-pushed the bearer_authentication_nessie_catalog branch from 22c24b9 to da3406b Compare November 6, 2025 18:15
@denodo-research-labs denodo-research-labs force-pushed the bearer_authentication_nessie_catalog branch from da3406b to b45e02a Compare November 7, 2025 09:31
@denodo-research-labs
Copy link
Contributor Author

The test failure seems to be unrelated.

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.

2 participants