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

Minor: Domain only access policy prevents bots from listing #19017

Merged
merged 4 commits into from
Dec 12, 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 @@ -14,6 +14,8 @@
import org.openmetadata.service.util.FullyQualifiedName;

public class ListFilter extends Filter<ListFilter> {
public static final String NULL_PARAM = "null";

public ListFilter() {
this(Include.NON_DELETED);
}
Expand Down Expand Up @@ -116,12 +118,24 @@ public String getTestSuiteFQNCondition() {

private String getDomainCondition(String tableName) {
String domainId = getQueryParam("domainId");
return domainId == null
? ""
: String.format(
"(%s in (SELECT entity_relationship.toId FROM entity_relationship WHERE entity_relationship.fromEntity='domain' AND entity_relationship.fromId IN (%s) AND "
+ "relation=10))",
nullOrEmpty(tableName) ? "id" : String.format("%s.id", tableName), domainId);
String entityIdColumn = nullOrEmpty(tableName) ? "id" : (tableName + ".id");
if (domainId == null) {
return "";
} else if (NULL_PARAM.equals(domainId)) {
String entityType = getQueryParam("entityType");
String entityTypeCondition =
nullOrEmpty(entityType)
? ""
: String.format("AND entity_relationship.toEntity='%s'", entityType);
return String.format(
"(%s NOT IN (SELECT entity_relationship.toId FROM entity_relationship WHERE entity_relationship.fromEntity='domain' %s AND relation=10))",
entityIdColumn, entityTypeCondition);
} else {
return String.format(
"(%s in (SELECT entity_relationship.toId FROM entity_relationship WHERE entity_relationship.fromEntity='domain' AND entity_relationship.fromId IN (%s) AND "
+ "relation=10))",
entityIdColumn, domainId);
}
}

public String getApiCollectionCondition(String apiEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public ResultList<T> listInternal(
authorizer.authorize(securityContext, operationContext, resourceContext);

// Add Domain Filter
EntityUtil.addDomainQueryParam(securityContext, filter);
EntityUtil.addDomainQueryParam(securityContext, filter, entityType);

// List
ResultList<T> resultList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty;
import static org.openmetadata.schema.type.Include.ALL;
import static org.openmetadata.schema.type.Include.NON_DELETED;
import static org.openmetadata.service.jdbi3.ListFilter.NULL_PARAM;
import static org.openmetadata.service.jdbi3.RoleRepository.DOMAIN_ONLY_ACCESS_ROLE;
import static org.openmetadata.service.security.DefaultAuthorizer.getSubjectContext;

Expand Down Expand Up @@ -688,7 +689,8 @@ public static List<EntityReference> mergedInheritedEntityRefs(
return result.stream().toList();
}

public static void addDomainQueryParam(SecurityContext securityContext, ListFilter filter) {
public static void addDomainQueryParam(
SecurityContext securityContext, ListFilter filter, String entityType) {
SubjectContext subjectContext = getSubjectContext(securityContext);
// If the User is admin then no need to add domainId in the query param
// Also if there are domain restriction on the subject context via role
Expand All @@ -697,8 +699,8 @@ public static void addDomainQueryParam(SecurityContext securityContext, ListFilt
filter.addQueryParam(
"domainId", getCommaSeparatedIdsFromRefs(subjectContext.getUserDomains()));
} else {
// TODO: Hack :(
filter.addQueryParam("domainId", "null");
filter.addQueryParam("domainId", NULL_PARAM);
filter.addQueryParam("entityType", entityType);
}
}
}
Expand Down
Loading