Skip to content

NR-428950: Added support for Entra ID (AD Service Principal) authentication. #242

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

Merged
merged 7 commits into from
Jul 4, 2025

Conversation

satya-nr
Copy link
Contributor

@satya-nr satya-nr commented Jul 2, 2025

This pull request includes modifications to extend the authentication options to Entra ID in addition to the existing SQL authentication. The changes were tested using the appropriate tenant_id, client_id, and client_secret as username and password, confirming that queries execute successfully with a proper connection. Additionally, test cases have been added to verify the functionality of the CreateEntraIdConnectionURL function.

Documentation changes - newrelic/docs-website@01b3e49

@satya-nr satya-nr requested a review from a team as a code owner July 2, 2025 04:42
Copy link
Contributor

@sairaj18 sairaj18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this change. Left few comments. Also, please update the mssql-config.yml with other example of the config for Entra ID service principal authentication.

Copy link
Contributor

@sairaj18 sairaj18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the earlier comments. Left a few more comments.

@@ -17,8 +17,8 @@ const (
// ArgumentList struct that holds all MSSQL arguments
type ArgumentList struct {
sdkArgs.DefaultArgumentList
Username string `default:"" help:"The Microsoft SQL Server connection user name"`
Password string `default:"" help:"The Microsoft SQL Server connection password"`
Username string `default:"" help:"The Microsoft SQL Server connection user name. For Azure AD Service Principal, use format: <client_id>@<tenant_id>"`
Copy link
Contributor

@sairaj18 sairaj18 Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here instead of using the same fields for Azure AD Service Principal. Adding new optional args will make identifying authtype more easy.

Comment on lines 20 to 21
Username string `default:"" help:"The Microsoft SQL Server connection user name. For Azure AD Service Principal, use format: <client_id>@<tenant_id>"`
Password string `default:"" help:"The Microsoft SQL Server connection password. For Azure AD Service Principal, use client secret"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why we are reusing username, password fields for SP values. Would it not be easier for the users to have clear field names for args: client_id, tenant_id, client_secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added changes, please review it.

@@ -50,4 +50,54 @@ integrations:
# db_hostname: my-custom-hostname # useful to filter in dashboards, especially in multi-server environments.
inventory_source: config/mssql

- name: nri-mssql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Adding a comment about what this config represents will help when refered in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done added.

sairaj18
sairaj18 previously approved these changes Jul 3, 2025
@sairaj18 sairaj18 dismissed their stale review July 3, 2025 13:27

LGTM, I'll leave it to Rohan for final approval

Comment on lines 41 to 63
func determineAuthMethod(args *args.ArgumentList) (AuthConnector, error) {
azureFieldsProvided := 0
if args.ClientID != "" {
azureFieldsProvided++
}
if args.TenantID != "" {
azureFieldsProvided++
}
if args.ClientSecret != "" {
azureFieldsProvided++
}

if azureFieldsProvided == 3 {
log.Debug("Detected Azure AD Service Principal authentication - using ClientID, TenantID, and ClientSecret")
return AzureADAuthConnector{}, nil
}

if azureFieldsProvided > 0 && azureFieldsProvided < 3 {
return nil, fmt.Errorf("incomplete Azure AD Service Principal credentials: all three fields (ClientID, TenantID, ClientSecret) must be provided together")
}

return SQLAuthConnector{}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic can be improved. It's not extendable in it's current state.
I'd just write helper functions to return true if certain auth type is satisfied. And have a switch to go through them. This means adding new method is as simple as adding a new helper and another condition in the switch. The default for the switch will be an error because that is only hit if we don't have sufficient args for any of the auth types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added changes as per review, for default authentication we cant check username/password because for gMSA user both can be empty. So i added SQL authenticator in default case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQL Server authentication can work with empty username and password in some cases (like Windows Authentication).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, okay, so default case could be that, but I still don't understand why you need azureFieldsProvided, could you not put them in a single condition?

@sairaj18
Copy link
Contributor

sairaj18 commented Jul 4, 2025

Documentation updates to support EntraId Authentication for Azure SQL Managed Instance are in this comment of this PR

Copy link
Contributor

@rajrohanyadav rajrohanyadav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@satya-nr satya-nr merged commit 794649d into master Jul 4, 2025
16 checks passed
@satya-nr satya-nr deleted the NR-428950 branch July 4, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants