Skip to content

[receiver/azuremonitor] Add support for azureauthextension #39658

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 39 commits into from
May 14, 2025

Conversation

constanca-m
Copy link
Contributor

Description

Add support for extension azureauth for authentication.

Link to tracking issue

Fixes #39048.

Testing

Unit tests added.

Documentation

README updated.

Copy link
Member

@celian-garcia celian-garcia left a comment

Choose a reason for hiding this comment

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

Thank you for that effort! I will later probably remove the old one but that's ok to have both for a while.
I let you rule the red pipeline and answer my different comments.

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azuremonitorreceiver/internal/metadata"
)

func TestLoadConfig(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for that! So cool to see some tests of this quality for the config :)

@@ -23,7 +23,9 @@ The following settings are required:

The following settings are optional:

- `auth` (default = service_principal): Specifies the used authentication method. Supported values are `service_principal`, `workload_identity`, `managed_identity`, `default_credentials`.
- `token_provider` or `auth` (default = service_principal): Specifies the used authentication method:
Copy link
Member

Choose a reason for hiding this comment

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

I think it can be clearer if you keep token_provider and auth separated bullet points. You can have a little duplication here no problem as I think I will remove auth later on.
Can you also put a deprecated flag on the auth one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have added it in the README, and also added a warning in the code:

s.settings.Logger.Warn("'auth' is deprecated, use 'credentials' instead")

receivers:
azuremonitor:
subscription_ids: ["${subscription_id}"]
token_provider: azureauth
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that token_provider is the right term knowing that it does not generate token behind the scene. If you put that in others component though, I'm ok to keep same for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So far it is not use in any other components. Do you have a field name that you prefer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed to credentials. Is it better?

Copy link
Member

@celian-garcia celian-garcia Apr 29, 2025

Choose a reason for hiding this comment

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

I'm discovering a bit, but it looks like there is a recurring pattern.

auth:
  authenticator: <name of the extension>

image

There is a common structure for this in the collector https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configauth/configauth.go, it's used for all authentications.

That said this structure is dedicated to create http/grpc clients so what I would propose would be to create something like this:

  • In the azure auth extension, copy this structure, with the same logic, and with a getter to obtain the creds.
// Authentication defines the auth settings for the azure receiver.
type Authentication struct {
	// AuthenticatorID specifies the name of the azure extension to use in order to authenticate the incoming data point.
	AuthenticatorID component.ID `mapstructure:"authenticator,omitempty"`
}

// GetAzureTokenCredential attempts to select the credential of the appropriate azure extension from the list of extensions,
// based on the requested extension name. If an authenticator is not found, an error is returned.
func (a Authentication) GetAzureTokenCredential(_ context.Context, extensions map[component.ID]component.Component) (*azcore.TokenCredential, error) {
	if ext, found := extensions[a.AuthenticatorID]; found {
		if cred, ok := ext.(azcore.TokenCredential); ok {
			return &cred, nil
		}
		return nil, errNotServer
	}

	return nil, fmt.Errorf("failed to resolve authenticator %q: %w", a.AuthenticatorID, errAuthenticatorNotFound)
}
  • In the azure monitor receiver, add a field in config with that type, with a azureauth name (to avoid breaking change and it tells well what it is)
azureauth:
  authenticator: azureauth/prd

WDYT?

Copy link
Contributor Author

@constanca-m constanca-m Apr 29, 2025

Choose a reason for hiding this comment

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

The azureauth extension has the support for authenticator if the receiver requires client/server config (see this).

For this receiver, we actually need to use azcore.TokenCredential, which then implements this function.

So the easiest way would be to just replace the name credentials with authenticator in the receiver config (here). But I don't know if authenticator would be the best name, as we are not really using it as a client/server. Especially with authenticator being out of auth, which as you pointed out, is the common schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming could work, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I'm on it

Copy link
Member

Choose a reason for hiding this comment

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

Here it is #39738

Copy link
Member

Choose a reason for hiding this comment

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

