Skip to content

Commit

Permalink
Merge pull request #22 from sentemon/fix-ci-for-docker-compose
Browse files Browse the repository at this point in the history
Fix CI by deleting check IssuerSigningKey
  • Loading branch information
sentemon authored Jan 6, 2025
2 parents c15118e + a4d7abb commit 0939a8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 68 deletions.
33 changes: 15 additions & 18 deletions .github/workflows/compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@ jobs:
- name: Start Docker Compose
run: docker compose up -d

# ToDo
# - name: Health Check AuthService
# run: |
# echo "Checking health..."
# for i in {1..10}; do
# curl --fail http://localhost:8000/auth/health && break || sleep 5
# curl --fail http://gateway:8000/auth/health && break || sleep 5
# done
# curl --fail http://localhost:8000/auth/health || exit 1
#
# - name: Health Check PostService
# run: |
# echo "Checking health..."
# for i in {1..10}; do
# curl --fail http://localhost:8000/post/health && break || sleep 5
# curl --fail http://gateway:8000/post/health && break || sleep 5
# done
# curl --fail http://localhost:8000/post/health || exit 1
- name: Health Check AuthService
run: |
echo "Checking health..."
for i in {1..10}; do
curl --fail http://0.0.0.0:8000/auth/health && break || sleep 5
done
curl --fail http://0.0.0.0:8000/auth/health || exit 1
- name: Health Check PostService
run: |
echo "Checking health..."
for i in {1..10}; do
curl --fail http://0.0.0.0:8000/post/health && break || sleep 5
done
curl --fail http://0.0.0.0:8000/post/health || exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
keycloakSection[AppSettingsConstants.AdminPassword]
);

var rsaSecurityKey = GetRsaSecurityKeyFromKeycloak(keycloakConfig.Url, keycloakConfig.Realm);

services.AddSingleton(keycloakConfig);

services.AddHttpClient("KeycloakClient", client =>
Expand Down Expand Up @@ -63,7 +61,6 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
ValidAudience = "account",
ValidateLifetime = true,
ValidateIssuerSigningKey = false,
IssuerSigningKey = rsaSecurityKey,
SignatureValidator = (token, parameters) =>
{
var jwt = new JsonWebToken(token);
Expand All @@ -80,46 +77,4 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti

return services;
}

private static RsaSecurityKey GetRsaSecurityKeyFromKeycloak(string keycloakUrl, string realm)
{
using var httpClient = new HttpClient();
var certsUrl = $"{keycloakUrl}/realms/{realm}/protocol/openid-connect/certs";
var response = httpClient.GetStringAsync(certsUrl).Result;

var jwks = JsonDocument.Parse(response).RootElement;
var key = jwks.GetProperty("keys")[0];

var modulusBase64 = key.GetProperty("n").GetString()?.Trim();
var exponentBase64 = key.GetProperty("e").GetString()?.Trim();

if (string.IsNullOrEmpty(modulusBase64) || string.IsNullOrEmpty(exponentBase64))
{
throw new FormatException("Invalid modulus or exponent in the public key");
}

try
{
modulusBase64 = ConvertUrlBase64ToStandardBase64(modulusBase64);
exponentBase64 = ConvertUrlBase64ToStandardBase64(exponentBase64);

var modulus = Convert.FromBase64String(modulusBase64);
var exponent = Convert.FromBase64String(exponentBase64);

return new RsaSecurityKey(new RSAParameters
{
Modulus = modulus,
Exponent = exponent
});
}
catch (FormatException ex)
{
throw new FormatException("Base64 decoding failed for modulus or exponent", ex);
}
}

private static string ConvertUrlBase64ToStandardBase64(string urlBase64)
{
return urlBase64.Replace('-', '+').Replace('_', '/') + new string('=', (4 - urlBase64.Length % 4) % 4);
}
}
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
depends_on:
gateway:
condition: service_healthy
networks:
networks:
- microservices

gateway:
Expand All @@ -36,7 +36,7 @@ services:
interval: 10s
timeout: 5s
retries: 3
networks:
networks:
- microservices

auth-service:
Expand Down Expand Up @@ -113,9 +113,9 @@ services:
- "8080:8080"
command: [ "start-dev" ]
restart: always
networks:
networks:
- microservices

rabittmq:
image: rabbitmq:4-management
container_name: rabbitmq
Expand All @@ -134,4 +134,4 @@ services:
- microservices

volumes:
postgres-data:
postgres-data:

0 comments on commit 0939a8b

Please sign in to comment.