-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Miscellaneous java.base file entitlements #122906
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
Changes from 1 commit
e400940
a095b3a
ea6159c
64060e0
9d151ef
089bdac
e02ae80
84dc310
919dc48
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 |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |
| import java.io.File; | ||
| import java.io.FileDescriptor; | ||
| import java.io.FileInputStream; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.FileOutputStream; | ||
| import java.io.FileReader; | ||
| import java.io.FileWriter; | ||
|
|
@@ -26,12 +25,12 @@ | |
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.nio.file.attribute.UserPrincipal; | ||
| import java.util.Scanner; | ||
|
|
||
| import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.ALWAYS_DENIED; | ||
| import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS; | ||
|
|
||
| @SuppressForbidden(reason = "Explicitly checking APIs that are forbidden") | ||
| @SuppressWarnings("unused") // Called via reflection | ||
| class FileCheckActions { | ||
|
|
||
| static Path testRootDir = Paths.get(System.getProperty("es.entitlements.testdir")); | ||
|
|
@@ -207,21 +206,6 @@ static void fileSetWritableOwner() throws IOException { | |
| readWriteFile().toFile().setWritable(true, false); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createScannerFile() throws FileNotFoundException { | ||
|
Member
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. Aren't all of the rest of the methods in this file also in java.base? I don't understand the distinction as to why they belong in a separate files vs in this one.
Contributor
Author
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. Oh I didn't check. I just moved over the ones that were on the spreadsheet tab. What would you like to do? Merge them together?
Member
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. Maybe split them based on some explainable attributes? I don't feel strongly, but it seems like having a test file that implies java.base classes should be tested in it, yet other test files contain java.base classes, will cause confusion.
Contributor
Author
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. I'm not sure I can explain why these ended up in their own spreadsheet tab. Maybe I'll just merge them into |
||
| new Scanner(readFile().toFile()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createScannerFileWithCharset() throws IOException { | ||
| new Scanner(readFile().toFile(), StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createScannerFileWithCharsetName() throws FileNotFoundException { | ||
| new Scanner(readFile().toFile(), "UTF-8"); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createFileInputStreamFile() throws IOException { | ||
| new FileInputStream(readFile().toFile()).close(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.entitlement.qa.test; | ||
|
|
||
| import org.elasticsearch.core.CheckedRunnable; | ||
| import org.elasticsearch.core.SuppressForbidden; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.security.GeneralSecurityException; | ||
| import java.security.KeyStore; | ||
| import java.util.Scanner; | ||
| import java.util.jar.JarFile; | ||
| import java.util.zip.ZipException; | ||
| import java.util.zip.ZipFile; | ||
|
|
||
| import static java.nio.charset.Charset.defaultCharset; | ||
| import static java.util.zip.ZipFile.OPEN_DELETE; | ||
| import static java.util.zip.ZipFile.OPEN_READ; | ||
| import static org.elasticsearch.entitlement.qa.entitled.EntitledActions.createTempFileForWrite; | ||
| import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS; | ||
| import static org.elasticsearch.entitlement.qa.test.FileCheckActions.readFile; | ||
|
|
||
| @SuppressForbidden(reason = "Explicitly checking APIs that are forbidden") | ||
| @SuppressWarnings("unused") // Called via reflection | ||
| public class JavaBaseFileActions { | ||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void keystore_getInstance_1() throws IOException { | ||
| try { | ||
| KeyStore.getInstance(readFile().toFile(), new char[0]); | ||
| } catch (GeneralSecurityException expected) { | ||
| return; | ||
| } | ||
| throw new AssertionError("Expected an exception"); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void keystore_getInstance_2() throws IOException { | ||
| try { | ||
| KeyStore.LoadStoreParameter loadStoreParameter = () -> null; | ||
| KeyStore.getInstance(readFile().toFile(), loadStoreParameter); | ||
| } catch (GeneralSecurityException expected) { | ||
| return; | ||
| } | ||
| throw new AssertionError("Expected an exception"); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void keystoreBuilder_newInstance() { | ||
| try { | ||
| KeyStore.Builder.newInstance("", null, readFile().toFile(), null); | ||
| } catch (NullPointerException expected) { | ||
| return; | ||
| } | ||
| throw new AssertionError("Expected an exception"); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_1() throws IOException { | ||
|
||
| expectZipException(() -> new ZipFile(readFile().toString()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_2() throws IOException { | ||
| expectZipException(() -> new ZipFile(readFile().toString(), defaultCharset()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_3() throws IOException { | ||
| expectZipException(() -> new ZipFile(readFile().toFile()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_4() throws IOException { | ||
| expectZipException(() -> new ZipFile(readFile().toFile(), defaultCharset()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_5_readOnly() throws IOException { | ||
| expectZipException(() -> new ZipFile(readFile().toFile(), OPEN_READ).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_5_readAndDelete() throws IOException { | ||
| expectZipException(() -> new ZipFile(createTempFileForWrite().toFile(), OPEN_READ | OPEN_DELETE).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void zipFile_6_readOnly() throws IOException { | ||
| expectZipException(() -> new ZipFile(readFile().toFile(), OPEN_READ, defaultCharset()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_1() throws IOException { | ||
| expectZipException(() -> new JarFile(readFile().toString()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_2() throws IOException { | ||
| expectZipException(() -> new JarFile(readFile().toString(), false).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_3_readOnly() throws IOException { | ||
| expectZipException(() -> new JarFile(readFile().toFile(), false, OPEN_READ).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_3_readAndDelete() throws IOException { | ||
| expectZipException(() -> new JarFile(createTempFileForWrite().toFile(), false, OPEN_READ | OPEN_DELETE).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_4_readOnly() throws IOException { | ||
| expectZipException(() -> new JarFile(readFile().toFile(), false, OPEN_READ, Runtime.version()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_4_readAndDelete() throws IOException { | ||
| expectZipException(() -> new JarFile(createTempFileForWrite().toFile(), false, OPEN_READ | OPEN_DELETE, Runtime.version()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_5() throws IOException { | ||
| expectZipException(() -> new JarFile(readFile().toFile()).close()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void jarFile_6() throws IOException { | ||
| expectZipException(() -> new JarFile(readFile().toFile(), false).close()); | ||
| } | ||
|
|
||
| private static void expectZipException(CheckedRunnable<IOException> action) throws IOException { | ||
| try { | ||
| action.run(); | ||
| } catch (ZipException expected) { | ||
| return; | ||
| } | ||
| throw new AssertionError("Expected an exception"); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createScannerFile() throws FileNotFoundException { | ||
| new Scanner(readFile().toFile()); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createScannerFileWithCharset() throws IOException { | ||
| new Scanner(readFile().toFile(), StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void createScannerFileWithCharsetName() throws FileNotFoundException { | ||
| new Scanner(readFile().toFile(), "UTF-8"); | ||
| } | ||
|
|
||
| } | ||
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 you please split this out? We've talked about it across several PRs, let's do it, but as distinct commits.
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.
I thought the controversy was using exceptions to get a stack trace.
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.
There's no controversy, I just think adding debug logging to instrumentation is unrelated to adding miscellaneous file entitlements?
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.
#122935