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

chore(server): clear context after req done #2470

Merged
merged 28 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ae90955
chore(server): update swagger info for default server profile
SunnyBoy-WYH Jan 19, 2024
bb67693
chore(server): update swagger info for default server profile
SunnyBoy-WYH Jan 19, 2024
13f916f
fix(server): arthas default bind ip should not be 0.0.0.0
SunnyBoy-WYH Jan 27, 2024
30f1821
Merge branch 'master' into arthas-bind-ip
SunnyBoy-WYH Jan 27, 2024
2519b39
fix(server): arthas default bind ip should not be 0.0.0.0
SunnyBoy-WYH Jan 27, 2024
c787baf
Merge branch 'master' into arthas-bind-ip
SunnyBoy-WYH Feb 21, 2024
7d75e0d
fix(server): fix the bug which promtheus cant collect hg metric
SunnyBoy-WYH Feb 21, 2024
552dcb8
fix(server): fix the arthas default bind ip to 127.0.0.1
SunnyBoy-WYH Feb 27, 2024
ba74aaa
fix(server): clear auth context (TLS) after req done
SunnyBoy-WYH Mar 3, 2024
4f7fc0f
fix(server): clear auth context (TLS) after req done
SunnyBoy-WYH Mar 3, 2024
43288d9
fix: security bug
zyxxoo Jan 19, 2024
6104ed6
improve
zyxxoo Jan 19, 2024
906c0de
fix(server): white list change to fixed and flexable
SunnyBoy-WYH Mar 6, 2024
177e513
Merge branch 'arthas-bind-ip' into fix-context
SunnyBoy-WYH Mar 6, 2024
165b5c8
fix(server): white list change to fixed and flexable
SunnyBoy-WYH Mar 6, 2024
7eeda25
fix(server): white list change to fixed and flexable
SunnyBoy-WYH Mar 6, 2024
5aa1a40
fix(server): white list change to fixed and flexable
SunnyBoy-WYH Mar 6, 2024
6030882
Merge branch 'master' into pr/2470
imbajin Mar 8, 2024
41459f5
remove login from whiteList
imbajin Mar 8, 2024
1435e44
Merge branch 'master' into fix-context
imbajin Mar 9, 2024
3643116
Update AccessLogFilter.java
imbajin Mar 9, 2024
7484ab3
Update AuthenticationFilter.java
imbajin Mar 9, 2024
6a50b99
fix(server): white list change to fixed and flexable
SunnyBoy-WYH Mar 10, 2024
ed2b24a
fix(server): better code
SunnyBoy-WYH Mar 13, 2024
80c1634
fix(server): better code
SunnyBoy-WYH Mar 13, 2024
ed250f2
fix(server): better code
SunnyBoy-WYH Mar 13, 2024
2e3325c
fix(server): better code
SunnyBoy-WYH Mar 18, 2024
5817ccd
tiny improve
imbajin Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void filter(ContainerRequestContext requestContext,

// Unset the context in "HugeAuthenticator", need distinguish Graph/Auth server lifecycle
GraphManager manager = managerProvider.get();
// TODO transfer Authorizer if we need after.
// TODO: transfer Authorizer if we need after.
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need TODO mark anymore since it's done

if (manager.requireAuthentication()) {
manager.unauthorize(requestContext.getSecurityContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"versions",
"openapi.json"
);
// Remove auth/login API from white list
/** Remove auth/login API from whitelist */
Copy link
Contributor

Choose a reason for hiding this comment

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

one * is ok

private static final Set<String> FLEXIBLE_WHITE_API_SET = ImmutableSet.of();

private static Boolean enabledWhiteIpCheck;
Expand Down Expand Up @@ -107,7 +107,7 @@
E.checkState(manager != null, "Context GraphManager is absent");

if (!manager.requireAuthentication()) {
// Return anonymous user with admin role if disable authentication
// Return anonymous user with an admin role if disable authentication
return User.ANONYMOUS;
}

Expand Down Expand Up @@ -135,38 +135,32 @@
boolean whiteIpEnabled = manager.authManager().getWhiteIpStatus();
if (!path.contains(STRING_WHITE_IP_LIST) && whiteIpEnabled &&
!whiteIpList.contains(remoteIp)) {
throw new ForbiddenException(
String.format("Remote ip '%s' is not permitted",
remoteIp));
throw new ForbiddenException(String.format("Remote ip '%s' is not permitted",

Check warning on line 138 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L138

Added line #L138 was not covered by tests
remoteIp));
}
}

Map<String, String> credentials = new HashMap<>();
// Extract authentication credentials
String auth = context.getHeaderString(HttpHeaders.AUTHORIZATION);
if (auth == null) {
throw new NotAuthorizedException(
"Authentication credentials are required",
"Missing authentication credentials");
throw new NotAuthorizedException("Authentication credentials are required",
"Missing authentication credentials");
}

if (auth.startsWith(BASIC_AUTH_PREFIX)) {
auth = auth.substring(BASIC_AUTH_PREFIX.length());
auth = new String(DatatypeConverter.parseBase64Binary(auth),
Charsets.ASCII_CHARSET);
auth = new String(DatatypeConverter.parseBase64Binary(auth), Charsets.ASCII_CHARSET);
String[] values = auth.split(":");
if (values.length != 2) {
throw new BadRequestException(
"Invalid syntax for username and password");
throw new BadRequestException("Invalid syntax for username and password");

Check warning on line 156 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L156

Added line #L156 was not covered by tests
}

final String username = values[0];
final String password = values[1];

if (StringUtils.isEmpty(username) ||
StringUtils.isEmpty(password)) {
throw new BadRequestException(
"Invalid syntax for username and password");
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
throw new BadRequestException("Invalid syntax for username and password");

Check warning on line 163 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L163

Added line #L163 was not covered by tests
}

credentials.put(HugeAuthenticator.KEY_USERNAME, username);
Expand All @@ -175,8 +169,7 @@
String token = auth.substring(BEARER_TOKEN_PREFIX.length());
credentials.put(HugeAuthenticator.KEY_TOKEN, token);
} else {
throw new BadRequestException(
"Only HTTP Basic or Bearer authentication is supported");
throw new BadRequestException("Only HTTP Basic or Bearer authentication is supported");

Check warning on line 172 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L172

Added line #L172 was not covered by tests
}

credentials.put(HugeAuthenticator.KEY_ADDRESS, peer);
Expand All @@ -186,8 +179,7 @@
try {
return manager.authenticate(credentials);
} catch (AuthenticationException e) {
throw new NotAuthorizedException("Authentication failed",
e.getMessage());
throw new NotAuthorizedException("Authentication failed", e.getMessage());
}
}

