From c24575d1cd85a7c5e241aaf00b2131c8acf4e5fd Mon Sep 17 00:00:00 2001 From: Rami Mohamed Date: Sat, 12 Sep 2026 18:35:52 +0400 Subject: [PATCH 1/3] feat: inject SIT Redis password from Secret --- helm/templates/deployment.yaml | 5 +++++ helm/values-sit.yaml | 4 ++++ helm/values.yaml | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index f3e20f6..79c9f6b 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -46,6 +46,11 @@ spec: name: {{ .Values.security.secretName | quote }} key: {{ .Values.security.secretKey | quote }} {{- end }} + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: {{ .Values.redis.secretName | quote }} + key: {{ .Values.redis.secretKey | quote }} securityContext: {{- toYaml .Values.containerSecurityContext | nindent 12 }} ports: diff --git a/helm/values-sit.yaml b/helm/values-sit.yaml index 9f8a843..da1a59c 100644 --- a/helm/values-sit.yaml +++ b/helm/values-sit.yaml @@ -4,3 +4,7 @@ runtime: security: enabled: true + +redis: + secretName: redis + secretKey: REDIS_PASSWORD diff --git a/helm/values.yaml b/helm/values.yaml index febeda7..0ad28ab 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -17,6 +17,10 @@ security: secretName: auth-service-secrets secretKey: jwt-secret +redis: + secretName: redis + secretKey: REDIS_PASSWORD + service: type: ClusterIP port: 8080 From b8a4b8bc8ea8582453043144053d4a65f48ac873 Mon Sep 17 00:00:00 2001 From: Rami Mohamed Date: Sat, 12 Sep 2026 18:39:09 +0400 Subject: [PATCH 2/3] fix: require ownership scopes for customer routes --- README.md | 6 ++++-- .../apigateway/security/GatewaySecurityConfiguration.java | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 30a8bcd..40bd882 100644 --- a/README.md +++ b/README.md @@ -124,12 +124,14 @@ The gateway emits one ECS-formatted JSON completion event per exchange. It conta The gateway is an internal Kubernetes `ClusterIP` Service in SIT. Authentication is enabled by default and validates JWTs before enforcing these scopes. A local test must explicitly set `GATEWAY_SECURITY_ENABLED=false` to use the bypass configuration; do not use that bypass in a deployed environment. -- `admin.internal` for `/admin/**` and centralized API documentation. +- `admin.internal` for `/admin/**`, centralized API documentation, and administrative access to customer/account resources. +- `customer.self` for a customer profile whose UUID matches the JWT `sub` claim. +- `account.self` for account resources owned by the customer UUID in the JWT `sub` claim. - `mfa.internal` for `/api/v1/mfa/**`. - `transfer.internal` for `/internal/v1/transfer-workflows/**`. - `payment.internal` for `/internal/v1/payment-instructions/**`. -Customer and account APIs require an authenticated token. Health endpoints and Auth login remain public. Requests that do not authenticate receive `401` Problem Details; authenticated requests without the required scope receive `403` Problem Details. +Customer and account APIs require an ownership scope, not merely an authenticated token. Health endpoints and Auth login remain public. Requests that do not authenticate receive `401` Problem Details; authenticated requests without the required scope or ownership receive `403` Problem Details. The current SIT fixture is the `transfer-orchestrator` administrative identity and retains `admin.internal`; subject-to-customer UUID mapping is a temporary boundary until a customer identity provider supplies explicit customer claims. SIT uses a base64-encoded HMAC secret supplied through the Kubernetes `auth-service-secrets` Secret. UAT and PROD should use the same application contract with an AWS-managed secret or an OIDC/JWK issuer; no token secret belongs in Git. The chart fails closed by default when an environment does not provide an explicit security override. diff --git a/src/main/java/com/digitalbank/apigateway/security/GatewaySecurityConfiguration.java b/src/main/java/com/digitalbank/apigateway/security/GatewaySecurityConfiguration.java index 88a4ed6..6296a54 100644 --- a/src/main/java/com/digitalbank/apigateway/security/GatewaySecurityConfiguration.java +++ b/src/main/java/com/digitalbank/apigateway/security/GatewaySecurityConfiguration.java @@ -52,8 +52,12 @@ SecurityWebFilterChain gatewaySecurityWebFilterChain(ServerHttpSecurity http, .hasAuthority("SCOPE_transfer.internal") .pathMatchers("/internal/v1/payment-instructions", "/internal/v1/payment-instructions/**") .hasAuthority("SCOPE_payment.internal") - .pathMatchers("/api/v1/customers/**", "/api/v1/accounts/**") - .authenticated() + .pathMatchers("/api/v1/customers/*/accounts") + .hasAnyAuthority("SCOPE_account.self", "SCOPE_admin.internal") + .pathMatchers("/api/v1/customers/**") + .hasAnyAuthority("SCOPE_customer.self", "SCOPE_admin.internal") + .pathMatchers("/api/v1/accounts/**") + .hasAnyAuthority("SCOPE_account.self", "SCOPE_admin.internal") .anyExchange().denyAll()) .oauth2ResourceServer(oauth2 -> oauth2 .jwt(withDefaults()) From 007926adb4fd9f68060c641bcb073e688e9ef2e1 Mon Sep 17 00:00:00 2001 From: Rami Mohamed Date: Sat, 12 Sep 2026 18:40:47 +0400 Subject: [PATCH 3/3] feat: validate gateway JWT audience and purpose --- .../GatewayJwtDecoderConfiguration.java | 43 +++++++++++++------ .../GatewaySecurityIntegrationTests.java | 2 + 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/digitalbank/apigateway/security/GatewayJwtDecoderConfiguration.java b/src/main/java/com/digitalbank/apigateway/security/GatewayJwtDecoderConfiguration.java index c860c60..bc73fcf 100644 --- a/src/main/java/com/digitalbank/apigateway/security/GatewayJwtDecoderConfiguration.java +++ b/src/main/java/com/digitalbank/apigateway/security/GatewayJwtDecoderConfiguration.java @@ -1,6 +1,7 @@ package com.digitalbank.apigateway.security; import java.util.Base64; +import java.util.List; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; @@ -12,6 +13,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator; import org.springframework.security.oauth2.core.OAuth2TokenValidator; +import org.springframework.security.oauth2.jwt.JwtClaimValidator; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.oauth2.jwt.JwtValidators; import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder; @@ -30,21 +32,28 @@ class GatewayJwtDecoderConfiguration { ReactiveJwtDecoder gatewayReactiveJwtDecoder( @Value("${auth.jwt.issuer:}") String issuer, @Value("${auth.jwt.secret:}") String secret, - @Value("${auth.jwt.jwk-set-uri:}") String jwkSetUri) { + @Value("${auth.jwt.jwk-set-uri:}") String jwkSetUri, + @Value("${auth.jwt.audience:}") String audience, + @Value("${auth.jwt.token-purpose:}") String tokenPurpose) { + if (!StringUtils.hasText(audience) || !StringUtils.hasText(tokenPurpose)) { + throw new IllegalStateException( + "Gateway security is enabled but auth.jwt.audience and auth.jwt.token-purpose are not configured"); + } if (StringUtils.hasText(secret)) { - return hmacDecoder(secret, issuer); + return hmacDecoder(secret, issuer, audience, tokenPurpose); } if (StringUtils.hasText(jwkSetUri)) { - return jwkDecoder(jwkSetUri, issuer); + return jwkDecoder(jwkSetUri, issuer, audience, tokenPurpose); } if (StringUtils.hasText(issuer)) { - return ReactiveJwtDecoders.fromIssuerLocation(issuer); + return configuredDecoder((NimbusReactiveJwtDecoder) ReactiveJwtDecoders.fromIssuerLocation(issuer), issuer, + audience, tokenPurpose); } throw new IllegalStateException( "Gateway security is enabled but no auth.jwt.secret, auth.jwt.jwk-set-uri, or auth.jwt.issuer is configured"); } - private ReactiveJwtDecoder hmacDecoder(String encodedSecret, String issuer) { + private ReactiveJwtDecoder hmacDecoder(String encodedSecret, String issuer, String audience, String tokenPurpose) { final byte[] secret; try { secret = Base64.getDecoder().decode(encodedSecret); @@ -54,22 +63,30 @@ private ReactiveJwtDecoder hmacDecoder(String encodedSecret, String issuer) { if (secret.length < MINIMUM_HMAC_KEY_BYTES) { throw new IllegalStateException("auth.jwt.secret must decode to at least 32 bytes"); } - return configuredDecoder(new SecretKeySpec(secret, "HmacSHA256"), issuer); + return configuredDecoder(new SecretKeySpec(secret, "HmacSHA256"), issuer, audience, tokenPurpose); } - private ReactiveJwtDecoder jwkDecoder(String jwkSetUri, String issuer) { + private ReactiveJwtDecoder jwkDecoder(String jwkSetUri, String issuer, String audience, String tokenPurpose) { NimbusReactiveJwtDecoder decoder = NimbusReactiveJwtDecoder.withJwkSetUri(jwkSetUri).build(); - if (StringUtils.hasText(issuer)) { - decoder.setJwtValidator(JwtValidators.createDefaultWithIssuer(issuer)); - } - return decoder; + return configuredDecoder(decoder, issuer, audience, tokenPurpose); } - private ReactiveJwtDecoder configuredDecoder(SecretKey key, String issuer) { + private ReactiveJwtDecoder configuredDecoder(SecretKey key, String issuer, String audience, String tokenPurpose) { NimbusReactiveJwtDecoder decoder = NimbusReactiveJwtDecoder.withSecretKey(key).build(); + return configuredDecoder(decoder, issuer, audience, tokenPurpose); + } + + private ReactiveJwtDecoder configuredDecoder( + NimbusReactiveJwtDecoder decoder, String issuer, String audience, String tokenPurpose) { + OAuth2TokenValidator audienceValidator = new JwtClaimValidator>( + "aud", values -> values != null && values.contains(audience)); + OAuth2TokenValidator purposeValidator = new JwtClaimValidator( + "token_purpose", tokenPurpose::equals); if (StringUtils.hasText(issuer)) { OAuth2TokenValidator issuerValidator = JwtValidators.createDefaultWithIssuer(issuer); - decoder.setJwtValidator(new DelegatingOAuth2TokenValidator<>(issuerValidator)); + decoder.setJwtValidator(new DelegatingOAuth2TokenValidator<>(issuerValidator, audienceValidator, purposeValidator)); + } else { + decoder.setJwtValidator(new DelegatingOAuth2TokenValidator<>(audienceValidator, purposeValidator)); } return decoder; } diff --git a/src/test/java/com/digitalbank/apigateway/GatewaySecurityIntegrationTests.java b/src/test/java/com/digitalbank/apigateway/GatewaySecurityIntegrationTests.java index 2516346..32b8bc1 100644 --- a/src/test/java/com/digitalbank/apigateway/GatewaySecurityIntegrationTests.java +++ b/src/test/java/com/digitalbank/apigateway/GatewaySecurityIntegrationTests.java @@ -21,6 +21,8 @@ "spring.cloud.config.enabled=false", "gateway.security.enabled=true", "auth.jwt.issuer=https://issuer.test", + "auth.jwt.audience=api-gateway", + "auth.jwt.token-purpose=user-access", "management.health.redis.enabled=false" }) @Import(GatewaySecurityIntegrationTests.TestJwtConfiguration.class) class GatewaySecurityIntegrationTests {