🐛 Fixes bugs, endless CA issue, and endless unsecure grpc
This commit is contained in:
@@ -2,50 +2,62 @@ using Aspire.Hosting.Yarp.Transforms;
|
||||
|
||||
var builder = DistributedApplication.CreateBuilder(args);
|
||||
|
||||
var database = builder.AddPostgres("database");
|
||||
// Database was configured separately in each service.
|
||||
// var database = builder.AddPostgres("database");
|
||||
|
||||
var cache = builder.AddConnectionString("cache");
|
||||
var queue = builder.AddNats("queue").WithJetStream();
|
||||
|
||||
var ringService = builder.AddProject<Projects.DysonNetwork_Ring>("ring")
|
||||
.WithReference(database)
|
||||
.WithReference(queue);
|
||||
var passService = builder.AddProject<Projects.DysonNetwork_Pass>("pass")
|
||||
.WithReference(database)
|
||||
.WithReference(cache)
|
||||
.WithReference(queue)
|
||||
.WithReference(ringService);
|
||||
var driveService = builder.AddProject<Projects.DysonNetwork_Drive>("drive")
|
||||
.WithReference(database)
|
||||
.WithReference(cache)
|
||||
.WithReference(queue)
|
||||
.WithReference(passService);
|
||||
.WithReference(passService)
|
||||
.WithReference(ringService);
|
||||
var sphereService = builder.AddProject<Projects.DysonNetwork_Sphere>("sphere")
|
||||
.WithReference(database)
|
||||
.WithReference(cache)
|
||||
.WithReference(queue)
|
||||
.WithReference(passService);
|
||||
.WithReference(passService)
|
||||
.WithReference(ringService);
|
||||
var developService = builder.AddProject<Projects.DysonNetwork_Develop>("develop")
|
||||
.WithReference(database)
|
||||
.WithReference(cache)
|
||||
.WithReference(passService);
|
||||
.WithReference(passService)
|
||||
.WithReference(ringService);
|
||||
|
||||
// Extra double-ended references
|
||||
ringService.WithReference(passService);
|
||||
|
||||
var gateway = builder.AddYarp("gateway")
|
||||
.WithHostPort(5000)
|
||||
.WithConfiguration(yarp =>
|
||||
{
|
||||
yarp.AddRoute("/ring/{**catch-all}", ringService)
|
||||
var ringCluster = yarp.AddCluster(ringService.GetEndpoint("http"));
|
||||
yarp.AddRoute("/ws", ringCluster);
|
||||
yarp.AddRoute("/ring/{**catch-all}", ringCluster)
|
||||
.WithTransformPathRemovePrefix("/ring")
|
||||
.WithTransformPathPrefix("/api");
|
||||
yarp.AddRoute("/id/{**catch-all}", passService)
|
||||
var passCluster = yarp.AddCluster(passService.GetEndpoint("http"));
|
||||
yarp.AddRoute("/.well-known/openid-configuration", passCluster);
|
||||
yarp.AddRoute("/.well-known/jwks", passCluster);
|
||||
yarp.AddRoute("/id/{**catch-all}", passCluster)
|
||||
.WithTransformPathRemovePrefix("/id")
|
||||
.WithTransformPathPrefix("/api");
|
||||
yarp.AddRoute("/drive/{**catch-all}", driveService)
|
||||
var driveCluster = yarp.AddCluster(driveService.GetEndpoint("http"));
|
||||
yarp.AddRoute("/api/tus", driveCluster);
|
||||
yarp.AddRoute("/drive/{**catch-all}", driveCluster)
|
||||
.WithTransformPathRemovePrefix("/drive")
|
||||
.WithTransformPathPrefix("/api");
|
||||
yarp.AddRoute("/sphere/{**catch-all}", sphereService)
|
||||
var sphereCluster = yarp.AddCluster(sphereService.GetEndpoint("http"));
|
||||
yarp.AddRoute("/sphere/{**catch-all}", sphereCluster)
|
||||
.WithTransformPathRemovePrefix("/sphere")
|
||||
.WithTransformPathPrefix("/api");
|
||||
yarp.AddRoute("/develop/{**catch-all}", developService)
|
||||
var developCluster = yarp.AddCluster(developService.GetEndpoint("http"));
|
||||
yarp.AddRoute("/develop/{**catch-all}", developCluster)
|
||||
.WithTransformPathRemovePrefix("/develop")
|
||||
.WithTransformPathPrefix("/api");
|
||||
});
|
||||
|
@@ -21,7 +21,6 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DysonNetwork.Develop\DysonNetwork.Develop.csproj" />
|
||||
<ProjectReference Include="..\DysonNetwork.Drive\DysonNetwork.Drive.csproj" />
|
||||
<ProjectReference Include="..\DysonNetwork.Gateway\DysonNetwork.Gateway.csproj" />
|
||||
<ProjectReference Include="..\DysonNetwork.Pass\DysonNetwork.Pass.csproj" />
|
||||
<ProjectReference Include="..\DysonNetwork.Ring\DysonNetwork.Ring.csproj" />
|
||||
<ProjectReference Include="..\DysonNetwork.Shared\DysonNetwork.Shared.csproj" />
|
||||
|
@@ -9,6 +9,15 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7192;http://localhost:5156",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,15 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7092;http://localhost:5090",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,108 +0,0 @@
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using dotnet_etcd.interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yarp.ReverseProxy.Configuration;
|
||||
|
||||
namespace DysonNetwork.Gateway.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/.well-known")]
|
||||
public class WellKnownController(
|
||||
IConfiguration configuration,
|
||||
IProxyConfigProvider proxyConfigProvider,
|
||||
IEtcdClient etcdClient)
|
||||
: ControllerBase
|
||||
{
|
||||
public class IpCheckResponse
|
||||
{
|
||||
[JsonPropertyName("remote_ip")] public string? RemoteIp { get; set; }
|
||||
[JsonPropertyName("x_forwarded_for")] public string? XForwardedFor { get; set; }
|
||||
[JsonPropertyName("x_forwarded_proto")] public string? XForwardedProto { get; set; }
|
||||
[JsonPropertyName("x_forwarded_host")] public string? XForwardedHost { get; set; }
|
||||
[JsonPropertyName("x_real_ip")] public string? XRealIp { get; set; }
|
||||
}
|
||||
|
||||
[HttpGet("ip-check")]
|
||||
public ActionResult<IpCheckResponse> GetIpCheck()
|
||||
{
|
||||
var ip = HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||
|
||||
var xForwardedFor = Request.Headers["X-Forwarded-For"].FirstOrDefault();
|
||||
var xForwardedProto = Request.Headers["X-Forwarded-Proto"].FirstOrDefault();
|
||||
var xForwardedHost = Request.Headers["X-Forwarded-Host"].FirstOrDefault();
|
||||
var realIp = Request.Headers["X-Real-IP"].FirstOrDefault();
|
||||
|
||||
return Ok(new IpCheckResponse
|
||||
{
|
||||
RemoteIp = ip,
|
||||
XForwardedFor = xForwardedFor,
|
||||
XForwardedProto = xForwardedProto,
|
||||
XForwardedHost = xForwardedHost,
|
||||
XRealIp = realIp
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("domains")]
|
||||
public IActionResult GetDomainMappings()
|
||||
{
|
||||
var domainMappings = configuration.GetSection("DomainMappings").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
return Ok(domainMappings);
|
||||
}
|
||||
|
||||
[HttpGet("services")]
|
||||
public IActionResult GetServices()
|
||||
{
|
||||
var local = configuration.GetValue<bool>("LocalMode");
|
||||
var response = etcdClient.GetRange("/services/");
|
||||
var kvs = response.Kvs;
|
||||
|
||||
var serviceMap = kvs.ToDictionary(
|
||||
kv => Encoding.UTF8.GetString(kv.Key.ToByteArray()).Replace("/services/", ""),
|
||||
kv => Encoding.UTF8.GetString(kv.Value.ToByteArray())
|
||||
);
|
||||
|
||||
if (local) return Ok(serviceMap);
|
||||
|
||||
var domainMappings = configuration.GetSection("DomainMappings").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
foreach (var (key, _) in serviceMap.ToList())
|
||||
{
|
||||
if (!domainMappings.TryGetValue(key, out var domain)) continue;
|
||||
if (domain is not null)
|
||||
serviceMap[key] = "http://" + domain;
|
||||
}
|
||||
|
||||
return Ok(serviceMap);
|
||||
}
|
||||
|
||||
[HttpGet("routes")]
|
||||
public IActionResult GetProxyRules()
|
||||
{
|
||||
var config = proxyConfigProvider.GetConfig();
|
||||
var rules = config.Routes.Select(r => new
|
||||
{
|
||||
r.RouteId,
|
||||
r.ClusterId,
|
||||
Match = new
|
||||
{
|
||||
r.Match.Path,
|
||||
Hosts = r.Match.Hosts != null ? string.Join(", ", r.Match.Hosts) : null
|
||||
},
|
||||
Transforms = r.Transforms?.Select(t => t.Select(kv => $"{kv.Key}: {kv.Value}").ToList())
|
||||
}).ToList();
|
||||
|
||||
var clusters = config.Clusters.Select(c => new
|
||||
{
|
||||
c.ClusterId,
|
||||
Destinations = c.Destinations?.Select(d => new
|
||||
{
|
||||
d.Key,
|
||||
d.Value.Address
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
|
||||
return Ok(new { Rules = rules, Clusters = clusters });
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["DysonNetwork.Gateway/DysonNetwork.Gateway.csproj", "DysonNetwork.Gateway/"]
|
||||
RUN dotnet restore "DysonNetwork.Gateway/DysonNetwork.Gateway.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/DysonNetwork.Gateway"
|
||||
RUN dotnet build "./DysonNetwork.Gateway.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./DysonNetwork.Gateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "DysonNetwork.Gateway.dll"]
|
@@ -1,24 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dotnet-etcd" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Yarp.ReverseProxy" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DysonNetwork.ServiceDefaults\DysonNetwork.ServiceDefaults.csproj" />
|
||||
<ProjectReference Include="..\DysonNetwork.Shared\DysonNetwork.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@@ -1,40 +0,0 @@
|
||||
using DysonNetwork.Gateway.Startup;
|
||||
using DysonNetwork.Shared.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
|
||||
builder.Host.UseContentRoot(Directory.GetCurrentDirectory());
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = long.MaxValue;
|
||||
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
|
||||
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30);
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddGateway(builder.Configuration);
|
||||
builder.Services.AddControllers();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapDefaultEndpoints();
|
||||
|
||||
app.ConfigureForwardedHeaders(app.Configuration);
|
||||
|
||||
app.UseRequestTimeouts();
|
||||
app.UseCors(opts =>
|
||||
opts.SetIsOriginAllowed(_ => true)
|
||||
.WithExposedHeaders("*")
|
||||
.WithHeaders("*")
|
||||
.AllowCredentials()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
);
|
||||
|
||||
app.MapControllers();
|
||||
app.MapReverseProxy();
|
||||
|
||||
app.Run();
|
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5094",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7034;http://0.0.0.0:5094",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,239 +0,0 @@
|
||||
using System.Text;
|
||||
using dotnet_etcd.interfaces;
|
||||
using Yarp.ReverseProxy.Configuration;
|
||||
using Yarp.ReverseProxy.Forwarder;
|
||||
|
||||
namespace DysonNetwork.Gateway;
|
||||
|
||||
public class RegistryProxyConfigProvider : IProxyConfigProvider, IDisposable
|
||||
{
|
||||
private readonly object _lock = new();
|
||||
private readonly IEtcdClient _etcdClient;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<RegistryProxyConfigProvider> _logger;
|
||||
private readonly CancellationTokenSource _watchCts = new();
|
||||
private CancellationTokenSource _cts;
|
||||
private IProxyConfig _config;
|
||||
|
||||
public RegistryProxyConfigProvider(
|
||||
IEtcdClient etcdClient,
|
||||
IConfiguration configuration,
|
||||
ILogger<RegistryProxyConfigProvider> logger
|
||||
)
|
||||
{
|
||||
_etcdClient = etcdClient;
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
_cts = new CancellationTokenSource();
|
||||
_config = LoadConfig();
|
||||
|
||||
// Watch for changes in etcd
|
||||
_etcdClient.WatchRange("/services/", _ =>
|
||||
{
|
||||
_logger.LogInformation("Etcd configuration changed. Reloading proxy config.");
|
||||
ReloadConfig();
|
||||
}, cancellationToken: _watchCts.Token);
|
||||
}
|
||||
|
||||
public IProxyConfig GetConfig() => _config;
|
||||
|
||||
private void ReloadConfig()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var oldCts = _cts;
|
||||
_cts = new CancellationTokenSource();
|
||||
_config = LoadConfig();
|
||||
oldCts.Cancel();
|
||||
oldCts.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private IProxyConfig LoadConfig()
|
||||
{
|
||||
_logger.LogInformation("Generating new proxy config.");
|
||||
var response = _etcdClient.GetRange("/services/");
|
||||
var kvs = response.Kvs;
|
||||
|
||||
var serviceMap = kvs.ToDictionary(
|
||||
kv => Encoding.UTF8.GetString(kv.Key.ToByteArray()).Replace("/services/", ""),
|
||||
kv => Encoding.UTF8.GetString(kv.Value.ToByteArray())
|
||||
);
|
||||
|
||||
var clusters = new List<ClusterConfig>();
|
||||
var routes = new List<RouteConfig>();
|
||||
|
||||
var domainMappings = _configuration.GetSection("DomainMappings").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
var pathAliases = _configuration.GetSection("PathAliases").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
var directRoutes = _configuration.GetSection("DirectRoutes").Get<List<DirectRouteConfig>>() ??
|
||||
[];
|
||||
|
||||
_logger.LogInformation("Indexing {ServiceCount} services from Etcd.", kvs.Count);
|
||||
|
||||
var gatewayServiceName = _configuration["Service:Name"];
|
||||
|
||||
// Add direct routes
|
||||
foreach (var directRoute in directRoutes)
|
||||
{
|
||||
if (serviceMap.TryGetValue(directRoute.Service, out var serviceUrl))
|
||||
{
|
||||
var existingCluster = clusters.FirstOrDefault(c => c.ClusterId == directRoute.Service);
|
||||
if (existingCluster is null)
|
||||
{
|
||||
var cluster = new ClusterConfig
|
||||
{
|
||||
ClusterId = directRoute.Service,
|
||||
Destinations = new Dictionary<string, DestinationConfig>
|
||||
{
|
||||
{ "destination1", new DestinationConfig { Address = serviceUrl } }
|
||||
},
|
||||
};
|
||||
clusters.Add(cluster);
|
||||
}
|
||||
|
||||
var route = new RouteConfig
|
||||
{
|
||||
RouteId = $"direct-{directRoute.Service}-{directRoute.Path.Replace("/", "-")}",
|
||||
ClusterId = directRoute.Service,
|
||||
Match = new RouteMatch { Path = directRoute.Path },
|
||||
};
|
||||
routes.Add(route);
|
||||
_logger.LogInformation(" Added Direct Route: {Path} -> {Service}", directRoute.Path,
|
||||
directRoute.Service);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning(" Direct route service {Service} not found in Etcd.", directRoute.Service);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var serviceName in serviceMap.Keys)
|
||||
{
|
||||
if (serviceName == gatewayServiceName)
|
||||
{
|
||||
_logger.LogInformation("Skipping gateway service: {ServiceName}", serviceName);
|
||||
continue;
|
||||
}
|
||||
|
||||
var serviceUrl = serviceMap[serviceName];
|
||||
|
||||
// Determine the path alias
|
||||
string? pathAlias;
|
||||
pathAlias = pathAliases.TryGetValue(serviceName, out var alias)
|
||||
? alias
|
||||
: serviceName.Split('.').Last().ToLowerInvariant();
|
||||
|
||||
_logger.LogInformation(" Service: {ServiceName}, URL: {ServiceUrl}, Path Alias: {PathAlias}", serviceName,
|
||||
serviceUrl, pathAlias);
|
||||
|
||||
// Check if the cluster already exists
|
||||
var existingCluster = clusters.FirstOrDefault(c => c.ClusterId == serviceName);
|
||||
if (existingCluster == null)
|
||||
{
|
||||
var cluster = new ClusterConfig
|
||||
{
|
||||
ClusterId = serviceName,
|
||||
Destinations = new Dictionary<string, DestinationConfig>
|
||||
{
|
||||
{ "destination1", new DestinationConfig { Address = serviceUrl } }
|
||||
}
|
||||
};
|
||||
clusters.Add(cluster);
|
||||
_logger.LogInformation(" Added Cluster: {ServiceName}", serviceName);
|
||||
}
|
||||
else if (existingCluster.Destinations is not null)
|
||||
{
|
||||
// Create a new cluster with merged destinations
|
||||
var newDestinations = new Dictionary<string, DestinationConfig>(existingCluster.Destinations)
|
||||
{
|
||||
{
|
||||
$"destination{existingCluster.Destinations.Count + 1}",
|
||||
new DestinationConfig { Address = serviceUrl }
|
||||
}
|
||||
};
|
||||
|
||||
var mergedCluster = new ClusterConfig
|
||||
{
|
||||
ClusterId = serviceName,
|
||||
Destinations = newDestinations
|
||||
};
|
||||
|
||||
// Replace the existing cluster with the merged one
|
||||
var index = clusters.IndexOf(existingCluster);
|
||||
clusters[index] = mergedCluster;
|
||||
|
||||
_logger.LogInformation(" Updated Cluster {ServiceName} with {DestinationCount} destinations",
|
||||
serviceName, mergedCluster.Destinations.Count);
|
||||
}
|
||||
|
||||
// Host-based routing
|
||||
if (domainMappings.TryGetValue(serviceName, out var domain) && domain is not null)
|
||||
{
|
||||
var hostRoute = new RouteConfig
|
||||
{
|
||||
RouteId = $"{serviceName}-host",
|
||||
ClusterId = serviceName,
|
||||
Match = new RouteMatch
|
||||
{
|
||||
Hosts = [domain],
|
||||
Path = "/{**catch-all}"
|
||||
},
|
||||
};
|
||||
routes.Add(hostRoute);
|
||||
_logger.LogInformation(" Added Host-based Route: {Host}", domain);
|
||||
}
|
||||
|
||||
// Path-based routing
|
||||
var pathRoute = new RouteConfig
|
||||
{
|
||||
RouteId = $"{serviceName}-path",
|
||||
ClusterId = serviceName,
|
||||
Match = new RouteMatch { Path = $"/{pathAlias}/{{**catch-all}}" },
|
||||
Transforms = new List<Dictionary<string, string>>
|
||||
{
|
||||
new() { { "PathRemovePrefix", $"/{pathAlias}" } },
|
||||
new() { { "PathPrefix", "/api" } },
|
||||
},
|
||||
Timeout = TimeSpan.FromSeconds(5)
|
||||
};
|
||||
routes.Add(pathRoute);
|
||||
_logger.LogInformation(" Added Path-based Route: {Path}", pathRoute.Match.Path);
|
||||
}
|
||||
|
||||
return new CustomProxyConfig(
|
||||
routes,
|
||||
clusters,
|
||||
new Microsoft.Extensions.Primitives.CancellationChangeToken(_cts.Token)
|
||||
);
|
||||
}
|
||||
|
||||
private class CustomProxyConfig(
|
||||
IReadOnlyList<RouteConfig> routes,
|
||||
IReadOnlyList<ClusterConfig> clusters,
|
||||
Microsoft.Extensions.Primitives.IChangeToken changeToken
|
||||
)
|
||||
: IProxyConfig
|
||||
{
|
||||
public IReadOnlyList<RouteConfig> Routes { get; } = routes;
|
||||
public IReadOnlyList<ClusterConfig> Clusters { get; } = clusters;
|
||||
public Microsoft.Extensions.Primitives.IChangeToken ChangeToken { get; } = changeToken;
|
||||
}
|
||||
|
||||
public record DirectRouteConfig
|
||||
{
|
||||
public required string Path { get; set; }
|
||||
public required string Service { get; set; }
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
_cts.Cancel();
|
||||
_cts.Dispose();
|
||||
_watchCts.Cancel();
|
||||
_watchCts.Dispose();
|
||||
}
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
using System.Net.Security;
|
||||
using Yarp.ReverseProxy.Configuration;
|
||||
using Yarp.ReverseProxy.Transforms;
|
||||
|
||||
namespace DysonNetwork.Gateway.Startup;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddGateway(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddRequestTimeouts();
|
||||
|
||||
services
|
||||
.AddReverseProxy()
|
||||
.ConfigureHttpClient((context, handler) =>
|
||||
{
|
||||
// var caCert = X509CertificateLoader.LoadCertificateFromFile(configuration["CaCert"]!);
|
||||
handler.SslOptions = new SslClientAuthenticationOptions
|
||||
{
|
||||
RemoteCertificateValidationCallback = (sender, cert, chain, errors) => true
|
||||
};
|
||||
})
|
||||
.AddTransforms(context =>
|
||||
{
|
||||
context.CopyRequestHeaders = true;
|
||||
context.AddOriginalHost();
|
||||
context.AddForwarded(action: ForwardedTransformActions.Set);
|
||||
context.AddXForwarded(action: ForwardedTransformActions.Set);
|
||||
});
|
||||
|
||||
services.AddSingleton<IProxyConfigProvider, RegistryProxyConfigProvider>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
using DysonNetwork.Shared.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DysonNetwork.Gateway;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/version")]
|
||||
public class VersionController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
return Ok(new AppVersion
|
||||
{
|
||||
Version = ThisAssembly.AssemblyVersion,
|
||||
Commit = ThisAssembly.GitCommitId,
|
||||
UpdateDate = ThisAssembly.GitCommitDate
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
{
|
||||
"LocalMode": true,
|
||||
"CaCert": "../Certificates/ca.crt",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"Etcd": "etcd.orb.local:2379"
|
||||
},
|
||||
"Etcd": {
|
||||
"Insecure": true
|
||||
},
|
||||
"Service": {
|
||||
"Name": "DysonNetwork.Gateway",
|
||||
"Url": "https://localhost:7034"
|
||||
},
|
||||
"DomainMappings": {
|
||||
"DysonNetwork.Pass": "id.solsynth.dev",
|
||||
"DysonNetwork.Drive": "drive.solsynth.dev",
|
||||
"DysonNetwork.Ring": "push.solsynth.dev",
|
||||
"DysonNetwork.Sphere": "sphere.solsynth.dev"
|
||||
},
|
||||
"PathAliases": {
|
||||
"DysonNetwork.Pass": "id",
|
||||
"DysonNetwork.Drive": "drive"
|
||||
},
|
||||
"DirectRoutes": [
|
||||
{
|
||||
"Path": "/ws",
|
||||
"Service": "DysonNetwork.Ring"
|
||||
},
|
||||
{
|
||||
"Path": "/api/tus",
|
||||
"Service": "DysonNetwork.Drive"
|
||||
},
|
||||
{
|
||||
"Path": "/.well-known/openid-configuration",
|
||||
"Service": "DysonNetwork.Pass"
|
||||
},
|
||||
{
|
||||
"Path": "/.well-known/jwks",
|
||||
"Service": "DysonNetwork.Pass"
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"publicReleaseRefSpec": ["^refs/heads/main$"],
|
||||
"cloudBuild": {
|
||||
"setVersionVariables": true
|
||||
}
|
||||
}
|
@@ -9,6 +9,15 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7058;http://localhost:5216",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,15 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7259;http://localhost:5212",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,9 @@ public static class Extensions
|
||||
|
||||
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
// Allow unencrypted grpc
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
|
||||
builder.ConfigureOpenTelemetry();
|
||||
|
||||
builder.AddDefaultHealthChecks();
|
||||
|
@@ -9,6 +9,15 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7099;http://localhost:5071",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DysonNetwork.Ring", "DysonN
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DysonNetwork.Drive", "DysonNetwork.Drive\DysonNetwork.Drive.csproj", "{8DE0B783-8852-494D-B90A-201ABBB71202}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DysonNetwork.Gateway", "DysonNetwork.Gateway\DysonNetwork.Gateway.csproj", "{19EB0086-4049-4B78-91C4-EAC37130A006}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DysonNetwork.Develop", "DysonNetwork.Develop\DysonNetwork.Develop.csproj", "{C577AA78-B11D-4076-89A6-1C7F0ECC04E2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DysonNetwork.Control", "DysonNetwork.Control\DysonNetwork.Control.csproj", "{7FFED190-51C7-4302-A8B5-96C839463458}"
|
||||
@@ -50,10 +48,6 @@ Global
|
||||
{8DE0B783-8852-494D-B90A-201ABBB71202}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8DE0B783-8852-494D-B90A-201ABBB71202}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8DE0B783-8852-494D-B90A-201ABBB71202}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{19EB0086-4049-4B78-91C4-EAC37130A006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{19EB0086-4049-4B78-91C4-EAC37130A006}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{19EB0086-4049-4B78-91C4-EAC37130A006}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{19EB0086-4049-4B78-91C4-EAC37130A006}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C577AA78-B11D-4076-89A6-1C7F0ECC04E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C577AA78-B11D-4076-89A6-1C7F0ECC04E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C577AA78-B11D-4076-89A6-1C7F0ECC04E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
@@ -93,6 +93,7 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AJwtSecurityTokenHandler_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F477051138f1f40de9077b7b1cdc55c6215fb0_003Ff5_003Fd716e016_003FJwtSecurityTokenHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKestrelServerLimits_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F1e2e5dfcafad4407b569dd5df56a2fbf274e00_003Fa4_003F39445f62_003FKestrelServerLimits_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKnownResamplers_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fef3339e864a448e2b1ec6fa7bbf4c6661fee00_003Fb3_003Fcdb3e080_003FKnownResamplers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AListenOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fafff40a572554b579e7307e8ac16b014279a00_003Fc7_003Ff445744a_003FListenOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALivekitRoom_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F82666257d5ad47354add7af860f66dd85df55ec93e92e8a45891b9bff7bf80ac_003FLivekitRoom_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALocalDate_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F9bab6c3f4ee252ba1a9d0707f963a846da4f248fa52e9ff43e789149728a4_003FLocalDate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMailboxAddress_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8e03e47c46b7469f97abc40667cbcf9b133000_003Fa6_003F83324248_003FMailboxAddress_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
|
Reference in New Issue
Block a user