mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-29 09:18:13 +08:00
Merge pull request #176 from meysamhadeli/feat/config-identitiy-server-for-revers-proxy
feat: Config identity server for ingress revers proxy
This commit is contained in:
commit
fb3117ef94
@ -252,7 +252,7 @@ services:
|
|||||||
#######################################################
|
#######################################################
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
container_name: elasticsearch
|
container_name: elasticsearch
|
||||||
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
|
image: elasticsearch:7.17.9
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 9200:9200
|
- 9200:9200
|
||||||
@ -271,7 +271,7 @@ services:
|
|||||||
#######################################################
|
#######################################################
|
||||||
kibana:
|
kibana:
|
||||||
container_name: kibana
|
container_name: kibana
|
||||||
image: docker.elastic.co/kibana/kibana:7.9.2
|
image: kibana:7.17.9
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 5601:5601
|
- 5601:5601
|
||||||
@ -285,7 +285,6 @@ services:
|
|||||||
|
|
||||||
networks:
|
networks:
|
||||||
booking:
|
booking:
|
||||||
name: booking
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
elasticsearch-data:
|
elasticsearch-data:
|
||||||
|
|||||||
@ -95,7 +95,7 @@ services:
|
|||||||
#######################################################
|
#######################################################
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
container_name: elasticsearch
|
container_name: elasticsearch
|
||||||
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.9
|
image: elasticsearch:7.17.9
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 9200:9200
|
- 9200:9200
|
||||||
@ -114,7 +114,7 @@ services:
|
|||||||
#######################################################
|
#######################################################
|
||||||
kibana:
|
kibana:
|
||||||
container_name: kibana
|
container_name: kibana
|
||||||
image: docker.elastic.co/kibana/kibana:7.17.9
|
image: kibana:7.17.9
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 5601:5601
|
- 5601:5601
|
||||||
@ -141,8 +141,6 @@ services:
|
|||||||
|
|
||||||
networks:
|
networks:
|
||||||
booking:
|
booking:
|
||||||
name: booking
|
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
elasticsearch-data:
|
elasticsearch-data:
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public static class JwtExtensions
|
|||||||
{
|
{
|
||||||
options.Authority = jwtOptions.Authority;
|
options.Authority = jwtOptions.Authority;
|
||||||
options.TokenValidationParameters.ValidateAudience = false;
|
options.TokenValidationParameters.ValidateAudience = false;
|
||||||
options.RequireHttpsMetadata = false;
|
options.RequireHttpsMetadata = jwtOptions.RequireHttpsMetadata;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(jwtOptions.Audience))
|
if (!string.IsNullOrEmpty(jwtOptions.Audience))
|
||||||
|
|||||||
@ -20,7 +20,6 @@ var app = builder.Build();
|
|||||||
app.MapMinimalEndpoints();
|
app.MapMinimalEndpoints();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseHttpsRedirection();
|
|
||||||
app.UseInfrastructure();
|
app.UseInfrastructure();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@ -26,8 +26,9 @@
|
|||||||
"Port": 5672
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Authority": "identity:5005",
|
"Authority": "https://myidentityserver.com",
|
||||||
"Audience": "booking-api"
|
"Audience": "booking-api",
|
||||||
|
"RequireHttpsMetadata": false
|
||||||
},
|
},
|
||||||
"Grpc": {
|
"Grpc": {
|
||||||
"FlightAddress": "flight:5003",
|
"FlightAddress": "flight:5003",
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Authority": "https://localhost:5005",
|
"Authority": "https://localhost:5005",
|
||||||
"Audience": "booking-api"
|
"Audience": "booking-api",
|
||||||
|
"RequireHttpsMetadata": true
|
||||||
},
|
},
|
||||||
"RabbitMqOptions": {
|
"RabbitMqOptions": {
|
||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
|
|||||||
@ -12,7 +12,6 @@ using BuildingBlocks.MassTransit;
|
|||||||
using BuildingBlocks.Mongo;
|
using BuildingBlocks.Mongo;
|
||||||
using BuildingBlocks.OpenTelemetry;
|
using BuildingBlocks.OpenTelemetry;
|
||||||
using BuildingBlocks.PersistMessageProcessor;
|
using BuildingBlocks.PersistMessageProcessor;
|
||||||
using BuildingBlocks.PersistMessageProcessor.Data;
|
|
||||||
using BuildingBlocks.Swagger;
|
using BuildingBlocks.Swagger;
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using Figgle;
|
using Figgle;
|
||||||
|
|||||||
@ -10,6 +10,16 @@
|
|||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:5003",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
"ConnectionString": "Server=postgres;Port=5432;Database=flight;User Id=postgres;Password=postgres;Include Error Detail=true"
|
"ConnectionString": "Server=postgres;Port=5432;Database=flight;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Authority": "http://myidentityserver.com",
|
"Authority": "https://myidentityserver.com",
|
||||||
"Audience": "flight-api",
|
"Audience": "flight-api",
|
||||||
"RequireHttpsMetadata": false
|
"RequireHttpsMetadata": false
|
||||||
},
|
},
|
||||||
|
|||||||
@ -16,7 +16,6 @@ using BuildingBlocks.Mongo;
|
|||||||
using BuildingBlocks.OpenTelemetry;
|
using BuildingBlocks.OpenTelemetry;
|
||||||
using BuildingBlocks.PersistMessageProcessor;
|
using BuildingBlocks.PersistMessageProcessor;
|
||||||
using BuildingBlocks.Swagger;
|
using BuildingBlocks.Swagger;
|
||||||
using BuildingBlocks.Utils;
|
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using Figgle;
|
using Figgle;
|
||||||
using Flight.Data;
|
using Flight.Data;
|
||||||
|
|||||||
@ -20,7 +20,6 @@ var app = builder.Build();
|
|||||||
app.MapMinimalEndpoints();
|
app.MapMinimalEndpoints();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseHttpsRedirection();
|
|
||||||
app.UseInfrastructure();
|
app.UseInfrastructure();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@ -1,6 +1,24 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:42478",
|
||||||
|
"sslPort": 44342
|
||||||
|
}
|
||||||
|
},
|
||||||
"profiles": {
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "http://localhost:5009",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
"https": {
|
"https": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
|
|||||||
@ -15,10 +15,6 @@
|
|||||||
"Password": "guest",
|
"Password": "guest",
|
||||||
"Port": 5672
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Jwt": {
|
|
||||||
"Authority": "identity:5005",
|
|
||||||
"Audience": "identity-api"
|
|
||||||
},
|
|
||||||
"LogOptions": {
|
"LogOptions": {
|
||||||
"Level": "information",
|
"Level": "information",
|
||||||
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
||||||
|
|||||||
@ -12,10 +12,6 @@
|
|||||||
"Password": "guest",
|
"Password": "guest",
|
||||||
"Port": 5672
|
"Port": 5672
|
||||||
},
|
},
|
||||||
"Jwt": {
|
|
||||||
"Authority": "https://localhost:5005",
|
|
||||||
"Audience": "identity-api"
|
|
||||||
},
|
|
||||||
"LogOptions": {
|
"LogOptions": {
|
||||||
"Level": "information",
|
"Level": "information",
|
||||||
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
||||||
|
|||||||
@ -35,10 +35,8 @@ public static class IdentityServerExtensions
|
|||||||
.AddAspNetIdentity<User>()
|
.AddAspNetIdentity<User>()
|
||||||
.AddResourceOwnerValidator<UserValidator>();
|
.AddResourceOwnerValidator<UserValidator>();
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
//ref: https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html
|
||||||
{
|
|
||||||
identityServerBuilder.AddDeveloperSigningCredential();
|
identityServerBuilder.AddDeveloperSigningCredential();
|
||||||
}
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,9 @@ using Serilog;
|
|||||||
|
|
||||||
namespace Identity.Extensions.Infrastructure;
|
namespace Identity.Extensions.Infrastructure;
|
||||||
|
|
||||||
|
using Duende.IdentityServer.Extensions;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
public static class InfrastructureExtensions
|
public static class InfrastructureExtensions
|
||||||
{
|
{
|
||||||
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
||||||
@ -76,6 +79,14 @@ public static class InfrastructureExtensions
|
|||||||
|
|
||||||
builder.Services.AddIdentityServer(env);
|
builder.Services.AddIdentityServer(env);
|
||||||
|
|
||||||
|
//ref: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-7.0&viewFallbackFrom=aspnetcore-2.2
|
||||||
|
//ref: https://medium.com/@christopherlenard/identity-server-and-nginx-ingress-controller-in-kubernetes-7146c22a2466
|
||||||
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders =
|
||||||
|
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||||
|
});
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +96,10 @@ public static class InfrastructureExtensions
|
|||||||
var env = app.Environment;
|
var env = app.Environment;
|
||||||
var appOptions = app.GetOptions<AppOptions>(nameof(AppOptions));
|
var appOptions = app.GetOptions<AppOptions>(nameof(AppOptions));
|
||||||
|
|
||||||
|
//ref: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-7.0&viewFallbackFrom=aspnetcore-2.2
|
||||||
|
//ref: https://medium.com/@christopherlenard/identity-server-and-nginx-ingress-controller-in-kubernetes-7146c22a2466
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
app.UseProblemDetails();
|
app.UseProblemDetails();
|
||||||
app.UseSerilogRequestLogging(options =>
|
app.UseSerilogRequestLogging(options =>
|
||||||
{
|
{
|
||||||
@ -100,6 +115,22 @@ public static class InfrastructureExtensions
|
|||||||
|
|
||||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||||
|
|
||||||
|
app.Use((httpContext, next) =>
|
||||||
|
{
|
||||||
|
httpContext.Request.Scheme = "https";
|
||||||
|
return next();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.Use(async (ctx, next) =>
|
||||||
|
{
|
||||||
|
if (ctx.Request.Headers.ContainsKey("from-ingress"))
|
||||||
|
{
|
||||||
|
ctx.SetIdentityServerOrigin("https://myidentityserver.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
await next();
|
||||||
|
});
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseCustomSwagger();
|
app.UseCustomSwagger();
|
||||||
|
|||||||
@ -20,7 +20,6 @@ var app = builder.Build();
|
|||||||
app.MapMinimalEndpoints();
|
app.MapMinimalEndpoints();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseHttpsRedirection();
|
|
||||||
app.UseInfrastructure();
|
app.UseInfrastructure();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@ -9,8 +9,9 @@
|
|||||||
"ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true"
|
"ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Authority": "identity:5005",
|
"Authority": "https://myidentityserver.com",
|
||||||
"Audience": "passenger-api"
|
"Audience": "passenger-api",
|
||||||
|
"RequireHttpsMetadata": false
|
||||||
},
|
},
|
||||||
"MongoOptions": {
|
"MongoOptions": {
|
||||||
"ConnectionString": "mongodb://mongo:27017",
|
"ConnectionString": "mongodb://mongo:27017",
|
||||||
|
|||||||
@ -11,7 +11,8 @@
|
|||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Authority": "https://localhost:5005",
|
"Authority": "https://localhost:5005",
|
||||||
"Audience": "passenger-api"
|
"Audience": "passenger-api",
|
||||||
|
"RequireHttpsMetadata": "true"
|
||||||
},
|
},
|
||||||
"RabbitMqOptions": {
|
"RabbitMqOptions": {
|
||||||
"HostName": "localhost",
|
"HostName": "localhost",
|
||||||
|
|||||||
@ -12,7 +12,6 @@ using BuildingBlocks.Mongo;
|
|||||||
using BuildingBlocks.OpenTelemetry;
|
using BuildingBlocks.OpenTelemetry;
|
||||||
using BuildingBlocks.PersistMessageProcessor;
|
using BuildingBlocks.PersistMessageProcessor;
|
||||||
using BuildingBlocks.Swagger;
|
using BuildingBlocks.Swagger;
|
||||||
using BuildingBlocks.Utils;
|
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using Figgle;
|
using Figgle;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user