-
Notifications
You must be signed in to change notification settings - Fork 143
feat: add Zitadel host integration #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@dotnet-policy-service agree |
aaronpowell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned a problem with hostnames, can you tag the line(s) where that's surfacing?
Currently that would be https://github.com/CommunityToolkit/Aspire/pull/1021/files/677452ebe38d7be79caf11268057182f5594136d#diff-427aa76f92a729429b7b134c3be02f0a722e8ab12d85a50a2bc822d9819cda33R35 Zitadel requires a "stable" external hostname or it'll return a 404 if the This means that if I configure the external hostname as Currently I'm setting it to |
b84f375 to
10c9a28
Compare
|
rebased changes on |
|
Is there a reason that the |
How would I retrieve that? |
Use the endpoint reference and get the allocated endpoint, that will have all the parts of the endpoint on it |
|
@aaronpowell one final tweak I'd like to make is that the Aspire dashboard generates the URL to the dashboard with it's a minor thing as this only affects the link shown in the dashboard, but I feel it would be a lot more polished if I managed to get that working as well |
|
I think I'm still not properly understanding the role of the The endpoint reference host is going to be pointing to the host that the resource is exposed within the container network, so Resources outside the network, say your browser, would use the host So then, shouldn't the |
Agreed, whenever I run without setting the external domain I get
|
A single Zitadel instance can have multiple "virtual" instances running and it uses the This means if we set Let's assume the following setup in Aspire: var builder = DistributedApplication.CreateBuilder(args);
var database = builder.AddPostgres("postgres");
builder.AddZitadel("zitadel")
.WithDatabase(database);
builder.AddProject<Example>("my-example")
.WithReference(zitadel);
builder.Build().Run();if we set
As a middle ground I set I hope that helps clarify the role of |
|
@dealloc APIs to make the .NET dev cert available to resources (and configure them to use it) are in Aspire main and will ship with 13.1 as early as next week, so you'd be able to get HTTPS working once that's available. |
|
Also, as a heads up, |
| .WithUrlForEndpoint(ZitadelResource.HttpEndpointName, e => e.DisplayText = "Zitadel Dashboard"); | ||
|
|
||
| // Use ReferenceExpression for the port to avoid issues with endpoint allocation | ||
| var endpoint = resource.GetEndpoint(ZitadelResource.HttpEndpointName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will get a reference to the endpoint from the perspective of the host, so it'll resolve the localhost domain and port instead of the internal container address and port. That being said there's a bug that'll need to be fixed that's preventing the network identifier from actually applying: dotnet/aspire#13440
| var endpoint = resource.GetEndpoint(ZitadelResource.HttpEndpointName); | |
| var endpoint = resource.GetEndpoint(ZitadelResource.HttpEndpointName, KnownNetworkIdentifiers.LocalhostNetwork); |
| .WithEnvironment("ZITADEL_TLS_ENABLED", "false") | ||
| .WithEnvironment("ZITADEL_EXTERNALSECURE", "false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once Aspire 13.1 is available, this will get you HTTPS support. It'll set the appropriate config if the resource is configured with a certificate (it'll get the ASP.NET development certificate by default):
| .WithEnvironment("ZITADEL_TLS_ENABLED", "false") | |
| .WithEnvironment("ZITADEL_EXTERNALSECURE", "false") | |
| .WithEnvironment("ZITADEL_TLS_ENABLED", "false") | |
| .WithEnvironment("ZITADEL_EXTERNALSECURE", "false") | |
| .WithHttpsCertificateConfiguration(ctx => | |
| { | |
| ctx.EnvironmentVariables["ZITADEL_EXTERNALSECURE"] = "true"; | |
| ctx.EnvironmentVariables["ZITADEL_TLS_ENABLED"] = "true"; | |
| ctx.EnvironmentVariables["ZITADEL_TLS_CERTPATH"] = ctx.CertificatePath; | |
| ctx.EnvironmentVariables["ZITADEL_TLS_KEYPATH"] = ctx.KeyPath; | |
| return Task.CompletedTask; | |
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also need something like this to optionally enable HTTPS on the endpoint. It's a bit boilerplate currently as we're still working on the API for updating endpoints:
if (builder.ExecutionContext.IsRunMode)
{
builder.Eventing.Subscribe<BeforeStartEvent>((@event, cancellationToken) =>
{
var developerCertificateService = @event.Services.GetRequiredService<IDeveloperCertificateService>();
bool addHttps = false;
if (!zitadelBuilder.Resource.TryGetLastAnnotation<HttpsCertificateAnnotation>(out var annotation))
{
if (developerCertificateService.UseForHttps)
{
// If no certificate is configured, and the developer certificate service supports container trust,
// configure the resource to use the developer certificate for its key pair.
addHttps = true;
}
}
else if (annotation.UseDeveloperCertificate.GetValueOrDefault(developerCertificateService.UseForHttps) || annotation.Certificate is not null)
{
addHttps = true;
}
if (addHttps)
{
// If a TLS certificate is configured, override the endpoint to use HTTPS instead of HTTP
// Zitadel only binds to a single port
zitadelBuilder
.WithEndpoint(ZitadelResource.HttpEndpointName, ep => ep.UriScheme = "https");
}
return Task.CompletedTask;
});
}
Closes #1015
Adds host support for Zitadel to Aspire.
PR Checklist
Other information
Currently in draft since I haven't figured out everything.
<name>but if you open from the dashboard it'slocalhost:<port>. Currently it uses a semi-hardcoded<name>.dev.localhostas a middle ground.I played around with something similar to Keycloak's
WithRealmImportto "seed" the instance but AFAIK Zitadel doesn't support such things.I need to update some of the docs that are missing and write the tests, not sure if the example I've included is sufficient for now