Skip to content

Commit f6120e0

Browse files
authored
Permit access to the API browser with the “api_browser:read” permission. (#23318)
* Permit access to the API browser with the “api_browser:read” permission. * add changelog
1 parent 7f762a8 commit f6120e0

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

UPGRADING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ can only talk to Kafka brokers with version 2.1 or newer.
6262
}
6363
}
6464
```
65+
- Access to the API browser now requires the `api_browser:read` permission. This permission can be granted by assigning
66+
the new “API Browser Reader” role to a user.
6567

6668
## REST API Endpoint Changes
6769

changelog/unreleased/pr-23318.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type = "a"
2+
message = 'API browser is now only visible to users with the role "Admin" or "API Browser Reader".'
3+
4+
issues = ["graylog-plugin-enterprise#10625"]
5+
pulls = ["23318"]

graylog2-server/src/main/java/org/graylog2/shared/rest/resources/documentation/DocumentationBrowserResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
import jakarta.ws.rs.core.MediaType;
3232
import jakarta.ws.rs.core.Response;
3333
import org.apache.shiro.authz.annotation.RequiresAuthentication;
34+
import org.apache.shiro.authz.annotation.RequiresPermissions;
3435
import org.graylog2.Configuration;
3536
import org.graylog2.configuration.HttpConfiguration;
3637
import org.graylog2.rest.RestTools;
3738
import org.graylog2.shared.rest.resources.RestResource;
3839
import org.graylog2.shared.rest.resources.csp.CSP;
40+
import org.graylog2.shared.security.RestPermissions;
3941

4042
import javax.activation.MimetypesFileTypeMap;
4143
import java.io.IOException;
@@ -49,6 +51,7 @@
4951
@Path("/api-browser")
5052
@CSP(group = CSP.SWAGGER)
5153
@RequiresAuthentication
54+
@RequiresPermissions(RestPermissions.API_BROWSER_READ)
5255
public class DocumentationBrowserResource extends RestResource {
5356
private final MimetypesFileTypeMap mimeTypes;
5457
private final HttpConfiguration httpConfiguration;

graylog2-server/src/main/java/org/graylog2/shared/security/RestPermissions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class RestPermissions implements PluginPermissions {
3232
* These should all be in the form of "domain:action", because {@link Permissions#allPermissionsMap()} below depends on it.
3333
* Should this ever change, you need to adapt the code below, too.
3434
*/
35+
public static final String API_BROWSER_READ = "api_browser:read";
3536
public static final String AUTH_HTTP_HEADER_CONFIG_EDIT = "authhttpheaderconfig:edit";
3637
public static final String AUTH_HTTP_HEADER_CONFIG_READ = "authhttpheaderconfig:read";
3738
public static final String AUTH_SERVICE_BACKEND_CREATE = "authservicebackend:create";
@@ -193,6 +194,7 @@ public class RestPermissions implements PluginPermissions {
193194
public static final String USERS_TOKENREMOVE = "users:tokenremove";
194195

195196
protected static final ImmutableSet<Permission> PERMISSIONS = ImmutableSet.<Permission>builder()
197+
.add(create(API_BROWSER_READ, ""))
196198
.add(create(AUTH_HTTP_HEADER_CONFIG_EDIT, ""))
197199
.add(create(AUTH_HTTP_HEADER_CONFIG_READ, ""))
198200
.add(create(AUTH_SERVICE_BACKEND_CREATE, ""))
@@ -383,6 +385,9 @@ public class RestPermissions implements PluginPermissions {
383385
)),
384386
BuiltinRole.create("Cluster Configuration Reader", "Allows viewing the Cluster Configuration page", ImmutableSet.of(
385387
RestPermissions.CLUSTER_CONFIGURATION_READ
388+
)),
389+
BuiltinRole.create("API Browser Reader", "Allows viewing the API browser page", ImmutableSet.of(
390+
RestPermissions.API_BROWSER_READ
386391
))
387392
).build();
388393

graylog2-web-interface/src/components/cluster-configuration/ClusterActions.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ const ClusterActions = ({ node }: Props) => {
103103
<MenuItem>Get recent system log messages</MenuItem>
104104
</LinkContainer>
105105
</IfPermitted>
106-
<MenuItem href={apiBrowserURI} target="_blank">
107-
<ExternalLink>API Browser</ExternalLink>
108-
</MenuItem>
106+
<IfPermitted permissions="api_browser:read">
107+
<MenuItem href={apiBrowserURI} target="_blank">
108+
<ExternalLink>API Browser</ExternalLink>
109+
</MenuItem>
110+
</IfPermitted>
109111
</DropdownButton>
110112
{showMessageProcessingModal && (
111113
<ConfirmDialog

graylog2-web-interface/src/components/navigation/HelpMenu.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import * as React from 'react';
1818

1919
import { NavDropdown } from 'components/bootstrap';
20-
import { Icon } from 'components/common';
20+
import { Icon, IfPermitted } from 'components/common';
2121
import DocsHelper from 'util/DocsHelper';
2222
import Routes from 'routing/Routes';
2323
import useHotkeysContext from 'hooks/useHotkeysContext';
@@ -39,7 +39,9 @@ const HelpMenu = () => {
3939

4040
<Menu.Item onClick={() => setShowHotkeysModal(true)}>Keyboard Shortcuts</Menu.Item>
4141

42-
<HelpMenuLinkItem href={Routes.global_api_browser()}>Cluster Global API browser</HelpMenuLinkItem>
42+
<IfPermitted permissions="api_browser:read">
43+
<HelpMenuLinkItem href={Routes.global_api_browser()}>Cluster Global API browser</HelpMenuLinkItem>
44+
</IfPermitted>
4345
</NavDropdown>
4446
);
4547
};

0 commit comments

Comments
 (0)