Skip to content

RBAC: Actions granted for cluster A are mistakenly available for cluster B #330

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

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -27,6 +27,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -54,7 +55,9 @@ public class AccessControlService {
private final RoleBasedAccessControlProperties properties;
private final Environment environment;

@Getter
private boolean rbacEnabled = false;
@Getter
private Set<ProviderAuthorityExtractor> oauthExtractors = Collections.emptySet();

@PostConstruct
Expand Down Expand Up @@ -107,12 +110,14 @@ private boolean isAccessible(AuthenticatedUser user, AccessContext context) {
if (context.cluster() != null && !isClusterAccessible(context.cluster(), user)) {
return false;
}
return context.isAccessible(getUserPermissions(user));
return context.isAccessible(getUserPermissions(user, context.cluster()));
}

private List<Permission> getUserPermissions(AuthenticatedUser user) {
return properties.getRoles().stream()
private List<Permission> getUserPermissions(AuthenticatedUser user, String clusterName) {
return properties.getRoles()
.stream()
.filter(filterRole(user))
.filter(role -> role.getClusters().stream().anyMatch(clusterName::equalsIgnoreCase))
.flatMap(role -> role.getPermissions().stream())
.toList();
}
Expand Down Expand Up @@ -188,10 +193,6 @@ public Mono<Boolean> isConnectAccessible(String connectName, String clusterName)
);
}

public Set<ProviderAuthorityExtractor> getOauthExtractors() {
return oauthExtractors;
}

public List<Role> getRoles() {
if (!rbacEnabled) {
return Collections.emptyList();
Expand All @@ -203,7 +204,4 @@ private Predicate<Role> filterRole(AuthenticatedUser user) {
return role -> user.groups().contains(role.getName());
}

public boolean isRbacEnabled() {
return rbacEnabled;
}
}
16 changes: 13 additions & 3 deletions frontend/src/components/ACLPage/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import useAppParams from 'lib/hooks/useAppParams';
import { useAcls, useDeleteAcl } from 'lib/hooks/api/acl';
import { ClusterName } from 'lib/interfaces/cluster';
import {
Action,
KafkaAcl,
KafkaAclNamePatternType,
KafkaAclPermissionEnum,
ResourceType,
} from 'generated-sources';
import useBoolean from 'lib/hooks/useBoolean';
import { Button } from 'components/common/Button/Button';
import ACLForm from 'components/ACLPage/Form/Form';
import DeleteIcon from 'components/common/Icons/DeleteIcon';
import { useTheme } from 'styled-components';
import ACLFormContext from 'components/ACLPage/Form/AclFormContext';
import PlusIcon from 'components/common/Icons/PlusIcon';
import ActionButton from 'components/common/ActionComponent/ActionButton/ActionButton';

import * as S from './List.styled';

Expand Down Expand Up @@ -148,9 +150,17 @@ const ACList: React.FC = () => {
return (
<S.Container>
<PageHeading text="Access Control List">
<Button buttonType="primary" buttonSize="M" onClick={openFrom}>
<ActionButton
buttonType="primary"
buttonSize="M"
onClick={openFrom}
permission={{
resource: ResourceType.ACL,
action: Action.EDIT,
}}
>
<PlusIcon /> Create ACL
</Button>
</ActionButton>
</PageHeading>
<Table
columns={columns}
Expand Down