From 72d7a4888a062273a79082e3648342ea10a3482f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 2 Aug 2021 17:30:35 +0300 Subject: [PATCH] Added account & api services --- .../account/templates/account-ingress.yaml | 3 +- .../account/templates/account-service.yaml | 4 +- .../charts/account/templates/account.yaml | 2 +- .../helm-chart/eventhub/charts/api/Chart.yaml | 6 ++ .../charts/api/templates/api-ingress.yaml | 18 +++++ .../charts/api/templates/api-service.yaml | 14 ++++ .../eventhub/charts/api/templates/api.yaml | 22 ++++++ .../EventHubAdminHttpApiHostModule.cs | 1 + src/EventHub.Admin.HttpApi.Host/Program.cs | 2 - .../EventHub.DbMigrator.csproj | 4 ++ .../appsettings.Development.json | 5 ++ .../Web/EventHubExternalUrls.cs | 8 +-- src/EventHub.HttpApi.Host/Dockerfile | 4 ++ .../EventHubHttpApiHostModule.cs | 10 +++ src/EventHub.HttpApi.Host/Program.cs | 2 - ...eSiteCookiesServiceCollectionExtensions.cs | 70 +++++++++++++++++++ .../appsettings.Development.json | 12 ++++ src/EventHub.HttpApi.Host/appsettings.json | 6 +- .../EventHub.IdentityServer.csproj | 4 ++ .../EventHubIdentityServerModule.cs | 16 +++++ .../appsettings.Development.json | 8 ++- .../wwwroot/themes/eventhub/owl-edit.css | 6 +- .../wwwroot/themes/eventhub/style.css | 6 +- src/EventHub.Web/Program.cs | 2 - 24 files changed, 211 insertions(+), 24 deletions(-) create mode 100644 etc/k8s/helm-chart/eventhub/charts/api/Chart.yaml create mode 100644 etc/k8s/helm-chart/eventhub/charts/api/templates/api-ingress.yaml create mode 100644 etc/k8s/helm-chart/eventhub/charts/api/templates/api-service.yaml create mode 100644 etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml create mode 100644 src/EventHub.DbMigrator/appsettings.Development.json create mode 100644 src/EventHub.HttpApi.Host/Dockerfile create mode 100644 src/EventHub.HttpApi.Host/SameSiteCookiesServiceCollectionExtensions.cs diff --git a/etc/k8s/helm-chart/eventhub/charts/account/templates/account-ingress.yaml b/etc/k8s/helm-chart/eventhub/charts/account/templates/account-ingress.yaml index 19ef867..2138aa0 100644 --- a/etc/k8s/helm-chart/eventhub/charts/account/templates/account-ingress.yaml +++ b/etc/k8s/helm-chart/eventhub/charts/account/templates/account-ingress.yaml @@ -4,6 +4,7 @@ metadata: name: account-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / + nginx.ingress.kubernetes.io/force-ssl-redirect: "true" spec: rules: - host: "account.openeventhub.com" @@ -15,4 +16,4 @@ spec: service: name: account port: - number: 443 \ No newline at end of file + number: 80 \ No newline at end of file diff --git a/etc/k8s/helm-chart/eventhub/charts/account/templates/account-service.yaml b/etc/k8s/helm-chart/eventhub/charts/account/templates/account-service.yaml index 8d843f1..075e7d7 100644 --- a/etc/k8s/helm-chart/eventhub/charts/account/templates/account-service.yaml +++ b/etc/k8s/helm-chart/eventhub/charts/account/templates/account-service.yaml @@ -8,7 +8,7 @@ spec: ports: - name: "80" port: 80 - - name: "433" - port: 433 + - name: "443" + port: 443 selector: app: account diff --git a/etc/k8s/helm-chart/eventhub/charts/account/templates/account.yaml b/etc/k8s/helm-chart/eventhub/charts/account/templates/account.yaml index a4455c9..e67dbcb 100644 --- a/etc/k8s/helm-chart/eventhub/charts/account/templates/account.yaml +++ b/etc/k8s/helm-chart/eventhub/charts/account/templates/account.yaml @@ -19,4 +19,4 @@ spec: - name: accounthttp containerPort: 80 - name: accounthttps - containerPort: 433 \ No newline at end of file + containerPort: 443 \ No newline at end of file diff --git a/etc/k8s/helm-chart/eventhub/charts/api/Chart.yaml b/etc/k8s/helm-chart/eventhub/charts/api/Chart.yaml new file mode 100644 index 0000000..fa75f5b --- /dev/null +++ b/etc/k8s/helm-chart/eventhub/charts/api/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: api +appVersion: "1.0" +description: EventHub API Application +version: 1.0.0 +type: application \ No newline at end of file diff --git a/etc/k8s/helm-chart/eventhub/charts/api/templates/api-ingress.yaml b/etc/k8s/helm-chart/eventhub/charts/api/templates/api-ingress.yaml new file mode 100644 index 0000000..efc2deb --- /dev/null +++ b/etc/k8s/helm-chart/eventhub/charts/api/templates/api-ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: api-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + rules: + - host: "api.openeventhub.com" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: api + port: + number: 80 \ No newline at end of file diff --git a/etc/k8s/helm-chart/eventhub/charts/api/templates/api-service.yaml b/etc/k8s/helm-chart/eventhub/charts/api/templates/api-service.yaml new file mode 100644 index 0000000..e4b7ee7 --- /dev/null +++ b/etc/k8s/helm-chart/eventhub/charts/api/templates/api-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: api + name: api +spec: + ports: + - name: "80" + port: 80 + - name: "443" + port: 443 + selector: + app: api diff --git a/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml b/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml new file mode 100644 index 0000000..b5ad403 --- /dev/null +++ b/etc/k8s/helm-chart/eventhub/charts/api/templates/api.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: api +spec: + selector: + matchLabels: + app: api + template: + metadata: + labels: + app: api + spec: + containers: + - image: eventhub.api + imagePullPolicy: Never + name: api + ports: + - name: apihttp + containerPort: 80 + - name: apihttps + containerPort: 443 \ No newline at end of file diff --git a/src/EventHub.Admin.HttpApi.Host/EventHubAdminHttpApiHostModule.cs b/src/EventHub.Admin.HttpApi.Host/EventHubAdminHttpApiHostModule.cs index 38ff481..81a76bc 100644 --- a/src/EventHub.Admin.HttpApi.Host/EventHubAdminHttpApiHostModule.cs +++ b/src/EventHub.Admin.HttpApi.Host/EventHubAdminHttpApiHostModule.cs @@ -15,6 +15,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; using StackExchange.Redis; using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Serilog; diff --git a/src/EventHub.Admin.HttpApi.Host/Program.cs b/src/EventHub.Admin.HttpApi.Host/Program.cs index fdb4ed3..076a07e 100644 --- a/src/EventHub.Admin.HttpApi.Host/Program.cs +++ b/src/EventHub.Admin.HttpApi.Host/Program.cs @@ -20,9 +20,7 @@ namespace EventHub.Admin .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Async(c => c.File("Logs/logs.txt")) -#if DEBUG .WriteTo.Async(c => c.Console()) -#endif .CreateLogger(); try diff --git a/src/EventHub.DbMigrator/EventHub.DbMigrator.csproj b/src/EventHub.DbMigrator/EventHub.DbMigrator.csproj index 69154bc..ed41ba6 100644 --- a/src/EventHub.DbMigrator/EventHub.DbMigrator.csproj +++ b/src/EventHub.DbMigrator/EventHub.DbMigrator.csproj @@ -12,6 +12,10 @@ + + PreserveNewest + Always + PreserveNewest Always diff --git a/src/EventHub.DbMigrator/appsettings.Development.json b/src/EventHub.DbMigrator/appsettings.Development.json new file mode 100644 index 0000000..4ba93e6 --- /dev/null +++ b/src/EventHub.DbMigrator/appsettings.Development.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" + } +} diff --git a/src/EventHub.Domain.Shared/Web/EventHubExternalUrls.cs b/src/EventHub.Domain.Shared/Web/EventHubExternalUrls.cs index e6d8c7a..60ff0bd 100644 --- a/src/EventHub.Domain.Shared/Web/EventHubExternalUrls.cs +++ b/src/EventHub.Domain.Shared/Web/EventHubExternalUrls.cs @@ -9,10 +9,10 @@ namespace EventHub.Web public const string EhWww = "https://localhost:44308"; #else // TODO: Change these production links - public const string EhAccount = "https://localhost:44313"; - public const string EhApi = "https://localhost:44362"; - public const string EhAdmin = "https://localhost:44307"; - public const string EhWww = "https://localhost:44308"; + public const string EhAccount = "https://account.openeventhub.com"; + public const string EhApi = "https://api.openeventhub.com"; + public const string EhAdmin = "https://admin.openeventhub.com"; + public const string EhWww = "https://openeventhub.com"; #endif } } \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/Dockerfile b/src/EventHub.HttpApi.Host/Dockerfile new file mode 100644 index 0000000..b5bd5d9 --- /dev/null +++ b/src/EventHub.HttpApi.Host/Dockerfile @@ -0,0 +1,4 @@ + FROM mcr.microsoft.com/dotnet/aspnet:5.0 + COPY bin/Release/net5.0/publish/ app/ + WORKDIR /app + ENTRYPOINT ["dotnet", "EventHub.HttpApi.Host.dll"] \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs index 65b752f..5814887 100644 --- a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs +++ b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs @@ -170,6 +170,8 @@ namespace EventHub .AllowCredentials(); }); }); + + context.Services.AddSameSiteCookiePolicy(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -181,6 +183,12 @@ namespace EventHub { app.UseDeveloperExceptionPage(); } + + app.Use((context, next) => + { + context.Request.Scheme = "https"; + return next(); + }); var supportedCultures = new[] { @@ -204,6 +212,8 @@ namespace EventHub app.UseErrorPage(); } + app.UseCookiePolicy(); + app.UseCorrelationId(); app.UseVirtualFiles(); app.UseRouting(); diff --git a/src/EventHub.HttpApi.Host/Program.cs b/src/EventHub.HttpApi.Host/Program.cs index 08c00d8..1bf31ea 100644 --- a/src/EventHub.HttpApi.Host/Program.cs +++ b/src/EventHub.HttpApi.Host/Program.cs @@ -20,9 +20,7 @@ namespace EventHub .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Async(c => c.File("Logs/logs.txt")) -#if DEBUG .WriteTo.Async(c => c.Console()) -#endif .CreateLogger(); try diff --git a/src/EventHub.HttpApi.Host/SameSiteCookiesServiceCollectionExtensions.cs b/src/EventHub.HttpApi.Host/SameSiteCookiesServiceCollectionExtensions.cs new file mode 100644 index 0000000..3b0c754 --- /dev/null +++ b/src/EventHub.HttpApi.Host/SameSiteCookiesServiceCollectionExtensions.cs @@ -0,0 +1,70 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class SameSiteCookiesServiceCollectionExtensions + { + public static IServiceCollection AddSameSiteCookiePolicy(this IServiceCollection services) + { + services.Configure(options => + { + options.MinimumSameSitePolicy = SameSiteMode.Unspecified; + options.OnAppendCookie = cookieContext => + CheckSameSite(cookieContext.Context, cookieContext.CookieOptions); + options.OnDeleteCookie = cookieContext => + CheckSameSite(cookieContext.Context, cookieContext.CookieOptions); + }); + + return services; + } + + private static void CheckSameSite(HttpContext httpContext, CookieOptions options) + { + if (options.SameSite == SameSiteMode.None) + { + var userAgent = httpContext.Request.Headers["User-Agent"].ToString(); + if (!httpContext.Request.IsHttps || DisallowsSameSiteNone(userAgent)) + { + // For .NET Core < 3.1 set SameSite = (SameSiteMode)(-1) + options.SameSite = SameSiteMode.Unspecified; + } + } + } + + private static bool DisallowsSameSiteNone(string userAgent) + { + // Cover all iOS based browsers here. This includes: + // - Safari on iOS 12 for iPhone, iPod Touch, iPad + // - WkWebview on iOS 12 for iPhone, iPod Touch, iPad + // - Chrome on iOS 12 for iPhone, iPod Touch, iPad + // All of which are broken by SameSite=None, because they use the iOS networking stack + if (userAgent.Contains("CPU iPhone OS 12") || userAgent.Contains("iPad; CPU OS 12")) + { + return true; + } + + // Cover Mac OS X based browsers that use the Mac OS networking stack. This includes: + // - Safari on Mac OS X. + // This does not include: + // - Chrome on Mac OS X + // Because they do not use the Mac OS networking stack. + if (userAgent.Contains("Macintosh; Intel Mac OS X 10_14") && + userAgent.Contains("Version/") && userAgent.Contains("Safari")) + { + return true; + } + + // Cover Chrome 50-69, because some versions are broken by SameSite=None, + // and none in this range require it. + // Note: this covers some pre-Chromium Edge versions, + // but pre-Chromium Edge does not require SameSite=None. + if (userAgent.Contains("Chrome/5") || userAgent.Contains("Chrome/6")) + { + return true; + } + + return false; + } + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/appsettings.Development.json b/src/EventHub.HttpApi.Host/appsettings.Development.json index 2c63c08..1455394 100644 --- a/src/EventHub.HttpApi.Host/appsettings.Development.json +++ b/src/EventHub.HttpApi.Host/appsettings.Development.json @@ -1,2 +1,14 @@ { + "ConnectionStrings": { + "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" + }, + "Redis": { + "Configuration": "127.0.0.1" + }, + "AuthServer": { + "Authority": "https://localhost:44313", + "RequireHttpsMetadata": "true", + "SwaggerClientId": "EventHub_Swagger", + "SwaggerClientSecret": "1q2w3e*" + } } diff --git a/src/EventHub.HttpApi.Host/appsettings.json b/src/EventHub.HttpApi.Host/appsettings.json index 7c2ab2d..e379370 100644 --- a/src/EventHub.HttpApi.Host/appsettings.json +++ b/src/EventHub.HttpApi.Host/appsettings.json @@ -3,13 +3,13 @@ "CorsOrigins": "https://*.openeventhub.com,https://localhost:44307,https://localhost:44308" }, "ConnectionStrings": { - "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" + "Default": "Host=postgresql;Port=5435;Database=EventHub;Username=root;Password=root" }, "Redis": { - "Configuration": "127.0.0.1" + "Configuration": "redis" }, "AuthServer": { - "Authority": "https://localhost:44313", + "Authority": "https://account.openeventhub.com", "RequireHttpsMetadata": "true", "SwaggerClientId": "EventHub_Swagger", "SwaggerClientSecret": "1q2w3e*" diff --git a/src/EventHub.IdentityServer/EventHub.IdentityServer.csproj b/src/EventHub.IdentityServer/EventHub.IdentityServer.csproj index 8d54cd5..69b7785 100644 --- a/src/EventHub.IdentityServer/EventHub.IdentityServer.csproj +++ b/src/EventHub.IdentityServer/EventHub.IdentityServer.csproj @@ -20,6 +20,10 @@ + + + Always + diff --git a/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs b/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs index f10a1ee..44632cc 100644 --- a/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs +++ b/src/EventHub.IdentityServer/EventHubIdentityServerModule.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Security.Cryptography.X509Certificates; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; @@ -13,6 +14,7 @@ using EventHub.Web; using EventHub.Web.Theme; using EventHub.Web.Theme.Bundling; using IdentityServer4.Configuration; +using Microsoft.IdentityModel.Tokens; using StackExchange.Redis; using Volo.Abp; using Volo.Abp.Account; @@ -46,6 +48,14 @@ namespace EventHub { private const string DefaultCorsPolicyName = "Default"; + public override void PreConfigureServices(ServiceConfigurationContext context) + { + PreConfigure(builder => + { + builder.AddSigningCredential(new X509Certificate2("localhost.pfx", "e8202f07-66e5-4619-be07-72ba76fde97f")); + }); + } + public override void ConfigureServices(ServiceConfigurationContext context) { var hostingEnvironment = context.Services.GetHostingEnvironment(); @@ -148,6 +158,12 @@ namespace EventHub var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); + app.Use((context, next) => + { + context.Request.Scheme = "https"; + return next(); + }); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/EventHub.IdentityServer/appsettings.Development.json b/src/EventHub.IdentityServer/appsettings.Development.json index 2c63c08..de1a3cb 100644 --- a/src/EventHub.IdentityServer/appsettings.Development.json +++ b/src/EventHub.IdentityServer/appsettings.Development.json @@ -1,2 +1,8 @@ { -} + "ConnectionStrings": { + "Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" + }, + "Redis": { + "Configuration": "localhost" + } +} \ No newline at end of file diff --git a/src/EventHub.Web.Theme/wwwroot/themes/eventhub/owl-edit.css b/src/EventHub.Web.Theme/wwwroot/themes/eventhub/owl-edit.css index 00d706f..8462a79 100644 --- a/src/EventHub.Web.Theme/wwwroot/themes/eventhub/owl-edit.css +++ b/src/EventHub.Web.Theme/wwwroot/themes/eventhub/owl-edit.css @@ -10,7 +10,7 @@ .main-slider .owl-carousel .owl-nav button.owl-next { width: 40px; height: 40px; - background: rgb(0 4 74 / 20%); + background: rgba(0, 4, 74, 0.2); transition: background-color .3s ease; position: absolute; display: inline-block; @@ -24,7 +24,7 @@ } .main-slider .owl-carousel .owl-nav button.owl-prev:hover, .main-slider .owl-carousel .owl-nav button.owl-next:hover { - background: rgb(255 255 255 / 35%); + background: rgba(255, 255, 255, 0.35); } .main-slider .owl-carousel .owl-nav button span { font-size: 40px; @@ -65,7 +65,7 @@ .card-slider .owl-carousel .owl-nav button.owl-next { width: 9px; height: 15px; - background: rgb(255 255 255 / 22%); + background: rgba(255, 255, 255, 0.22); transition: background-color .3s ease; display: inline-block; overflow: hidden; diff --git a/src/EventHub.Web.Theme/wwwroot/themes/eventhub/style.css b/src/EventHub.Web.Theme/wwwroot/themes/eventhub/style.css index 6572a86..d65228b 100644 --- a/src/EventHub.Web.Theme/wwwroot/themes/eventhub/style.css +++ b/src/EventHub.Web.Theme/wwwroot/themes/eventhub/style.css @@ -754,7 +754,7 @@ div.checkbox.switcher label, div.radio.switcher label { margin-right: 10px; width: 56px; height: 30px; - background: rgb(107 126 146 / 20%); + background: rgba(107, 126, 146, 0.20); border: 3px solid #e1e5e9; border-radius: 50px; transition: all 0.3s ease-in-out; @@ -791,7 +791,7 @@ div.checkbox.switcher label, div.radio.switcher label { .image-area { - border: 2px dashed rgb(218 224 229); + border: 2px dashed rgb(218, 224, 229); padding: 1em; position: relative; border-radius: 10px; @@ -802,7 +802,7 @@ div.checkbox.switcher label, div.radio.switcher label { .image-area::before { content: 'Uploaded image result'; - color: rgb(218 224 229); + color: rgb(218, 224, 229); font-weight: bold; text-transform: uppercase; position: absolute; diff --git a/src/EventHub.Web/Program.cs b/src/EventHub.Web/Program.cs index 73d69bd..010a36d 100644 --- a/src/EventHub.Web/Program.cs +++ b/src/EventHub.Web/Program.cs @@ -20,9 +20,7 @@ namespace EventHub.Web .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Async(c => c.File("Logs/logs.txt")) -#if DEBUG .WriteTo.Async(c => c.Console()) -#endif .CreateLogger(); try