Skip to content

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Aug 27, 2025

java.xml is part of the jdk, but it's really a utility module that shouldn't have direct access to network or files. This commit excludes java.xml from system modules. Note that since it is part of the jdk, it does need access to read jdk classes, so a new internal entitlement is also added to allow reading jrt urls.

java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
@rjernst rjernst requested a review from a team as a code owner August 27, 2025 17:24
@rjernst rjernst added :Core/Infra/Core Core issues without another label >refactoring auto-backport Automatically create backport pull requests when merged v9.1.4 v9.0.7 v8.18.7 v8.19.4 labels Aug 27, 2025
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team v9.2.0 labels Aug 27, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Contributor

@prdoyle prdoyle left a comment

Choose a reason for hiding this comment

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

Some optional javadoc suggestions. Mergeable as is I think.

@@ -610,5 +612,12 @@ static void javaDesktopFileAccess() throws Exception {
new FileImageInputStream(file.toFile()).close();
}

@EntitlementTest(expectedAccess = ALWAYS_DENIED)
static void javaXmlFileRequest() throws Exception {
// java.xml is part of the jdk, but not a system module. this checks it can't access the network
Copy link
Contributor

Choose a reason for hiding this comment

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

*filesystem?

/**
* Internal entitlement to read code from the jdk, ie jrt urls
*/
public class ReadJdkCodeEntitlement implements Entitlement {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh a new entitlement

package org.elasticsearch.entitlement.runtime.policy.entitlements;

/**
* Internal entitlement to read code from the jdk, ie jrt urls
Copy link
Contributor

Choose a reason for hiding this comment

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

This description could use a little refinement, I think. Anyone seeing ReadJdkCodeEntitlement can be trusted to infer that it's an entitlement for reading JDK code, but their question would be: what does that actually mean? I think it means allowing the opening of connections with URLs using the jrt protocol.

The actual implementation does not seem to be limited to just reading resources within the jar, but I suppose writes to jrt URLs would be forbidden by other means?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah the jdk images are read only. I updated the javadoc.

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 also tweaked the entitlement name to make it a little clearer what can be read

@mosche
Copy link
Contributor

mosche commented Aug 28, 2025

Looks like this needs further entitlements to read any jar on the classpath.

[2025-08-27T20:32:46,333][WARN ][o.e.e.r.p.P.(.j.x.c.s.o.a.x.i.impl] [test-cluster-0] Not entitled: component [(server)], module [java.xml], class [class com.sun.org.apache.xerces.internal.impl.XMLEntityManager], entitlement [file], operation [read], path [/dev/shm/bk/bk-agent-prod-gcp-1756317595243267155/elastic/elasticsearch-pull-request/distribution/archives/linux-tar/build/install/elasticsearch-9.2.0-SNAPSHOT/modules/x-pack-security/x-pack-security-9.2.0-SNAPSHOT.jar] org.elasticsearch.entitlement.runtime.api.NotEntitledException: component [(server)], module [java.xml], class [class com.sun.org.apache.xerces.internal.impl.XMLEntityManager], entitlement [file], operation [read], path [/dev/shm/bk/bk-agent-prod-gcp-1756317595243267155/elastic/elasticsearch-pull-request/distribution/archives/linux-tar/build/install/elasticsearch-9.2.0-SNAPSHOT/modules/x-pack-security/x-pack-security-9.2.0-SNAPSHOT.jar]	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.PolicyCheckerImpl.notEntitled(PolicyCheckerImpl.java:467)	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.PolicyCheckerImpl.checkFileRead(PolicyCheckerImpl.java:245)	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.PolicyCheckerImpl.checkFileRead(PolicyCheckerImpl.java:208)	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.PolicyCheckerImpl.checkURLFileRead(PolicyCheckerImpl.java:591)	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.PolicyCheckerImpl.handleNetworkOrFileUrlCheck(PolicyCheckerImpl.java:537)	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.PolicyCheckerImpl.checkEntitlementForUrl(PolicyCheckerImpl.java:491)	
	at [email protected]/org.elasticsearch.entitlement.runtime.policy.ElasticsearchEntitlementChecker.check$java_net_URL$openConnection(ElasticsearchEntitlementChecker.java:649)	
	at java.base/java.net.URL.openConnection(URL.java)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:661)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:150)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:593)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:696)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser.parse(SchemaDOMParser.java:530)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:2227)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:589)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(XMLSchemaLoader.java:844)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:606)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2711)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2070)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:830)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:615)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3089)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:866)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:635)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:113)	
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:551)	
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:890)	
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:826)	
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:134)	
	at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:247)	
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:342)	
	at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:122)	
	at [email protected]/org.elasticsearch.xpack.security.authc.saml.SamlObjectHandler.parseSamlMessage(SamlObjectHandler.java:377)

https://gradle-enterprise.elastic.co/s/6kvkwfqtw653u/tests/task/:x-pack:qa:saml-idp-tests:javaRestTest/details/org.elasticsearch.xpack.security.authc.saml.SamlAuthenticationIT/testLoginUserWithSamlRoleMapping?focused-execution=1&page=eyJvdXRwdXQiOnsiMCI6Mn19&top-execution=1#L213

@mosche
Copy link
Contributor

mosche commented Aug 28, 2025

Looks like granting java.xml read access to the MODULES dir is sufficient.

new Scope(
    "java.xml",
    List.of(
        new ReadJdkImageEntitlement(),
        new FilesEntitlement(List.of(FilesEntitlement.FileData.ofBaseDirPath(MODULES, READ)))
    )
)

but I suppose LIBS and PLUGINS should be granted as well to avoid any potential confusion.

Copy link
Contributor

@mosche mosche left a comment

Choose a reason for hiding this comment

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

Looking good besides above mentioned test issues

@rjernst rjernst added >bug and removed >refactoring labels Aug 28, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @rjernst, I've created a changelog YAML for you.

@rjernst rjernst merged commit 0322089 into elastic:main Aug 30, 2025
33 checks passed
@rjernst rjernst deleted the entitlements/java_xml branch August 30, 2025 00:17
rjernst added a commit to rjernst/elasticsearch that referenced this pull request Aug 30, 2025
java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
rjernst added a commit to rjernst/elasticsearch that referenced this pull request Aug 30, 2025
java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.1
9.0
8.18 Commit could not be cherrypicked due to conflicts
8.19

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 133671

rjernst added a commit to rjernst/elasticsearch that referenced this pull request Aug 30, 2025
java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
elasticsearchmachine pushed a commit that referenced this pull request Aug 30, 2025
java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
elasticsearchmachine pushed a commit that referenced this pull request Aug 30, 2025
java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
elasticsearchmachine pushed a commit that referenced this pull request Aug 30, 2025
java.xml is part of the jdk, but it's really a utility module that
shouldn't have direct access to network or files. This commit excludes
java.xml from system modules. Note that since it is part of the jdk, it
does need access to read jdk classes, so a new internal entitlement is
also added to allow reading jrt urls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged backport pending >bug :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team v8.18.7 v8.19.4 v9.0.7 v9.1.4 v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants