Skip to content

Commit

Permalink
Restructure the security guide and update with Polyglot sandboxing
Browse files Browse the repository at this point in the history
  • Loading branch information
matneu committed Apr 26, 2023
1 parent 2681115 commit 2f54f48
Show file tree
Hide file tree
Showing 8 changed files with 647 additions and 479 deletions.
335 changes: 0 additions & 335 deletions docs/reference-manual/embedding/sandbox-options.md

This file was deleted.

4 changes: 1 addition & 3 deletions docs/reference-manual/native-image/Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ Note that `invokedynamic` use cases generated by `javac` for, for example, Java

### Security Manager

The Java security manager is no longer recommended as a way to isolate less trusted code from more trusted code in the same process.
This is because almost all typical hardware architectures are susceptible to side-channel attacks to access data that is restricted via the security manager.
Using separate processes is now recommended for these cases.
Native Image will not allow a Java Security Manager to be enabled because this functionality has deprecated since Java 17.

## Features That May Operate Differently in a Native Image

Expand Down
55 changes: 1 addition & 54 deletions docs/reference-manual/native-image/InspectTool.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,7 @@ Native Image provides the `--enable-sbom` option to embed an SBOM into a native

> Note: Embedding a Software Bill of Materials (SBOM) is not available in GraalVM Community Edition. The feature is currently experimental.
The CycloneDX format is supported and the default.
To embed a CycloneDX SBOM into a native executable, pass the `--enable-sbom` option to the `native-image` command.

The implementation constructs the SBOM by recovering all version information observable in external library manifests for classes included in a native executable.
The SBOM is also compressed in order to limit the SBOM's impact on the native executable size.
Even though the tool is not yet supported on Windows, Windows users can still embed the SBOM with this experimental option.
The SBOM is stored in the `gzip` format with the exported `sbom` symbol referencing its start address and the `sbom_length` symbol its size.

After embedding the compressed SBOM into the executable, the tool is able to extract the compressed SBOM using an optional `--sbom` parameter accessible through `$JAVA_HOME/bin/native-image-inspect --sbom <path_to_binary>` and outputs the SBOM in the following format:

```json
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"components": [
{
"type": "library",
"group": "io.netty",
"name": "netty-codec-http2",
"version": "4.1.76.Final",
"properties": [
{
"name": "syft:cpe23",
"value": "cpe:2.3:a:codec:codec:4.1.76.Final:*:*:*:*:*:*:*"
},
{
"name": "syft:cpe23",
"value": "cpe:2.3:a:codec:netty-codec-http2:4.1.76.Final:*:*:*:*:*:*:*"
},
{
"name": "syft:cpe23",
"value": "cpe:2.3:a:codec:netty_codec_http2:4.1.76.Final:*:*:*:*:*:*:*"
},
...
]
},
...
],
"serialNumber": "urn:uuid:51ec305f-616e-4139-a033-a094bb94a17c"
}
```

