Skip to content
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

Azure PostgreSQL should support managed identity #5793

Closed
eerhardt opened this issue Sep 19, 2024 · 0 comments · Fixed by #5930
Closed

Azure PostgreSQL should support managed identity #5793

eerhardt opened this issue Sep 19, 2024 · 0 comments · Fixed by #5930
Assignees
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure postgres Issues related to Postgres integrations security 🔐
Milestone

Comments

@eerhardt
Copy link
Member

When provisioning a PostgreSQL database server today, we use an admin user name and password. This approach isn't as secure as using managed identity.

See

We should have an option for enabling managed identity / Entra ID when provisioning PostgreSQL database servers.

One could argue that we should do this by default, in the name of security. However, the problem is that the app connecting to this database is going to have to change to follow the steps in https://devblogs.microsoft.com/dotnet/using-postgre-sql-with-dotnet-and-entra-id/. So it would break apps when they published to Azure, if the app wasn't set up to work with Entra ID.

Proposal

Add a new enum that gets passed into .AsAzurePostgresFlexibleServer() that switches which kind of auth is used.

namespace Aspire.Hosting.Azure;

public enum AzurePostgresAuth
{
    Password = 0,
    ActiveDirectory = 1 // Note this is the name used in ARM, Bicep, CDK
}

// user code
var pgsqldb = builder.AddPostgres("pgsql")
    .AsAzurePostgresFlexibleServer(AzurePostgresAuth.ActiveDirectory)
    .AddDatabase("pgsqldb");

Alternative

We could add a new extension method .WithActiveDirectoryAuth() that disables the password based auth and switches the administrator to use managed identity.

var pgsqldb = builder.AddPostgres("pgsql")
    .AsAzurePostgresFlexibleServer()
    .WithActiveDirectoryAuth()
    .AddDatabase("pgsqldb");

The downfall of this is that it would need to hang off IResourceBuilder<PostgresServerResource> and if someone called it without calling AsAzurePostgresFlexibleServer first it wouldn't work well.

cc @mitchdenny @davidfowl @tg-msft @sebastienros @radical

@eerhardt eerhardt added this to the 9.0 milestone Sep 19, 2024
@eerhardt eerhardt added area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure security 🔐 postgres Issues related to Postgres integrations labels Sep 19, 2024
@eerhardt eerhardt added feature and removed feature labels Sep 23, 2024
@eerhardt eerhardt self-assigned this Sep 23, 2024
eerhardt added a commit to eerhardt/aspire that referenced this issue Sep 25, 2024
- Add a new API to replace AsAzure and PublishAsAzure. This creates an Azure resource to start, so it can be configured like other azure resources. Since this is a new API, we can use managed identity by default.

- Add an API to convert managed identity to password based auth, so users can still go that route if they need to.

- Add RunAsContainer following the RunAsEmulator model. This allows local development against a PostreSQL container and publish to go to a manged Azure PostgreSQL flexible server.

Fix dotnet#5793
eerhardt added a commit to eerhardt/aspire that referenced this issue Sep 27, 2024
- Add a new API to replace AsAzure and PublishAsAzure. This creates an Azure resource to start, so it can be configured like other azure resources. Since this is a new API, we can use managed identity by default.

- Add an API to convert managed identity to password based auth, so users can still go that route if they need to.

- Add RunAsContainer following the RunAsEmulator model. This allows local development against a PostreSQL container and publish to go to a manged Azure PostgreSQL flexible server.

Fix dotnet#5793
eerhardt added a commit to eerhardt/aspire that referenced this issue Sep 30, 2024
- Add a new API to replace AsAzure and PublishAsAzure. This creates an Azure resource to start, so it can be configured like other azure resources. Since this is a new API, we can use managed identity by default.

- Add an API to convert managed identity to password based auth, so users can still go that route if they need to.

- Add RunAsContainer following the RunAsEmulator model. This allows local development against a PostreSQL container and publish to go to a manged Azure PostgreSQL flexible server.

Fix dotnet#5793
eerhardt added a commit to eerhardt/aspire that referenced this issue Sep 30, 2024
- Add a new API to replace AsAzure and PublishAsAzure. This creates an Azure resource to start, so it can be configured like other azure resources. Since this is a new API, we can use managed identity by default.

- Add an API to convert managed identity to password based auth, so users can still go that route if they need to.

- Add RunAsContainer following the RunAsEmulator model. This allows local development against a PostreSQL container and publish to go to a manged Azure PostgreSQL flexible server.

Fix dotnet#5793
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure postgres Issues related to Postgres integrations security 🔐
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant