security: add authorization checks to WorkflowStatsSLAHttpHandler#16159
Open
adilburaksen wants to merge 1 commit into
Open
security: add authorization checks to WorkflowStatsSLAHttpHandler#16159adilburaksen wants to merge 1 commit into
adilburaksen wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces authorization checks in WorkflowStatsSLAHttpHandler by injecting ContextAccessEnforcer and enforcing StandardPermission.GET on workflow programs before retrieving run statistics. A review comment suggests simplifying the instantiation of ProgramReference by using its constructor directly instead of chaining methods via Ids.
Comment on lines
+88
to
+89
| ProgramReference programReference = Ids.namespace(namespaceId).appReference(appId) | ||
| .program(ProgramType.WORKFLOW, workflowId); |
There was a problem hiding this comment.
Instead of using the helper class Ids and chaining multiple method calls (Ids.namespace(...).appReference(...).program(...)), you can directly instantiate ProgramReference using its public constructor. This is more direct, improves readability, and avoids the need to import io.cdap.cdap.proto.id.Ids.
Suggested change
| ProgramReference programReference = Ids.namespace(namespaceId).appReference(appId) | |
| .program(ProgramType.WORKFLOW, workflowId); | |
| ProgramReference programReference = new ProgramReference(namespaceId, appId, | |
| ProgramType.WORKFLOW, workflowId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WorkflowStatsSLAHttpHandlerserves workflow run statistics, run details, and run comparisons for a namespace/application/workflow selected entirely from the request path, but it did not enforce any access check before reading from theStore. The handler only injectedStore,MRJobInfoFetcher, andMetricsSystemClient, so a principal could read run statistics for workflows in any namespace without an authorization check.This change adds
StandardPermission.GETenforcement on the targeted workflow program before the data read, consistent with the sibling program/workflow handlers in app-fabric.Changes
ContextAccessEnforcervia the existing@Injectconstructor (Guice resolves it fromAuthorizationEnforcementModule; the handler binding inAppFabricServiceRuntimeModuleis unchanged).enforceWorkflowAccess(namespace, app, workflow)helper that builds the workflowProgramReferenceand callscontextAccessEnforcer.enforce(programReference, StandardPermission.GET).workflowStats—.../workflows/{workflow-id}/statisticsworkflowRunDetail—.../workflows/{workflow-id}/runs/{run-id}/statisticscompare—.../workflows/{workflow-id}/runs/{run-id}/compareAll three endpoints are read-only, so
StandardPermission.GETis the appropriate permission. The enforcement mirrors the idiom already used inProgramLifecycleServiceandArtifactHttpHandler.Testing
mvn -o -pl cdap-app-fabric -am compile— BUILD SUCCESS.