Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#848] feat(doc): Add the examples for security (#1043)

qqqttt123b0a79522f597
diff --git a/docs/assets/jks.png b/docs/assets/jks.png
new file mode 100644
index 0000000000..66f655a8cc
Binary files /dev/null and b/docs/assets/jks.png differ
diff --git a/docs/assets/oauth.png b/docs/assets/oauth.png
new file mode 100644
index 0000000000..5c7da110b2
Binary files /dev/null and b/docs/assets/oauth.png differ
diff --git a/docs/assets/pem.png b/docs/assets/pem.png
new file mode 100644
index 0000000000..5d612dfbcf
Binary files /dev/null and b/docs/assets/pem.png differ
diff --git a/docs/security.md b/docs/security.md
index 2e5606d662..44071940d9 100644
--- a/docs/security.md
+++ b/docs/security.md
@@ -1,8 +1,8 @@
---
-title: "How to customize Gravitino server configurations"
-date: 2023-11-20T09:03:20-08:00
-license: "Copyright 2023 Datastrato Pvt Ltd.
-This software is licensed under the Apache License version 2."
+title: "Security"
+slug: /security
+keyword: security
+license: "Copyright 2023 Datastrato Pvt Ltd. This software is licensed under the Apache License version 2."
---
## Authentication
@@ -12,8 +12,11 @@ Gravitino supports two kinds of authentication mechanisms: simple and OAuth.
### Simple mode
Simple mode is the default authentication option.
+
Simple mode allows the client to use the environment variable `GRAVITINO_USER` as the user.
+
If the environment variable `GRAVITINO_USER` isn't set, the client uses the user of the machine that sends requests.
+
For the client side, users can enable `simple` mode by the following code:
```java
@@ -25,10 +28,13 @@ GravitinoClient client = GravitinoClient.builder(uri)
### OAuth mode
Gravitino only supports external OAuth 2.0 servers.
+
First, users need to guarantee that the external correctly configured OAuth 2.0 server supports Bearer JWT.
+
Then, on the server side, users should set `gravitino.authenticator` as `oauth` and give
`gravitino.authenticator.oauth.defaultSignKey`, `gravitino.authenticator.oauth.serverUri` and
`gravitino.authenticator.oauth.tokenPath` a proper value.
+
Next, for the client side, users can enable `OAuth` mode by the following code:
```java
@@ -73,13 +79,77 @@ The signature algorithms that Gravitino supports follows:
| PS384 | RSASSA-PSS using SHA-384 and MGF1 with SHA-384 |
| PS512 | RSASSA-PSS using SHA-512 and MGF1 with SHA-512 |
-## HTTPS configuration
+### Example
+
+You can follow the steps to set up an OAuth mode Gravitino server.
+
+1. Prerequisite
+
+ You need to install the JDK8 and Docker.
+
+2. Set up an external OAuth 2.0 server
+
+ There is a sample-authorization-server based on [spring-authorization-server](https://github.com/spring-projects/spring-authorization-server/tree/1.0.3).
+
+ The image has registered a client information in the external OAuth 2.0 server.
+
+ Its clientId is `test`. Its secret is `test`. Its scope is `test`.
+
+```shell
+ docker run -p 8177:8177 --name sample-auth-server -d datastrato/sample-authorization-server:0.3.0
+```
+
+3. Open [the JWK URL of the Authorization server](http://localhost:8177/oauth2/jwks) in the browser and you can get the JWK.
+
+ ![jks_response_image](assets/jks.png)
+
+4. Convert the JWK to PEM. You can use the [online tool](https://8gwifi.org/jwkconvertfunctions.jsp#google_vignette) or other tools.
+
+ ![pem_convert_result_image](assets/pem.png)
+
+5. Copy the public key and remove the character `\n` and you can get the default signing key of Gravitino server.
+
+6. You can refer to the [Configurations](gravitino-server-config) and append the configurations to the conf/gravitino.conf.
+
+```text
+gravitino.authenticator oauth
+gravitino.authenticator.oauth.serviceAudience test
+gravitino.authenticator.oauth.defaultSignKey <the default signing key>
+gravitino.authenticator.oauth.tokenPath /oauth2/token
+gravitino.authenticator.oauth.serverUri http://localhost:8177
+```
+
+7. Open [the URL of Gravitino server](http://localhost:8090) and login in with clientId `test`, clientSecret `test` and scope `test`.
+
+ ![oauth_login_image](assets/oauth.png)
+
+8. You can also use curl command to access Gravitino.
+
+Get access token
+
+```shell
+curl --location --request POST 'http://127.0.0.1:8177/oauth2/token?grant_type=client_credentials&client_id=test&client_secret=test&scope=test'
+```
+
+Use the access token to request the Gravitino
+
+```shell
+curl -v -X GET -H "Accept: application/vnd.gravitino.v1+json" -H "Content-Type: application/json" -H "Authorization: Bearer <access_token>" http://localhost:8090/api/version
+```
+
+
+## HTTPS
+
Users would better use HTTPS instead of HTTP if users choose OAuth 2.0 as the authenticator.
+
HTTPS protects the header of the request from smuggling, making it safer.
+
If users choose to enable HTTPS, Gravitino won't provide the ability of HTTP service.
+
Both Gravitino server and Iceberg REST service can configure HTTPS.
### Gravitino server's configuration
+
| Configuration item | Description | Default value | Since version |
|-----------------------------------------------------|------------------------------------------------------------|---------------|---------------|
| `gravitino.server.webserver.enableHttps` | Enables HTTPS. | `false` | 0.3.0 |
@@ -96,6 +166,7 @@ Both Gravitino server and Iceberg REST service can configure HTTPS.
| `gravitino.server.webserver.trustStoreType` | The type to the trust store. | `JKS` | 0.3.0 |
### Iceberg REST service's configuration
+
| Configuration item | Description | Default value | Since version |
|------------------------------------------------------------|------------------------------------------------------------|---------------|---------------|
| `gravitino.auxService.iceberg-rest.enableHttps` | Enables HTTPS. | `false` | 0.3.0 |
@@ -114,3 +185,76 @@ Both Gravitino server and Iceberg REST service can configure HTTPS.
Refer to the "Additional JSSE Standard Names" section of the [Java security guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#jssenames) for the list of protocols related to tlsProtocol. You can find the list of `tlsProtocol` values for Java 8 in this document.
Refer to the "Additional JSSE Standard Names" section of the [Java security guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#ciphersuites) for the list of protocols related to tlsProtocol. You can find the list of `enableCipherAlgorithms` values for Java 8 in this document.
+
+### Example
+
+You can follow the steps to set up a HTTPS server.
+
+1. Prerequisite
+
+ You need to install the JDK8, wget and set the environment JAVA_HOME.
+
+ If you want to use the command `curl` to request the Gravitino server, you should install openSSL.
+
+2. Generate the key store
+
+```shell
+cd $JAVA_HOME
+bin/keytool -genkeypair -alias localhost \
+-keyalg RSA -keysize 4096 -keypass localhost \
+-sigalg SHA256withRSA \
+-keystore localhost.jks -storetype JKS -storepass localhost \
+-dname "cn=localhost,ou=localhost,o=localhost,l=beijing,st=beijing,c=cn" \
+-validity 36500
+```
+
+3. Generate the certificate
+
+```shell
+bin/keytool -export -alias localhost -keystore localhost.jks -file localhost.crt -storepass localhost
+```
+
+4. Import the certificate
+
+```shell
+bin/keytool -import -alias localhost -keystore jre/lib/security/cacerts -file localhost.crt -storepass changeit -noprompt
+```
+
+5. You can refer to the [Configurations](gravitino-server-config) and append the configurations to the conf/gravitino.conf.
+Configuration doesn't support to resolve environment variable, so you should replace ${JAVA_HOME} with the actual value.
+Then, You can start the Gravitino server.
+
+```text
+gravitino.server.webserver.host localhost
+gravitino.server.webserver.enableHttps true
+gravitino.server.webserver.keyStorePath ${JAVA_HOME}/localhost.jks
+gravitino.server.webserver.keyStorePassword localhost
+gravitino.server.webserver.managerPassword localhost
+```
+
+6. Request the Gravitino server
+
+ If you use Java, you can follow the steps
+
+ Copy the code to a file named Main.java
+
+```java
+import com.datastrato.gravitino.client.GravitinoClient;
+import com.datastrato.gravitino.client.GravitinoVersion;
+
+public class Main {
+ public static void main(String[] args) {
+ String uri = "https://localhost:8433";
+ GravitinoClient client = GravitinoClient.builder(uri).build();
+ GravitinoVersion gravitinoVersion = client.getVersion();
+ System.out.println(gravitinoVersion);
+ }
+}
+```
+
+If you want to use the command `curl`, you can follow the commands:
+
+```shell
+openssl x509 -inform der -in $JAVA_HOME/localhost.crt -out certificate.pem
+curl -v -X GET --cacert ./certificate.pem -H "Accept: application/vnd.gravitino.v1+json" -H "Content-Type: application/json" https://localhost:8433/api/version
+```