-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix: Presto spark add X509 certificates to SessionContext #27183
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,15 +339,15 @@ public PrestoSparkQueryRunner( | |
| // Sql-Standard Access Control Checker | ||
| // needs us to specify our role | ||
| .setIdentity( | ||
| new Identity( | ||
| "hive", | ||
| Optional.empty(), | ||
| ImmutableMap.of(defaultCatalog, | ||
| new SelectedRole(Type.ROLE, Optional.of("admin"))), | ||
| ImmutableMap.of(), | ||
| ImmutableMap.of(), | ||
| Optional.empty(), | ||
| Optional.empty())) | ||
| new Identity( | ||
| "hive", | ||
| Optional.empty(), | ||
| ImmutableMap.of(defaultCatalog, | ||
| new SelectedRole(Type.ROLE, Optional.of("admin"))), | ||
| ImmutableMap.of(), | ||
| ImmutableMap.of(), | ||
| Optional.empty(), | ||
| Optional.empty())) | ||
| .build(); | ||
|
|
||
| transactionManager = injector.getInstance(TransactionManager.class); | ||
|
|
@@ -659,6 +659,7 @@ private static PrestoSparkSession createSessionInfo(Session session) | |
| session.getIdentity().getUser(), | ||
| session.getIdentity().getPrincipal(), | ||
| session.getIdentity().getExtraCredentials(), | ||
| session.getIdentity().getCertificates(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Add a test that verifies X509 certificates are propagated end-to-end into the Spark session/context The new
This validates that the new field is not only set at construction but is actually available where authentication will rely on it. Suggested implementation: session.getIdentity().getExtraCredentials(),
session.getIdentity().getCertificates(),
session.getCatalog(),
session.getSchema(),
session.getSource(),
@Test
public void testX509CertificatesPropagatedToSparkSessionContext()
throws Exception
{
// Arrange: build a Session with a non-empty certificates list
X509Certificate certificate = mock(X509Certificate.class);
List<X509Certificate> certificates = ImmutableList.of(certificate);
Session sessionWithCertificates = createSessionBuilder()
.setIdentity(
Identity.forUser("test_user")
.withPrincipal("test_principal")
.withCertificates(certificates)
.build())
.build();
// Act: run a simple Spark query using the existing Presto Spark test harness
PrestoSparkQueryRunner queryRunner = createPrestoSparkQueryRunner();
MaterializedResult result = queryRunner.execute(sessionWithCertificates, "SELECT 1");
// Sanity check query executed successfully
assertEquals(result.getOnlyValue(), 1L);
// Assert: the certificates are visible from the Spark execution context
PrestoSparkSessionContext sparkSessionContext = queryRunner.getLastSparkSessionContext();
assertNotNull(sparkSessionContext, "Spark session context should be initialized");
assertEquals(
sparkSessionContext.getIdentity().getCertificates(),
certificates,
"X509 certificates should be propagated end-to-end into the Spark session context");
}To make the above compile and behave as intended, you will also need to:
|
||
| session.getCatalog(), | ||
| session.getSchema(), | ||
| session.getSource(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it return null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can never be null. The getCertificates() method on Identity class always returns a list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrestoSparkSessionContext constructor also require non null Identity