Skip to content
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

[#1190] feat(server-common): Support custom filters #1191

Merged
merged 9 commits into from
Dec 21, 2023

Conversation

qqqttt123
Copy link
Contributor

@qqqttt123 qqqttt123 commented Dec 18, 2023

What changes were proposed in this pull request?

Add the support of custom filters referring to the Spark.

Why are the changes needed?

Some filters can be configured by users, the needs of users are different. Some filters are implemented by other libs.
For example, Jetty has implemented the CORS filter, so we supported custom filters to satisfy the needs of users.

Fix: #1190

Does this PR introduce any user-facing change?

Yes, I have added the document.

How was this patch tested?

test by the browser console
I test Jetty's cors filter.

Configuration

gravitino.server.webserver.customFilters=org.eclipse.jetty.servlets.CrossOriginFilter
gravitino.server.webserver.org.eclipse.jetty.servlets.CrossOriginFilter.param.allowedOrigins=*

Browser console code

var http = new XMLHttpRequest();
var url = 'http://localhost:8090/api/version';
http.onreadystatechange = (e) => {
    console.log(http.responseText)
}
http.open("GET", url);
http.send();

@qqqttt123 qqqttt123 marked this pull request as draft December 18, 2023 10:05
@qqqttt123 qqqttt123 changed the title [ISSUE-1190]feat(server-common): Support custom filter [ISSUE-1190]feat(server-common): Support custom filters Dec 18, 2023
@@ -245,8 +255,11 @@ private JettyServerConfig(Map<String, String> configs) {
Sets.newHashSet(internalConfig.get(ENABLE_CIPHER_ALGORITHMS).split(SPLITTER)));
this.enableClientAuth = internalConfig.get(ENABLE_CLIENT_AUTH);
this.trustStorePath = internalConfig.get(SSL_TRUST_STORE_PATH);
this.trustStorePasword = internalConfig.get(SSL_TRUST_STORE_PASSWORD);
this.trustStorePassword = internalConfig.get(SSL_TRUST_STORE_PASSWORD);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An unrelated typo. Just fix by the way.

@@ -330,14 +343,18 @@ public String getTrustStorePath() {
return trustStorePath;
}

public String getTrustStorePasword() {
return trustStorePasword;
public String getTrustStorePassword() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An unrelated typo. Just fix by the way.

docs/security.md Outdated Show resolved Hide resolved
@qqqttt123 qqqttt123 self-assigned this Dec 18, 2023
@qqqttt123 qqqttt123 changed the title [ISSUE-1190]feat(server-common): Support custom filters [ISSUE-1190] feat(server-common): Support custom filters Dec 19, 2023
@qqqttt123 qqqttt123 marked this pull request as ready for review December 19, 2023 08:05
docs/security.md Outdated
### Iceberg REST service's configuration
| Configuration item | Description | Default value | Required | Since version |
|-----------------------------------------------------|--------------------------------------------------------------------|---------------|-----------|---------------|
| `gravitino.auxService.iceberg-rest.customFilters` | Comma separated list of filter class names to apply to the APIs. | `` | Yes | 0.4.0 |
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the default value `` and it's a required value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Require value means that the value can't be null. It's ok to use `` as the value. It means that we don't use any filter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have the same question, Required means user must fillup this field or the program couldn't startup as I understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required means that this field can't be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have the same question, Required means user must fillup this field or the program couldn't startup as I understand.

According to your standard, gravitino.auxService.iceberg-rest.catalog-backend isn't a required field. But you choose it as a required field.

Copy link
Contributor

Choose a reason for hiding this comment

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

Following the previous document specification, we use "(none)" to indicate no default value.

JDBC catalog:
image

Hive catalog:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I see other documents follow this standard. I will change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1214 I raised another pr to fix the comments in other places.
If this config option has default value, this config option is not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

docs/security.md Outdated
|-----------------------------------------------------|--------------------------------------------------------------------|---------------|-----------|---------------|
| `gravitino.auxService.iceberg-rest.customFilters` | Comma separated list of filter class names to apply to the APIs. | `` | Yes | 0.4.0 |
The filter should be a standard javax servlet Filter.
Filter parameters can also be specified in the configuration, by setting config entries of the form `gravitino.auxService.iceberg-rest.<class name of filter>.param.<param name>=<value>`
Copy link
Contributor

Choose a reason for hiding this comment

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

The key seems to be too long, can we shorten it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refer to Spark's way. I have no better idea.

docs/security.md Outdated
| Configuration item | Description | Default value | Required | Since version |
|---------------------------------------------|------------------------------------------------------------------|---------------|-----------|---------------|
| `gravitino.server.webserver.customFilters` | Comma separated list of filter class names to apply to the APIs. | `` | Yes | 0.4.0 |
The filter should be a standard javax servlet Filter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an empty line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

docs/security.md Outdated
@@ -258,3 +258,51 @@ If you want to use the command `curl`, you can follow the commands:
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
```

## Custom filters
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to move doc to GravitinoServer Configuration because Custom filters is general and not limited to safety

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to move this part to server configurations, not here. Since user can configure other filters like redirect, it is not purely a security related feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

docs/security.md Outdated

```shell
wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlets/9.4.51.v20230217/jetty-servlets-9.4.51.v20230217.jar
cp jetty-servlets-9.4.51.v20230217.jar <gravitno home>/libs
Copy link
Contributor

Choose a reason for hiding this comment

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

gravitno home -> gravitino home

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

jerryshao pushed a commit that referenced this pull request Dec 20, 2023
…ty.md` (#1214)

### What changes were proposed in this pull request?

Modify the required value for the document `security.md`.
I modify some document mistakes by the way.

### Why are the changes needed?

According the review
#1191 (comment)
, modify the required value. If a config option has a default value,
this config option is not required.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
No need.

---------

Co-authored-by: Heng Qin <[email protected]>
github-actions bot pushed a commit that referenced this pull request Dec 20, 2023
…ty.md` (#1214)

### What changes were proposed in this pull request?

Modify the required value for the document `security.md`.
I modify some document mistakes by the way.

### Why are the changes needed?

According the review
#1191 (comment)
, modify the required value. If a config option has a default value,
this config option is not required.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
No need.

---------

Co-authored-by: Heng Qin <[email protected]>
jerryshao pushed a commit that referenced this pull request Dec 20, 2023
…ty.md` (#1223)

### What changes were proposed in this pull request?

Modify the required value for the document `security.md`.
I modify some document mistakes by the way.

### Why are the changes needed?

According the review
#1191 (comment)
, modify the required value. If a config option has a default value,
this config option is not required.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
No need.

Co-authored-by: qqqttt123 <[email protected]>
Co-authored-by: Heng Qin <[email protected]>
@jerryshao jerryshao changed the title [ISSUE-1190] feat(server-common): Support custom filters [#1190] feat(server-common): Support custom filters Dec 21, 2023
docs/security.md Outdated

```shell
wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlets/9.4.51.v20230217/jetty-servlets-9.4.51.v20230217.jar
cp jetty-servlets-9.4.51.v20230217.jar <gravitino home>/libs
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please change to <GRAVITINO_HOME>/libs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@jerryshao
Copy link
Contributor

Can you please add some UTs, at least to test the correctness of the configurations?

@jerryshao
Copy link
Contributor

jerryshao commented Dec 21, 2023

Also, I think we should support cors filter by our own, rather than letting users to configure it. So you should have a new PR to implement cors filter.

@qqqttt123
Copy link
Contributor Author

Also, I think we should support cors filter by our own, rather than letting users to configure it. So you should have a new PR to implement cors filter.

Jetty have implemented CORS filters: org.eclipse.jetty.servlets.CrossOriginFilter . Why do we reuse it? You can see my test.

@jerryshao
Copy link
Contributor

jerryshao commented Dec 21, 2023

You should at least wrap the jetty's implementation and provide gravitino configurations. Cors support is very important for all the web based apps, like Livy, Zeppelin, I don't see them letting users configure a filter to achieve this.

a) Users don't know where's the right filter they want, and how to enable this, unless they read the code of that filter. Here jetty for example, how did users configure cors without knowing Jetty?
b) Spark is not a web based app, so don't take Spark as an example for everything.

@qqqttt123
Copy link
Contributor Author

You should at least wrap the jetty's implementation and provide gravitino configurations. Cors support is very important for all the web based apps, like Livy, Zeppelin, I don't see them letting users configure a filter to achieve this.

a) Users don't know where's the right filter they want, and how to enable this, unless they read the code of that filter. Here jetty for example, how did users configure cors without knowing Jetty? b) Spark is not a web based app, so don't take Spark as an example for everything.

Ok, I will prefer wrapping the CORS filter of Jetty.

@qqqttt123
Copy link
Contributor Author

Can you please add some UTs, at least to test the correctness of the configurations?

Fixed.

@jerryshao jerryshao merged commit 18feb15 into apache:main Dec 21, 2023
11 checks passed
@qqqttt123 qqqttt123 deleted the ISSUE-42 branch December 22, 2023 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] Support the custom filters
5 participants