Skip to content

Commit

Permalink
fix: Remove "AUTO" from jwt configuration and clean up outdated APARs…
Browse files Browse the repository at this point in the history
… from mock service (#3717)

* remove jwt AUTO configuration. clean up outdated APARs from mock service

* fix integration tests

* fix integration tests

* fix integration tests

* fix integration tests

* fix integration tests

* fix integration tests

* fix integration tests

* refactor

* refactor

* address review comments

* address review comments

* fix sonar issues

* remove jwt from gateway

* fix sonar issues

* remove CITestsZosmfPH12143 from integration tests

* run CITestsZosmfWithoutJwt with ltpa

* remove CITestsZosmfWithoutJwtWithAuthendpont tests
  • Loading branch information
Shobhajayanna authored Sep 5, 2024
1 parent aff784f commit a81abe8
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 1,157 deletions.
194 changes: 3 additions & 191 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ jobs:
APIML_SECURITY_X509_CERTIFICATESURL: https://gateway-service:10010/gateway/certificates
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
ZOSMF_APPLIEDAPARS: PH34201

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -483,126 +481,6 @@ jobs:
- uses: ./.github/actions/teardown

CITestsZosmfRsu2012:
needs: PublishJibContainers
runs-on: ubuntu-latest
container: ubuntu:latest
timeout-minutes: 15

services:
api-catalog-services:
image: ghcr.io/balhar-jakub/api-catalog-services:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
caching-service:
image: ghcr.io/balhar-jakub/caching-service:${{ github.run_id }}-${{ github.run_number }}
discoverable-client:
image: ghcr.io/balhar-jakub/discoverable-client:${{ github.run_id }}-${{ github.run_number }}
discovery-service:
image: ghcr.io/balhar-jakub/discovery-service:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
zaas-service:
image: ghcr.io/balhar-jakub/zaas-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_X509_ENABLED: true
APIML_SECURITY_X509_ACCEPTFORWARDEDCERT: true
APIML_SECURITY_X509_CERTIFICATESURL: https://gateway-service:10010/gateway/certificates
gateway-service:
image: ghcr.io/balhar-jakub/gateway-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_AUTH_JWT_CUSTOMAUTHHEADER: customJwtHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMUSERHEADER: customUserHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMAUTHHEADER: customPassticketHeader
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
ZOSMF_APPLIEDAPARS: PH12143,RSU2012

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: ./.github/actions/setup

- name: Build with Gradle
run: >
./gradlew :integration-tests:runZosmfAuthTest --info -Denvironment.config=-docker -Denvironment.offPlatform=true
-Partifactory_user=${{ secrets.ARTIFACTORY_USERNAME }} -Partifactory_password=${{ secrets.ARTIFACTORY_PASSWORD }}
- uses: ./.github/actions/dump-jacoco
if: always()

- name: Store results
uses: actions/upload-artifact@v4
if: always()
with:
name: ContainerCITestsZosmfRsu2012-${{ env.JOB_ID }}
path: |
integration-tests/build/reports/**
results/**
- uses: ./.github/actions/teardown

CITestsZosmfPH34201:
needs: PublishJibContainers
runs-on: ubuntu-latest
container: ubuntu:latest
timeout-minutes: 15

services:
api-catalog-services:
image: ghcr.io/balhar-jakub/api-catalog-services:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
caching-service:
image: ghcr.io/balhar-jakub/caching-service:${{ github.run_id }}-${{ github.run_number }}
discoverable-client:
image: ghcr.io/balhar-jakub/discoverable-client:${{ github.run_id }}-${{ github.run_number }}
discovery-service:
image: ghcr.io/balhar-jakub/discovery-service:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
zaas-service:
image: ghcr.io/balhar-jakub/zaas-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_X509_ENABLED: true
APIML_SECURITY_X509_ACCEPTFORWARDEDCERT: true
APIML_SECURITY_X509_CERTIFICATESURL: https://gateway-service:10010/gateway/certificates
gateway-service:
image: ghcr.io/balhar-jakub/gateway-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_AUTH_JWT_CUSTOMAUTHHEADER: customJwtHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMUSERHEADER: customUserHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMAUTHHEADER: customPassticketHeader
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
ZOSMF_APPLIEDAPARS: PH12143,RSU2012,PH34201

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: ./.github/actions/setup

- name: Build with Gradle
run: >
./gradlew :integration-tests:runZosmfAuthTest --info -Denvironment.config=-docker -Denvironment.offPlatform=true
-Partifactory_user=${{ secrets.ARTIFACTORY_USERNAME }} -Partifactory_password=${{ secrets.ARTIFACTORY_PASSWORD }}
# Coverage results are not stored in this job as it would not provide much additional data
- name: Store results
uses: actions/upload-artifact@v4
if: always()
with:
name: CITestsZosmfPH34201-${{ env.JOB_ID }}
path: |
integration-tests/build/reports/**
- uses: ./.github/actions/teardown

CITestsZosmfWithoutJwt:
needs: PublishJibContainers
runs-on: ubuntu-latest
Expand All @@ -628,6 +506,7 @@ jobs:
APIML_SECURITY_X509_ENABLED: true
APIML_SECURITY_X509_ACCEPTFORWARDEDCERT: true
APIML_SECURITY_X509_CERTIFICATESURL: https://gateway-service:10010/gateway/certificates
APIML_SECURITY_AUTH_ZOSMF_JWTAUTOCONFIGURATION: ltpa
gateway-service:
image: ghcr.io/balhar-jakub/gateway-service:${{ github.run_id }}-${{ github.run_number }}
env:
Expand All @@ -636,8 +515,6 @@ jobs:
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMAUTHHEADER: customPassticketHeader
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
ZOSMF_APPLIEDAPARS: ''

steps:
- uses: actions/checkout@v4
Expand All @@ -661,65 +538,6 @@ jobs:
- uses: ./.github/actions/teardown


CITestsZosmfWithoutJwtWithAuthenticateEndpoint:
needs: PublishJibContainers
runs-on: ubuntu-latest
container: ubuntu:latest
timeout-minutes: 15

services:
api-catalog-services:
image: ghcr.io/balhar-jakub/api-catalog-services:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
caching-service:
image: ghcr.io/balhar-jakub/caching-service:${{ github.run_id }}-${{ github.run_number }}
discoverable-client:
image: ghcr.io/balhar-jakub/discoverable-client:${{ github.run_id }}-${{ github.run_number }}
discovery-service:
image: ghcr.io/balhar-jakub/discovery-service:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
zaas-service:
image: ghcr.io/balhar-jakub/zaas-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_X509_ENABLED: true
APIML_SECURITY_X509_ACCEPTFORWARDEDCERT: true
APIML_SECURITY_X509_CERTIFICATESURL: https://gateway-service:10010/gateway/certificates
gateway-service:
image: ghcr.io/balhar-jakub/gateway-service:${{ github.run_id }}-${{ github.run_number }}
env:
APIML_SECURITY_AUTH_JWT_CUSTOMAUTHHEADER: customJwtHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMUSERHEADER: customUserHeader
APIML_SECURITY_AUTH_PASSTICKET_CUSTOMAUTHHEADER: customPassticketHeader
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
ZOSMF_APPLIEDAPARS: AuthenticateApar

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: ./.github/actions/setup

- name: Build with Gradle
run: >
./gradlew :integration-tests:runZosmfAuthTest --info -Denvironment.config=-docker -Denvironment.offPlatform=true
-Partifactory_user=${{ secrets.ARTIFACTORY_USERNAME }} -Partifactory_password=${{ secrets.ARTIFACTORY_PASSWORD }}
# Coverage results are not stored in this job as it would not provide much additional data
- name: Store results
uses: actions/upload-artifact@v4
if: always()
with:
name: ContainerCITestsZosmfWithoutJwtWithAuthenticateEndpoint-${{ env.JOB_ID }}
path: |
integration-tests/build/reports/**
- uses: ./.github/actions/teardown

CITestsWithRedisReplica:
needs: PublishJibContainers
runs-on: ubuntu-latest
Expand Down Expand Up @@ -1491,8 +1309,6 @@ jobs:
APIML_SECURITY_X509_CERTIFICATESURL: https://gateway-service:10010/gateway/certificates
mock-services:
image: ghcr.io/balhar-jakub/mock-services:${{ github.run_id }}-${{ github.run_number }}
env:
ZOSMF_APPLIEDAPARS: AuthenticateApar
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -1645,7 +1461,7 @@ jobs:
- uses: ./.github/actions/teardown

PublishResults:
needs: [ CITests,CITestsWithInfinispan,CITestsZosmfRsu2012,CITestsZaas,GatewayProxy,GatewayServiceRouting ]
needs: [ CITests,CITestsWithInfinispan,CITestsZaas,GatewayProxy,GatewayServiceRouting ]
runs-on: ubuntu-latest
timeout-minutes: 20

Expand All @@ -1665,10 +1481,6 @@ jobs:
with:
name: CITestsWithInfinispan-${{ env.JOB_ID }}
path: citestswithinfinispan
- uses: actions/download-artifact@v4
with:
name: ContainerCITestsZosmfRsu2012-${{ env.JOB_ID }}
path: containercitestszosmfrsu2012
- uses: actions/download-artifact@v4
with:
name: GatewayProxy-${{ env.JOB_ID }}
Expand All @@ -1684,7 +1496,7 @@ jobs:

- name: Code coverage and publish results
run: >
./gradlew --info coverage sonar -Dresults="containercitests/results,citestswithinfinispan/results,containercitestszosmfrsu2012/results,GatewayProxy/results,citestswebsocketchaoticha/results,GatewayServiceRouting/results,containercitestszaas/results"
./gradlew --info coverage sonar -Dresults="containercitests/results,citestswithinfinispan/results,GatewayProxy/results,citestswebsocketchaoticha/results,GatewayServiceRouting/results,containercitestszaas/results"
-Psonar.host.url=$SONAR_HOST_URL -Dsonar.token=$SONAR_TOKEN -Partifactory_user=$ARTIFACTORY_USERNAME -Partifactory_password=$ARTIFACTORY_PASSWORD
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class AuthConfigurationProperties {
private AuthConfigurationProperties.PassTicketAuthProperties passTicket = new AuthConfigurationProperties.PassTicketAuthProperties();

public enum JWT_AUTOCONFIGURATION_MODE {
AUTO,
LTPA,
JWT
}
Expand Down Expand Up @@ -120,7 +119,7 @@ public static class X509Cert {
public static class Zosmf {
private String serviceId;
private String jwtEndpoint = "/jwt/ibm/api/zOSMFBuilder/jwk";
private JWT_AUTOCONFIGURATION_MODE jwtAutoconfiguration = JWT_AUTOCONFIGURATION_MODE.AUTO;
private JWT_AUTOCONFIGURATION_MODE jwtAutoconfiguration = JWT_AUTOCONFIGURATION_MODE.JWT;
}

public AuthConfigurationProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static Stream<Arguments> schemas() {
String jwt = r.getBody().path("headers.cookie").toString();
try {
String issuer = JWTParser.parse(jwt.substring(COOKIE_NAME.length()).trim()).getJWTClaimsSet().toJSONObject().get("iss").toString();
assertEquals("APIML", issuer);
assertEquals("zOSMF", issuer);
} catch (ParseException e) {
fail(e);
}
Expand Down
8 changes: 2 additions & 6 deletions mock-services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ As we mainly use zOSMF to authenticate the user, there are two properties in the

The Mock can simulate different configurations of zOSMF. This can be set via the `zosmf.appliedApars` field. If left empty, base zOSMF will be mocked.
The supported APARs are:
* PH12143
* PH17867
* PH28507
* PH28532
* RSU2012
* PH34912 - which mocks the password change functionality
* PH12143 - provides JWT support to validate LTPA and JWT tokens.


Multiple APARs can be set in `zosmf.appliedApars`. Conflicting functionality will result in only one functionality mocked, but it is not guaranteed which will be mocked.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public PH12143(List<String> usernames, List<String> passwords, String keystorePa
@Override
protected ResponseEntity<?> handleAuthenticationCreate(Map<String, String> headers, HttpServletResponse response) {
if (noAuthentication(headers)) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
if (isUnauthorized(headers)) {
if (containsInvalidOrNoUser(headers) && !ltpaIsPresent(headers)) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}

Expand All @@ -42,15 +42,18 @@ protected ResponseEntity<?> handleAuthenticationCreate(Map<String, String> heade

@Override
protected ResponseEntity<?> handleAuthenticationVerify(Map<String, String> headers, HttpServletResponse response) {
return handleAuthenticationCreate(headers, response);

if (containsInvalidOrNoUser(headers) && !isValidJwtCookie(headers) && !ltpaIsPresent(headers)) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
String[] credentials = getPiecesOfCredentials(headers);
return validJwtResponse(response, credentials[0], keystorePath);
}

@Override
protected ResponseEntity<?> handleAuthenticationDelete(Map<String, String> headers) {
if (noAuthentication(headers)) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
if (isValidJwtCookie(headers) || isUnauthorized(headers)) {

if (containsInvalidOrNoUser(headers) && !ltpaIsPresent(headers) && !isValidJwtCookie(headers)) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
Expand All @@ -71,8 +74,4 @@ protected ResponseEntity<?> handleJwtKeys() {
" ]\n" +
"}", HttpStatus.OK);
}

private boolean isUnauthorized(Map<String, String> headers) {
return containsInvalidOrNoUser(headers) && !ltpaIsPresent(headers);
}
}
Loading

0 comments on commit a81abe8

Please sign in to comment.