Repository navigation
Add Microsoft Entra ID and AWS IAM token authentication to PostgreSQL connections - #6064
Draft
johnsimons wants to merge 2 commits into
Draft
johnsimons wants to merge 2 commits into
johnsimons wants to merge 2 commits into
Conversation
johnsimons
force-pushed
the
john/token_refresh
branch
from
October 29, 2026 23:57
c6feec3 to
2574549
Compare
…L and SQL Server connections Passwords stored in connection strings don't work for managed databases that require short-lived tokens. A new ServiceControl.PostgreSql.TokenAuthentication project parses "Token Authentication" and "Token Scope" connection string keywords, builds an NpgsqlDataSource whose password provider refreshes the token periodically, and wires it into both EF Core persisters and the PostgreSql transport/throughput query/queue length provider. SQL Server gets Entra ID support through SqlClient's own Active Directory Default authentication. The cloud-database GitHub Action now provisions the infrastructure needed to exercise this: an Entra ID admin service principal for Azure SQL/PostgreSQL, and an sc_iam IAM-authenticated role on Aurora PostgreSQL, exporting *_TokenConnectionString variables that new token authentication test fixtures use. Docs describe the new workflow and variables.
johnsimons
force-pushed
the
john/token_refresh
branch
from
October 30, 2026 01:32
2574549 to
99693f4
Compare
Needed to match the SqlClient version used for Entra ID Active Directory Default authentication.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ServiceControl can now sign in to PostgreSQL with a Microsoft Entra ID token or an AWS RDS IAM token instead of a password. This covers the EF Core PostgreSQL persisters of the primary and audit instances and the PostgreSQL transport, including its queue length provider and throughput query. Password connection strings work as before.
Managed PostgreSQL on Azure and AWS can require token sign-in, and the tokens expire after minutes or hours. ServiceControl passed the connection string straight to Npgsql, so it could not refresh a token. SQL Server already supports Entra ID through SqlClient's
Authentication=Active Directory Defaultsince #5786, and this PR adds the first test of that path.Configuration
A keyword in the existing connection string turns token authentication on:
Token Authentication=AzureEntraIdgets the token fromDefaultAzureCredential. ServiceControl derives the scope and authority host from the host name for the public, US Government and China clouds. For other host names, such as a custom DNS name,Token Scope=<https URI>sets the scope.Token Authentication=AwsRdsIamsigns the token with the AWS SDK's default credentials and region. The connection string must name exactly one host, because an IAM token is signed for one host and port.The connection string needs a
Usernameand must not containPasswordorPassfile. ServiceControl removes the keywords before Npgsql reads the string. A connection string without either keyword is not parsed at all, so a malformed password connection string fails in the same place as before.An invalid value fails with an
InvalidOperationExceptionthat names the setting:Database/ConnectionString,LicensingComponent/PostgreSQL/ConnectionStringor the transport connection string.No setting is added, so ServiceControl Management, PowerShell and container configuration need no change. The
Helptext in the transport manifest describes the keyword.How it works
src/ServiceControl.PostgreSql.TokenAuthentication/, which has no project file. Both persisters and the transport compile it as linked source.NpgsqlDataSourcewith a periodic password provider. It gets a new token every 5 minutes and tries again 10 seconds after a failure, which it logs as an error. Five minutes is well inside the 15-minute lifetime of an AWS token, and it limits how oftenAzureCliCredentialstarts a process, which it does on every call.AWSSDK.SecurityToken, whichAWSSDK.Coreloads by name for web identity (EKS IRSA) and assume-role credentials.ServiceControl.Persistence.EFCoregets the same reference. Without it,--setupof a primary instance with S3 body storage and web identity credentials fails to load that assembly.Alternatives considered
Microsoft.Azure.PostgreSQL.Auth1.0.0 instead of our own Azure provider. It hard-codes the public cloud scope, requests amanagement.azure.comtoken to find the user name, and gets a token on every connection open.Authentication. A separate name avoids implying that SqlClient's otherAuthenticationvalues work here.