-
Notifications
You must be signed in to change notification settings - Fork 78
feat: require permissions to use debug with modifiable actuator #4820
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
Open
pablocarle
wants to merge
38
commits into
v3.x.x
Choose a base branch
from
reboot/fix/actuator-debug
base: v3.x.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
89aae2b
wip actuator rules
b384c73
wip test
ed0e205
Merge remote-tracking branch 'origin/v3.x.x' into reboot/fix/actuator…
26cec21
Merge remote-tracking branch 'origin/v3.x.x' into reboot/fix/actuator…
54fd023
add rules, update tests
32f50ba
Merge branch 'v3.x.x' into reboot/fix/actuator-debug
pablocarle 804f279
update test
7c87ba5
Merge remote-tracking branch 'origin/v3.x.x' into reboot/fix/actuator…
20a7eed
wip tests
915f3dd
Merge remote-tracking branch 'origin/v3.x.x' into reboot/fix/actuator…
00cae0d
wip use production properties in tests
be4cee5
wip test
70d3e1a
wip tests
303d24b
fix gateway-service tests
40104a6
wip actuator tests in apiml modulith
736d1f2
fix startup issue
3c9f3f7
fix tests in apiml modulith
1a2a4c4
unit test
ffd8658
try fix GAs wip
9bde7a3
try update saf
bc9cf50
Merge remote-tracking branch 'origin/v3.x.x' into reboot/fix/actuator…
b08a00f
try authorization endpoint
8ece2a7
rollback authorization endpoint change
873a923
ai review
7055735
dummy saf logs
c7f09ed
add lower case user
dda9d1d
logs
192711b
Merge branch 'v3.x.x' into reboot/fix/actuator-debug
pablocarle a9512af
sonar and log
2bb4326
save reports
bfae899
Merge remote-tracking branch 'origin/v3.x.x' into reboot/fix/actuator…
b107ca5
try rest config
f50d7bc
add retries to tests (for sonar stage)
f1f25f8
restore config
739cf28
another retry
0ee1e33
Merge branch 'v3.x.x' into reboot/fix/actuator-debug
pablocarle 2f1ae25
try to run on a container
7ac021d
Merge branch 'reboot/fix/actuator-debug' of https://github.com/zowe/a…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...common/src/main/java/org/zowe/apiml/security/common/auth/saf/SafAuthorizationManager.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.security.common.auth.saf; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.authorization.AuthorityAuthorizationDecision; | ||
| import org.springframework.security.authorization.AuthorizationDecision; | ||
| import org.springframework.security.authorization.ReactiveAuthorizationManager; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class SafAuthorizationManager<T> implements ReactiveAuthorizationManager<T> { | ||
|
|
||
| private final SafResourceAccessVerifying safResourceAccessVerifying; | ||
| private final String safResourceClass; | ||
| private final String safResourceName; | ||
| private final String safResourceAccess; | ||
|
|
||
| @Override | ||
| public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, T object) { | ||
| // @formatter:off | ||
| return authentication.filter(Authentication::isAuthenticated) | ||
| .filter(auth -> safResourceAccessVerifying.hasSafResourceAccess(auth, safResourceClass, safResourceName, safResourceAccess)) | ||
| .map(auth -> ((AuthorizationDecision) new AuthorityAuthorizationDecision(true, List.of(new SimpleGrantedAuthority(String.format("%s.%s:%s", safResourceClass, safResourceName, safResourceAccess)))))) | ||
| .defaultIfEmpty(new AuthorityAuthorizationDecision(false, Collections.emptyList())); | ||
|
pablocarle marked this conversation as resolved.
Outdated
|
||
| // @formatter:on | ||
| } | ||
|
|
||
| } | ||
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
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
92 changes: 92 additions & 0 deletions
92
...on/src/test/java/org/zowe/apiml/security/common/auth/saf/SafAuthorizationManagerTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.security.common.auth.saf; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.security.authorization.AuthorityAuthorizationDecision; | ||
| import org.springframework.security.core.Authentication; | ||
| import reactor.core.publisher.Mono; | ||
| import reactor.test.StepVerifier; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class SafAuthorizationManagerTest { | ||
|
|
||
| private static final String RESOURCE_CLASS = "ZOWE"; | ||
| private static final String RESOURCE_NAME = "APIML.SERVICES"; | ||
| private static final String RESOURCE_ACCESS = "READ"; | ||
|
|
||
| @Mock | ||
| private SafResourceAccessVerifying safResourceAccessVerifying; | ||
|
|
||
| @Mock | ||
| private Authentication authentication; | ||
|
|
||
| private SafAuthorizationManager<Object> safAuthorizationManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| safAuthorizationManager = new SafAuthorizationManager<>(safResourceAccessVerifying, RESOURCE_CLASS, RESOURCE_NAME, RESOURCE_ACCESS); | ||
| } | ||
|
|
||
| @Nested | ||
| class GivenSafAuthorization { | ||
|
|
||
| @Test | ||
| void whenAuthenticatedAndHasAccess_thenGrantWithAuthority() { | ||
| when(authentication.isAuthenticated()).thenReturn(true); | ||
| when(safResourceAccessVerifying.hasSafResourceAccess(authentication, RESOURCE_CLASS, RESOURCE_NAME, RESOURCE_ACCESS)).thenReturn(true); | ||
|
|
||
| StepVerifier.create(safAuthorizationManager.check(Mono.just(authentication), new Object())) | ||
| .assertNext(decision -> { | ||
| assertTrue(decision.isGranted()); | ||
| var authorities = ((AuthorityAuthorizationDecision) decision).getAuthorities(); | ||
| assertEquals(1, authorities.size()); | ||
| assertEquals(String.format("%s.%s:%s", RESOURCE_CLASS, RESOURCE_NAME, RESOURCE_ACCESS), authorities.iterator().next().getAuthority()); | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void whenAuthenticatedButNoAccess_thenDenyWithoutAuthorities() { | ||
| when(authentication.isAuthenticated()).thenReturn(true); | ||
| when(safResourceAccessVerifying.hasSafResourceAccess(authentication, RESOURCE_CLASS, RESOURCE_NAME, RESOURCE_ACCESS)).thenReturn(false); | ||
|
|
||
| StepVerifier.create(safAuthorizationManager.check(Mono.just(authentication), new Object())) | ||
| .assertNext(decision -> { | ||
| assertFalse(decision.isGranted()); | ||
| assertTrue(((AuthorityAuthorizationDecision) decision).getAuthorities().isEmpty()); | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void whenNotAuthenticated_thenDenyWithoutCallingVerifier() { | ||
| when(authentication.isAuthenticated()).thenReturn(false); | ||
|
|
||
| StepVerifier.create(safAuthorizationManager.check(Mono.just(authentication), new Object())) | ||
| .assertNext(decision -> assertFalse(decision.isGranted())) | ||
| .verifyComplete(); | ||
|
|
||
| verify(safResourceAccessVerifying, never()).hasSafResourceAccess(any(), any(), any(), any()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,9 @@ safAccess: | |
| APIML.RESOURCE: | ||
| READ: | ||
| - user | ||
| APIML.DEBUG: | ||
| CONTROL: | ||
| - USER | ||
| CLASS: | ||
| RESOURCE: | ||
| READ: | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # This file is used by the SafResourceAccessDummy class for testing and when the service is running outside of z/OS | ||
| # It defines what are the access levels for SAF resources and users | ||
| # | ||
| # There are to special values of access level: | ||
| # - `FAILURE` - the check request will fail with an internal error | ||
| # - `NONE` - there is no access to the resource but the resource is defined | ||
| # | ||
| # This file is stored in `src/main/resources/mock-saf.yml` which means that it will be used by the service and its unit tests. | ||
| # If you can create a different file in `src/test/resources/mock-saf.yml` then unit tests will use different definitions. | ||
| safAccess: | ||
| ZOWE: | ||
| APIML.DEBUG: | ||
| CONTROL: | ||
| - USER |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.