Skip to content

Commit 04d806d

Browse files
NIFI-14541 Added Scoped Authorization for Flow Registry Clients
- Added Registry Client Resource Type with path nested under Controller - Updated Controller Resource Flow Registry Client methods to use new Authorizable resolution
1 parent bfdb2c9 commit 04d806d

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ public String getSafeDescription() {
553553
case InputPort -> "Input Port";
554554
case OutputPort -> "Output Port";
555555
case Processor -> "Processor";
556+
case RegistryClient -> "Registry Client";
556557
case RemoteProcessGroup -> "Remote Process Group";
557558
case ReportingTask -> "Reporting Task";
558559
case FlowAnalysisRule -> "Flow Analysis Rule";

nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceType.java

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum ResourceType {
3535
RemoteProcessGroup("/remote-process-groups"),
3636
ReportingTask("/reporting-tasks"),
3737
FlowAnalysisRule("/controller/flow-analysis-rules"),
38+
RegistryClient("/controller/registry-clients"),
3839
Resource("/resources"),
3940
SiteToSite("/site-to-site"),
4041
DataTransfer("/data-transfer"),

nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/StandardFlowRegistryClientNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Authorizable getParentAuthorizable() {
9999

100100
@Override
101101
public Resource getResource() {
102-
return ResourceFactory.getComponentResource(ResourceType.Controller, getIdentifier(), getName());
102+
return ResourceFactory.getComponentResource(ResourceType.RegistryClient, getIdentifier(), getName());
103103
}
104104

105105
@Override

nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/authorization/StandardAuthorizableLookup.java

+3
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ private Authorizable getAccessPolicyByResource(final ResourceType resourceType,
644644
case ProcessGroup:
645645
authorizable = getProcessGroup(componentId).getAuthorizable();
646646
break;
647+
case RegistryClient:
648+
authorizable = getFlowRegistryClient(componentId).getAuthorizable();
649+
break;
647650
case RemoteProcessGroup:
648651
authorizable = getRemoteProcessGroup(componentId);
649652
break;

nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java

+28-13
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ private VerifyConfigRequestEntity createVerifyFlowAnalysisRuleConfigRequestEntit
14431443
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
14441444
},
14451445
security = {
1446-
@SecurityRequirement(name = "Read - /flow")
1446+
@SecurityRequirement(name = "Read - /controller")
14471447
}
14481448
)
14491449
public Response getFlowRegistryClients() {
@@ -1481,6 +1481,7 @@ public Response getFlowRegistryClients() {
14811481
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
14821482
},
14831483
security = {
1484+
@SecurityRequirement(name = "Read - /controller"),
14841485
@SecurityRequirement(name = "Write - /controller")
14851486
}
14861487
)
@@ -1569,7 +1570,7 @@ public Response createFlowRegistryClient(
15691570
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
15701571
},
15711572
security = {
1572-
@SecurityRequirement(name = "Read - /controller")
1573+
@SecurityRequirement(name = "Read - /controller/registry-clients/{id}")
15731574
}
15741575
)
15751576
public Response getFlowRegistryClient(
@@ -1584,7 +1585,10 @@ public Response getFlowRegistryClient(
15841585
}
15851586

15861587
// authorize access
1587-
authorizeController(RequestAction.READ);
1588+
serviceFacade.authorizeAccess(lookup -> {
1589+
final Authorizable authorizable = lookup.getFlowRegistryClient(id).getAuthorizable();
1590+
authorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
1591+
});
15881592

15891593
// get the flow registry client
15901594
final FlowRegistryClientEntity entity = serviceFacade.getRegistryClient(id);
@@ -1613,7 +1617,7 @@ public Response getFlowRegistryClient(
16131617
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
16141618
},
16151619
security = {
1616-
@SecurityRequirement(name = "Write - /controller")
1620+
@SecurityRequirement(name = "Write - /controller/registry-clients/{id}")
16171621
}
16181622
)
16191623
public Response updateFlowRegistryClient(
@@ -1635,8 +1639,11 @@ public Response updateFlowRegistryClient(
16351639
throw new IllegalArgumentException("Revision must be specified.");
16361640
}
16371641

1638-
// authorize access
1639-
authorizeController(RequestAction.WRITE);
1642+
// Authorize Read before Write Action
1643+
serviceFacade.authorizeAccess(lookup -> {
1644+
final Authorizable authorizable = lookup.getFlowRegistryClient(id).getAuthorizable();
1645+
authorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
1646+
});
16401647

16411648
// ensure the ids are the same
16421649
final FlowRegistryClientDTO requestRegistryClient = requestFlowRegistryClientEntity.getComponent();
@@ -1662,7 +1669,8 @@ public Response updateFlowRegistryClient(
16621669
requestFlowRegistryClientEntity,
16631670
requestRevision,
16641671
lookup -> {
1665-
authorizeController(RequestAction.WRITE);
1672+
final Authorizable authorizable = lookup.getFlowRegistryClient(id).getAuthorizable();
1673+
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
16661674
},
16671675
null,
16681676
(revision, registryClientEntity) -> {
@@ -1702,7 +1710,7 @@ public Response updateFlowRegistryClient(
17021710
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
17031711
},
17041712
security = {
1705-
@SecurityRequirement(name = "Write - /controller")
1713+
@SecurityRequirement(name = "Write - /controller/registry-clients/{id}")
17061714
}
17071715
)
17081716
public Response deleteFlowRegistryClient(
@@ -1731,7 +1739,10 @@ public Response deleteFlowRegistryClient(
17311739
}
17321740

17331741
// authorize access
1734-
authorizeController(RequestAction.WRITE);
1742+
serviceFacade.authorizeAccess(lookup -> {
1743+
final Authorizable authorizable = lookup.getFlowRegistryClient(id).getAuthorizable();
1744+
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
1745+
});
17351746

17361747
final FlowRegistryClientEntity requestFlowRegistryClientEntity = new FlowRegistryClientEntity();
17371748
requestFlowRegistryClientEntity.setId(id);
@@ -1743,7 +1754,8 @@ public Response deleteFlowRegistryClient(
17431754
requestFlowRegistryClientEntity,
17441755
requestRevision,
17451756
lookup -> {
1746-
authorizeController(RequestAction.WRITE);
1757+
final Authorizable authorizable = lookup.getFlowRegistryClient(id).getAuthorizable();
1758+
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
17471759
},
17481760
() -> serviceFacade.verifyDeleteRegistry(id),
17491761
(revision, registryClientEntity) -> {
@@ -1776,7 +1788,7 @@ public Response deleteFlowRegistryClient(
17761788
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
17771789
},
17781790
security = {
1779-
@SecurityRequirement(name = "Read - /controller/registry-clients/{uuid}")
1791+
@SecurityRequirement(name = "Read - /controller/registry-clients/{id}")
17801792
}
17811793
)
17821794
public Response getPropertyDescriptor(
@@ -1804,7 +1816,10 @@ public Response getPropertyDescriptor(
18041816
}
18051817

18061818
// authorize access
1807-
authorizeController(RequestAction.READ);
1819+
serviceFacade.authorizeAccess(lookup -> {
1820+
final Authorizable authorizable = lookup.getFlowRegistryClient(id).getAuthorizable();
1821+
authorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
1822+
});
18081823

18091824
// get the property descriptor
18101825
final PropertyDescriptorDTO descriptor = serviceFacade.getRegistryClientPropertyDescriptor(id, propertyName, sensitive);
@@ -1837,7 +1852,7 @@ public Response getPropertyDescriptor(
18371852
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
18381853
},
18391854
security = {
1840-
@SecurityRequirement(name = "Read - /flow")
1855+
@SecurityRequirement(name = "Read - /controller")
18411856
}
18421857
)
18431858
public Response getRegistryClientTypes() {

0 commit comments

Comments
 (0)