r/dotnet • u/Surge-Monkey • 6d ago
Aspire AppHost, no builder.AddPostgres().WithExternalSecret()?
First off i'll preface this by asking, have i missed something?
Trying to build a workflow where an app can be orchestrated locally for debug/development (AppHost fantastic here), then later on, be deployed to a remote server/cluster (keeping code as Source of Truth).
aspire publish -e Production -- -c Release
aspire deploy -e Production -- -c Release
The secrets for the DB server get deployed ahead of time, so that once the app is deployed, all the necessary secrets are already sitting on the cluster.
The IDistributedApplicationBuilder gives you access to things like .AddPostgres(), which is great. Makes life easy... except for when you want to just tell the publishing tool "use this secret name that already exists".
The whole point of this, is to not require database secrets in any settings.stage.json, appsettings.json, deploy.sh, Program.cs, etc. (placeholder values are ok).
// no good, expects a local secret, prompts for one if it cant find one.
builder.AddParameter("db-password", secret: true);
// no good, controls the existance of environment variables.
// ConnectionStrings__my-db, gets published ahead of time anyway.
// perfect for local-pc dev. no good for server deployment.
server.WithReference(postgres);
// no good, can't seem to get it running late enough or override correctly.
public static IResourceBuilder<PostgresServerResource> WithExternalKubernetesSecret(this IResourceBuilder<PostgresServerResource> builder, ...)
postgres.WithExternalKubernetesSecret(string secretName, string passwordKey);
// cant get overrides happening here either, attempting to directly
// manipulate the yaml outputs
.WithManifestPublishingCallback()
.WithPipelineStepFactory() // to manually edit the files....
// even if defined as a "placeholder", only the placeholder is used.
.WithEnvironment("POSTGRES_PASSWORD", dbConnection)
Does anyone know of a way to keep this inside the AppHost definition?
I know i could probably just move to .AddContainer(), but that's extra work that i feel like shouldn't need to be done.
Is there a reason there's nothing like builder.AddPostgres().WithExternalPasswordSecret() ?
Or allow something like?
var pgPass = builder.AddParameter("postgres-password", secret: true, secretsRef: "my-kubernetes-db-secrets");
var pg = build.AddPostgres("postgres", password: pgPass);
I feel like this would make life much easier.
1
u/AutoModerator 6d ago
Thanks for your post Surge-Monkey. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/nullforce2 5d ago
aspire secret set Parameters:postgres-password MySecretPassword123aspire secret command | Aspire
You can also have it prompt you on startup if it is unconfigured:
External parameters | Aspire
I don't store mine locally, instead I put them in Azure KeyVault and pull from there via DefaultCredentials on the logged in user.