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

fix(manage-tokens): fix manage access token policy #10853

Merged
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 @@ -5,6 +5,7 @@
import static com.linkedin.metadata.Constants.*;
import static com.linkedin.metadata.authorization.ApiOperation.DELETE;
import static com.linkedin.metadata.authorization.ApiOperation.MANAGE;
import static com.linkedin.metadata.authorization.PoliciesConfig.MANAGE_ACCESS_TOKENS;

import com.datahub.authorization.AuthUtil;
import com.datahub.authorization.ConjunctivePrivilegeGroup;
Expand Down Expand Up @@ -52,9 +53,11 @@ public static boolean canManagePolicies(@Nonnull QueryContext context) {

public static boolean canGeneratePersonalAccessToken(@Nonnull QueryContext context) {
return AuthUtil.isAuthorized(
context.getAuthorizer(),
context.getActorUrn(),
PoliciesConfig.GENERATE_PERSONAL_ACCESS_TOKENS_PRIVILEGE);
context.getAuthorizer(),
context.getActorUrn(),
PoliciesConfig.GENERATE_PERSONAL_ACCESS_TOKENS_PRIVILEGE)
|| AuthUtil.isAuthorized(
context.getAuthorizer(), context.getActorUrn(), MANAGE_ACCESS_TOKENS);
}

public static boolean canManageTokens(@Nonnull QueryContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,38 @@ public class PoliciesConfig {
ApiOperation.EXISTS,
API_PRIVILEGE_MAP.get(ApiGroup.ENTITY).get(ApiOperation.EXISTS))
.build())
.put(
// regular entity level permissions + MANAGE_ACCESS_TOKENS
Constants.ACCESS_TOKEN_ENTITY_NAME,
ImmutableMap.<ApiOperation, Disjunctive<Conjunctive<Privilege>>>builder()
.put(
ApiOperation.CREATE,
Disjunctive.disjoint(
MANAGE_ACCESS_TOKENS, CREATE_ENTITY_PRIVILEGE, EDIT_ENTITY_PRIVILEGE))
.put(
ApiOperation.READ,
Disjunctive.disjoint(
MANAGE_ACCESS_TOKENS,
VIEW_ENTITY_PAGE_PRIVILEGE,
GET_ENTITY_PRIVILEGE,
EDIT_ENTITY_PRIVILEGE,
DELETE_ENTITY_PRIVILEGE))
.put(
ApiOperation.UPDATE,
Disjunctive.disjoint(MANAGE_ACCESS_TOKENS, EDIT_ENTITY_PRIVILEGE))
.put(
ApiOperation.DELETE,
Disjunctive.disjoint(MANAGE_ACCESS_TOKENS, DELETE_ENTITY_PRIVILEGE))
.put(
ApiOperation.EXISTS,
Disjunctive.disjoint(
MANAGE_ACCESS_TOKENS,
EXISTS_ENTITY_PRIVILEGE,
EDIT_ENTITY_PRIVILEGE,
DELETE_ENTITY_PRIVILEGE,
VIEW_ENTITY_PAGE_PRIVILEGE,
SEARCH_PRIVILEGE))
.build())
.build();

/**
Expand Down
Loading