-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Servlerless API protection with annotations #93607
Changes from all commits
a58cbd5
0bc04b2
f686fb3
045d5a2
5160f09
9392dee
765df4f
c1d0f31
771a68f
2c4ae9a
daa5559
85c864f
b9ef1bc
4211d93
2624c48
5b59124
a030cb6
3527957
d7b6477
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 93607 | ||
summary: Servlerless API protection with annotations | ||
area: Indices APIs | ||
type: enhancement | ||
issues: [] |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||
/* | ||||||||||||
* 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 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 or the Server | ||||||||||||
* Side Public License, v 1. | ||||||||||||
*/ | ||||||||||||
|
||||||||||||
package org.elasticsearch.rest; | ||||||||||||
|
||||||||||||
public enum Scope { | ||||||||||||
PUBLIC, // available to all requests | ||||||||||||
INTERNAL // available only to requests with a X-elastic-internal-origin header | ||||||||||||
} | ||||||||||||
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. The rest API spec encodes Lines 46 to 50 in d27102f
Should we look into merging the two concepts? See: #56104 cc @sethmlarson 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 think this is slightly different, in that Scope here is specifically about serverless, while Visibility applies to self managed ES. The name "scope" should probably be more specific to make that clear. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.rest; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* This annotation is meant to be applied to RestHandler classes, and is used to determine which RestHandlers are available to requests | ||
* at runtime in Serverless mode. This annotation is unused when not running in serverless mode. If this annotation is not present in a | ||
* RestHandler, then that RestHandler is not available at all in Serverless mode. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface ServerlessScope { | ||
Scope value(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.RestResponse; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.rest.Scope; | ||
import org.elasticsearch.rest.ServerlessScope; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
@@ -24,6 +26,7 @@ | |
import static org.elasticsearch.rest.RestRequest.Method.GET; | ||
import static org.elasticsearch.rest.RestRequest.Method.HEAD; | ||
|
||
@ServerlessScope(Scope.INTERNAL) | ||
public class RestMainAction extends BaseRestHandler { | ||
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. Are we sure the main action is in scope for serverless? In its current form it exposes a bunch of information that will not make sense in serverless: cluster name, cluster uuid, build information (which includes the self managed version number). Maybe this should be internal to start? 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 hmm good point. I'll change it to internal. 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. Done. |
||
|
||
@Override | ||
|
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.
Perhaps my suggestion about a better error message could be handled with a static dummy handler (that has no scope), and then an else case here which returns the nicer error response?