The tool can extract the SBOM from both executables and shared libraries.
To scan for any vulnerable libraries, submit the SBOM to a vulnerability scanner.
For example, the popular [Anchore software supply chain management platform](https://anchore.com/) makes the `grype` scanner freely available.
You can check whether the libraries given in your SBOMs have known vulnerabilities documented in Anchore's database.
For this purpose, the output of the tool can be fed directly to the `grype` scanner to check for vulnerable libraries, using the command `$JAVA_HOME/bin/native-image-inspect --sbom <path_to_binary> | grype` which produces the following output:
```shell
NAME INSTALLED VULNERABILITY SEVERITY
netty-codec-http2 4.1.76.Final CVE-2022-24823 Medium
```

You can then use this report to update any vulnerable dependencies found in your executable.
The tool is able to extract the compressed SBOM using an optional `--sbom` parameter accessible through `$JAVA_HOME/bin/native-image-inspect --sbom <path_to_binary>`.

### Further Reading

Expand Down
104 changes: 104 additions & 0 deletions docs/security/native-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
layout: docs
toc_group: security-guide
link_title: Security Considerations in Native Image
permalink: /security-guide/native-image/
---
# Native Image

The `native-image` builder generates a snapshot of an application after startup and bundles it in a binary executable.

## Class Initialization

The `native-image` builder may execute the static initializers of certain classes at build time (see [class initialization](../reference-manual/native-image/ClassInitialization.md) for more details).
Executing static initializers at build time persists the state after initialization in the image heap.
This means that any information that is obtained or computed in static initializers becomes part of a native executable.
This can either result in sensitive data ending up in the snapshot or fixing initialization data that is supposed to be obtained at startup, such as random number seeds.

Developers can request static initializers that process sensitive information to be executed at run time by specifying the `--initialize-at-run-time` CLI parameter when building a native executable, followed by a comma-separated list of packages and classes (and implicitly all of their subclasses) that must be initialized at runtime and not during image building.
Alternatively developers can make use of the [`RuntimeClassInitialization` API](https://www.graalvm.org/sdk/javadoc/org/graalvm/nativeimage/hosted/RuntimeClassInitialization.html).

Developers should run the `native-image` builder in a dedicated environment, such as a container, that does not contain any sensitive information in the first place.

## Software Bill of Materials

GraalVM Native Image can embed a Software Bill of Materials (SBOM) at build time to detect any libraries that may be susceptible to known security vulnerabilities.
Native Image provides the `--enable-sbom` option to embed an SBOM into a native executable.

> Note: Embedding a Software Bill of Materials (SBOM) is not available in GraalVM Community Edition.
The CycloneDX format is supported and the default.
To embed a CycloneDX SBOM into a native executable, pass the `--enable-sbom` option to the `native-image` command.

The implementation constructs the SBOM by recovering all version information observable in external library manifests for classes included in a native executable.
The SBOM is also compressed in order to limit the SBOM's impact on the native executable size.
The SBOM is stored in the `gzip` format with the exported `sbom` symbol referencing its start address and the `sbom_length` symbol its size.

After embedding the compressed SBOM into the executable, the [native image inspect tool](../reference-manual/native-image/InspectTool.md) is able to extract the compressed SBOM using an optional `--sbom` parameter accessible through `$JAVA_HOME/bin/native-image-inspect --sbom <path_to_binary>` from both executables and shared libraries.
It outputs the SBOM in the following format:

```json
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"components": [
{
"type": "library",
"group": "io.netty",
"name": "netty-codec-http2",
"version": "4.1.76.Final",
"properties": [
{
"name": "syft:cpe23",
"value": "cpe:2.3:a:codec:codec:4.1.76.Final:*:*:*:*:*:*:*"
},
{
"name": "syft:cpe23",
"value": "cpe:2.3:a:codec:netty-codec-http2:4.1.76.Final:*:*:*:*:*:*:*"
},
{
"name": "syft:cpe23",
"value": "cpe:2.3:a:codec:netty_codec_http2:4.1.76.Final:*:*:*:*:*:*:*"
},
...
]
},
...
],
"serialNumber": "urn:uuid:51ec305f-616e-4139-a033-a094bb94a17c"
}
```

To scan for any vulnerable libraries, submit the SBOM to a vulnerability scanner.
For example, the popular [Anchore software supply chain management platform](https://anchore.com/) makes the `grype` scanner freely available.
You can check whether the libraries given in your SBOMs have known vulnerabilities documented in Anchore's database.
For this purpose, the output of the tool can be fed directly to the `grype` scanner to check for vulnerable libraries, using the command `$JAVA_HOME/bin/native-image-inspect --sbom <path_to_binary> | grype` which produces the following output:
```shell
NAME INSTALLED VULNERABILITY SEVERITY
netty-codec-http2 4.1.76.Final CVE-2022-24823 Medium
```

You can then use this report to update any vulnerable dependencies found in your executable.

## Java serialization in Native Image

Native Image supports Serialization to help users deserialize the constructors for classes, contained in a native executable.
Unless picked up by native image analysis automatically, [these classes have to be pre-specified](https://www.graalvm.org/22.0/reference-manual/native-image/Reflection/#manual-configuration), as classes not contained in a native executable cannot be deserialized.
Native Image cannot prevent exploitation of deserialization vulnerabilities in isolation.
The [serialization and deserialization Secure Coding Guidelines for Java SE](https://www.oracle.com/java/technologies/javase/seccodeguide.html#8) should be followed.

## Miscellaneous

Native Image provides multiple ways to specify a certificate file used to define the default TrustStore.
While the default behavior for `native-image` is to capture and use the default TrustStore from the build-time host environment, this can be changed at run time by setting the "javax.net.ssl.trustStore\*" system properties.
See the [documentation](../reference-manual/native-image/CertificateManagement.md) for more details.

The directory containing the native executable is part of the search path when loading native libraries using `System.loadLibrary()` at run time.

Native Image will not allow a Java Security Manager to be enabled because this functionality has now deprecated since Java 17.
Attempting to set a security manager will trigger a runtime error.

## Related Documentation
- [Security Guide](security-guide.md)
- [Polyglot Sandboxing](polyglot-sandbox.md)
Loading

0 comments on commit 2f54f48

Please sign in to comment.