Expand Down Expand Up @@ -251,7 +243,7 @@
requiredPerm = RequiredPerm.fromPermission(required);

/*
* Replace owner value(it may be a variable) if the permission
* Replace owner value (it may be a variable) if the permission
* format like: "$owner=$graph $action=vertex_write"
*/
String owner = requiredPerm.owner();
Expand Down Expand Up @@ -318,7 +310,7 @@
public static boolean isWhiteAPI(ContainerRequestContext context) {
String path = context.getUriInfo().getPath();
if (FIXED_WHITE_API_SET.contains(path)) {
return true;

Check warning on line 313 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L313

Added line #L313 was not covered by tests
}

for (String whiteApi : FLEXIBLE_WHITE_API_SET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ default User authenticate(final Map<String, String> credentials)
}

HugeGraphAuthProxy.logUser(user, credentials.get(KEY_PATH));
// Set authentication context & unset in AccessLogFilter
// TODO: Ensure context lifecycle in GraphServer & AuthServer(#AccessLogFilter)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need TODO mark anymore since it's done

HugeGraphAuthProxy.setContext(new Context(user));

return user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1752,9 +1752,9 @@ public void apply(Traversal.Admin<?, ?> traversal) {
}

/*
* Verify gremlin-execute permission for user gremlin(in gremlin-
* server-exec worker) and gremlin job(in task worker).
* But don't check permission in rest worker, because the following
* Verify gremlin-execute permission for user gremlin (in gremlin-server-exec worker)
* and gremlin job(in task worker).
* But don't check permission in rest worker because the following
* places need to call traversal():
* 1.vertices/edges rest api
* 2.oltp rest api (like crosspointpath/neighborrank)
Expand Down
Loading