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

RBAC integration #168

Merged
merged 1 commit into from
Jun 24, 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 @@ -33,6 +33,9 @@
public class ClientRequestHandler {
private final Client client;

private final String FROM_HEADER = "from";
private final String HEADER_VALUE = "test";

public ClientRequestHandler(
ClientConfig config, ClientHandler handler, ClientFilter... filters) {
ObjectMapper objectMapper = new ObjectMapperProvider().getObjectMapper();
Expand Down Expand Up @@ -60,22 +63,25 @@ public BulkResponse delete(URI uri, Object body) {
if (body != null) {
return client.resource(uri)
.type(MediaType.APPLICATION_JSON_TYPE)
.header(FROM_HEADER, HEADER_VALUE)
.delete(BulkResponse.class, body);
} else {
client.resource(uri).delete();
client.resource(uri).header(FROM_HEADER, HEADER_VALUE).delete();
}
return null;
}

public ClientResponse get(URI uri) {
return client.resource(uri)
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN)
.header(FROM_HEADER, HEADER_VALUE)
.get(ClientResponse.class);
}

public WebResource.Builder getWebResourceBuilder(URI URI, Object entity) {
return client.resource(URI)
.type(MediaType.APPLICATION_JSON)
.header(FROM_HEADER, HEADER_VALUE)
.entity(entity)
.accept(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,40 @@ public void populateTaskData(TaskModel taskModel) {
}
}

public boolean hasAccess(Object[] args, List<String> labels) {
return executionDAO.hasAccess(args, labels);
}

public boolean exists(Object[] args) {
return executionDAO.exists(args);
}

public List<String> getUserWorkflowIds(List<String> labels) {
return executionDAO.getUserWorkflowIds(labels);
}

public List<String> getPresentIds(List<String> ids) {
return executionDAO.getPresentIds(ids);
}

public SearchResult<String> getSearchResultIds(List<String> roles) {
return executionDAO.getSearchResultIds(roles);
}

public SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds) {
return indexDAO.getSummaries(searchResultIds);
}

public SearchResult<Workflow> getUserWorkflows(SearchResult<String> searchResultIds) {
final List<Workflow> workflows =
searchResultIds.getResults().stream()
.map(id -> executionDAO.getWorkflow(id, false))
.filter(Objects::nonNull)
.map(WorkflowModel::toWorkflow)
.toList();
return new SearchResult<>(workflows.size(), workflows);
}

class DelayWorkflowUpdate implements Runnable {

private final String workflowId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,9 @@ public List<String> searchArchivableWorkflows(String indexName, long archiveTtlD
public long getWorkflowCount(String query, String freeText) {
return 0;
}

@Override
public SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds) {
JumasJM marked this conversation as resolved.
Show resolved Hide resolved
return new SearchResult<>(0, Collections.emptyList());
}
}
11 changes: 11 additions & 0 deletions core/src/main/java/com/netflix/conductor/dao/ExecutionDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.netflix.conductor.common.metadata.events.EventExecution;
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.run.SearchResult;
import com.netflix.conductor.model.TaskModel;
import com.netflix.conductor.model.WorkflowModel;

Expand Down Expand Up @@ -222,4 +223,14 @@ List<WorkflowModel> getWorkflowsByCorrelationId(
default List<WorkflowModel> getWorkflowFamily(String workflowId, boolean summaryOnly) {
throw new UnsupportedOperationException();
}

boolean hasAccess(Object[] args, List<String> labels);

boolean exists(Object[] args);

List<String> getUserWorkflowIds(List<String> labels);

List<String> getPresentIds(List<String> ids);

SearchResult<String> getSearchResultIds(List<String> roles);
}
2 changes: 2 additions & 0 deletions core/src/main/java/com/netflix/conductor/dao/IndexDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,6 @@ CompletableFuture<Void> asyncUpdateTask(
* @return Number of matches for the query
*/
long getWorkflowCount(String query, String freeText);

SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds);
}
9 changes: 9 additions & 0 deletions core/src/main/java/com/netflix/conductor/dao/MetadataDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Optional;