They already merged it <3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @celian-garcia . I updated the PR now to use auth.authenticator.

atoulme pushed a commit that referenced this pull request Apr 29, 2025
…als` (#39738)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Doing this breaking change to prepare usage of azure auth extension and
be able to set the auth config like it's usually done for the different
authentication by extensions

```yaml
auth:
  authenticator: 'azureauth/prd'
```

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Unblocks #39658

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: Célian Garcia <[email protected]>
Copy link
Member

@celian-garcia celian-garcia left a comment

Choose a reason for hiding this comment

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

Great! just some nits and we should be good!
Thank you @constanca-m, I can't wait to remove all that crap 😈

@@ -242,11 +243,6 @@ type Config struct {
Cloud string `mapstructure:"cloud"`
SubscriptionIDs []string `mapstructure:"subscription_ids"`
DiscoverSubscriptions bool `mapstructure:"discover_subscriptions"`
Credentials string `mapstructure:"credentials"`
TenantID string `mapstructure:"tenant_id"`
Copy link
Member

Choose a reason for hiding this comment

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

Can you keep just TenantID at this place? Just a nit but this will be clearer when we'll remove the deprecated part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course

@edmocosta edmocosta added ready to merge Code review completed; ready to merge by maintainers and removed waiting for author labels May 9, 2025
@atoulme
Copy link
Contributor

atoulme commented May 9, 2025

Please resolve conflicts and mark ready for review again.

@atoulme atoulme marked this pull request as draft May 9, 2025 18:29
@atoulme atoulme removed the ready to merge Code review completed; ready to merge by maintainers label May 9, 2025
@constanca-m constanca-m marked this pull request as ready for review May 10, 2025 17:09
@atoulme atoulme merged commit 0f6f7e8 into open-telemetry:main May 14, 2025
173 checks passed
@github-actions github-actions bot added this to the next release milestone May 14, 2025
@constanca-m constanca-m deleted the azuremonitor-authextension branch May 14, 2025 22:27
seongpil0948 pushed a commit to seongpil0948/opentelemetry-collector-contrib that referenced this pull request May 16, 2025
…metry#39658)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Add support for extension `azureauth` for authentication.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#39048.

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tests added.

<!--Describe the documentation added.-->
#### Documentation

README updated.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Célian GARCIA <[email protected]>
Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 20, 2025
…als` (open-telemetry#39738)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Doing this breaking change to prepare usage of azure auth extension and
be able to set the auth config like it's usually done for the different
authentication by extensions

```yaml
auth:
  authenticator: 'azureauth/prd'
```

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Unblocks open-telemetry#39658

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: Célian Garcia <[email protected]>
johnleslie pushed a commit to johnleslie/opentelemetry-collector-contrib that referenced this pull request May 23, 2025
…metry#39658)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Add support for extension `azureauth` for authentication.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#39048.

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tests added.

<!--Describe the documentation added.-->
#### Documentation

README updated.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Célian GARCIA <[email protected]>
Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
johnleslie pushed a commit to johnleslie/opentelemetry-collector-contrib that referenced this pull request May 23, 2025
…metry#39658)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Add support for extension `azureauth` for authentication.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#39048.

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tests added.

<!--Describe the documentation added.-->
#### Documentation

README updated.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Célian GARCIA <[email protected]>
Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
dragonlord93 pushed a commit to dragonlord93/opentelemetry-collector-contrib that referenced this pull request May 23, 2025
…metry#39658)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Add support for extension `azureauth` for authentication.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#39048.

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tests added.

<!--Describe the documentation added.-->
#### Documentation

README updated.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Célian GARCIA <[email protected]>
Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
dd-jasminesun pushed a commit to DataDog/opentelemetry-collector-contrib that referenced this pull request Jun 23, 2025
…metry#39658)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Add support for extension `azureauth` for authentication.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#39048.

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tests added.

<!--Describe the documentation added.-->
#### Documentation

README updated.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Célian GARCIA <[email protected]>
Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[receiver/azuremonitor] Add support for azureauthextension
5 participants