import com.netflix.conductor.common.metadata.BaseDef;
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;

Expand Down Expand Up @@ -86,4 +87,12 @@ public interface MetadataDAO {
* @return List the latest versions of the workflow definitions
*/
List<WorkflowDef> getAllWorkflowDefsLatestVersions();

boolean hasAccess(Object[] args, List<String> labels, String uri);

boolean exists(Object[] args, String uri);

List<? extends BaseDef> getUserTaskDefs(List<String> roles);

List<? extends BaseDef> getUserWorkflowDefs(List<String> roles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,32 @@ public ExternalStorageLocation getExternalStorageLocation(
public List<String> getWorkflowPath(String workflowId) {
return executionDAOFacade.getWorkflowPath(workflowId);
}

public boolean hasAccess(Object[] args, List<String> labels) {
return executionDAOFacade.hasAccess(args, labels);
}

public boolean exists(Object[] args) {
return executionDAOFacade.exists(args);
}

public List<String> getUserWorkflowIds(List<String> labels) {
return executionDAOFacade.getUserWorkflowIds(labels);
}

public List<String> getPresentIds(List<String> ids) {
return executionDAOFacade.getPresentIds(ids);
}

public SearchResult<String> getSearchResultIds(List<String> roles) {
return executionDAOFacade.getSearchResultIds(roles);
}

public SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds) {
return executionDAOFacade.getSummaries(searchResultIds);
}

public SearchResult<Workflow> getUserWorkflows(SearchResult<String> searchResultIds) {
return executionDAOFacade.getUserWorkflows(searchResultIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.springframework.validation.annotation.Validated;

import com.netflix.conductor.common.metadata.BaseDef;
import com.netflix.conductor.common.metadata.events.EventHandler;
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
Expand Down Expand Up @@ -156,4 +157,12 @@ List<EventHandler> getEventHandlersForEvent(
boolean activeOnly);

List<WorkflowDef> getWorkflowDefsLatestVersions();

boolean hasAccess(Object[] args, List<String> labels, String uri);

boolean exists(Object[] args, String uri);

List<? extends BaseDef> getUserTaskDefs(List<String> roles);

List<? extends BaseDef> getUserWorkflowDefs(List<String> roles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.stereotype.Service;

import com.netflix.conductor.common.constraints.OwnerEmailMandatoryConstraint;
import com.netflix.conductor.common.metadata.BaseDef;
import com.netflix.conductor.common.metadata.events.EventHandler;
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
Expand Down Expand Up @@ -223,6 +224,26 @@ public List<WorkflowDef> getWorkflowDefsLatestVersions() {
return metadataDAO.getAllWorkflowDefsLatestVersions();
}

@Override
public boolean hasAccess(Object[] args, List<String> labels, String uri) {
return metadataDAO.hasAccess(args, labels, uri);
}

@Override
public boolean exists(Object[] args, String uri) {
return metadataDAO.exists(args, uri);
}

@Override
public List<? extends BaseDef> getUserTaskDefs(List<String> roles) {
return metadataDAO.getUserTaskDefs(roles);
}

@Override
public List<? extends BaseDef> getUserWorkflowDefs(List<String> roles) {
return metadataDAO.getUserWorkflowDefs(roles);
}

public Map<String, ? extends Iterable<WorkflowDefSummary>> getWorkflowNamesAndVersions() {
List<WorkflowDef> workflowDefs = metadataDAO.getAllWorkflowDefs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,18 @@ ExternalStorageLocation getExternalStorageLocation(
List<String> getWorkflowPath(String workflowId);

List<Workflow> getWorkflowFamily(String workflowId, boolean summaryOnly);

boolean hasAccess(Object[] args, List<String> labels);

boolean exists(Object[] args);

List<String> getUserWorkflowIds(List<String> labels);

List<String> getPresentIds(List<String> ids);

SearchResult<String> getSearchResultIds(List<String> roles);

SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds);

SearchResult<Workflow> getUserWorkflows(SearchResult<String> searchResultIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,41 @@ public List<Workflow> getWorkflowFamily(String workflowId, boolean summaryOnly)
return workflows;
}

@Override
public boolean hasAccess(Object[] args, List<String> labels) {
return executionService.hasAccess(args, labels);
}

@Override
public boolean exists(Object[] args) {
return executionService.exists(args);
}

@Override
public List<String> getUserWorkflowIds(List<String> labels) {
return executionService.getUserWorkflowIds(labels);
}

@Override
public List<String> getPresentIds(List<String> ids) {
return executionService.getPresentIds(ids);
}

@Override
public SearchResult<String> getSearchResultIds(List<String> roles) {
return executionService.getSearchResultIds(roles);
}

@Override
public SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds) {
return executionService.getSummaries(searchResultIds);
}

@Override
public SearchResult<Workflow> getUserWorkflows(SearchResult<String> searchResultIds) {
return executionService.getUserWorkflows(searchResultIds);
}

/**
* Removes the workflow from the system.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ public long getWorkflowCount(String query, String freeText) {
return count(query, freeText, WORKFLOW_DOC_TYPE);
}

@Override
public SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds) {
throw new UnsupportedOperationException(
"getSummaries is not supported in ElasticSearchDAOV6");
}

@Override
public SearchResult<String> searchTasks(
String query, String freeText, int start, int count, List<String> sort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,12 @@ public long getWorkflowCount(String query, String freeText) {
}
}

@Override
public SearchResult<WorkflowSummary> getSummaries(SearchResult<String> searchResultIds) {
throw new UnsupportedOperationException(
"getSummaries is not supported in ElasticSearchRestDAOV6");
}

private long getObjectCounts(String structuredQuery, String freeTextQuery, String docType)
throws ParserException, IOException {
QueryBuilder queryBuilder = boolQueryBuilder(structuredQuery, freeTextQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.netflix.conductor.common.metadata.events.EventExecution;
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.run.SearchResult;
import com.netflix.conductor.core.config.ConductorProperties;
import com.netflix.conductor.core.exception.TransientException;
import com.netflix.conductor.dao.ConcurrentExecutionLimitDAO;
Expand Down Expand Up @@ -726,6 +727,31 @@ public void removeEventExecution(EventExecution eventExecution) {
}
}

@Override
public boolean hasAccess(Object[] args, List<String> labels) {
return false;
}

@Override
public boolean exists(Object[] args) {
return false;
}

@Override
public List<String> getUserWorkflowIds(List<String> labels) {
return List.of();
}

@Override
public List<String> getPresentIds(List<String> ids) {
return List.of();
}

@Override
public SearchResult<String> getSearchResultIds(List<String> roles) {
return new SearchResult<>(0, Collections.emptyList());
}

public List<EventExecution> getEventExecutions(
String eventHandlerName, String eventName, String messageId, int max) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

import com.netflix.conductor.common.metadata.BaseDef;
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
import com.netflix.conductor.core.config.ConductorProperties;
Expand Down Expand Up @@ -320,6 +321,28 @@ public List<WorkflowDef> getAllWorkflowDefsLatestVersions() {
return workflows;
}

@Override
public boolean hasAccess(Object[] args, List<String> labels, String uri) {
throw new UnsupportedOperationException("hasAccess is not supported in RedisMetadataDAO");
}

@Override
public boolean exists(Object[] args, String uri) {
throw new UnsupportedOperationException("exists is not supported in RedisMetadataDAO");
}

@Override
public List<? extends BaseDef> getUserTaskDefs(List<String> roles) {
throw new UnsupportedOperationException(
"getUserTaskDefs is not supported in RedisMetadataDAO");
}

@Override
public List<? extends BaseDef> getUserWorkflowDefs(List<String> roles) {
throw new UnsupportedOperationException(
"getUserWorkflowDefs is not supported in RedisMetadataDAO");
}

private void _createOrUpdate(WorkflowDef workflowDef) {
// First set the workflow def
jedisProxy.hset(
Expand Down
Loading
Loading