Skip to content

Conversation

@juskeeratanand
Copy link

@juskeeratanand juskeeratanand commented Sep 25, 2025

This PR implements the work done here to add the ability to authenticate against AWS in the python client.

This is done by the client using AWS credentials to sign a request to GetCallerIdentity and then sending that signed proof to Datadog for validation. Read more about this process here. In this PR, we add the proof generation to the datadog client and add the ability to pass that token on subsequent requests.

@juskeeratanand juskeeratanand changed the title changed template files + generate [DELA-208] Adding delegated token authentication in python client Sep 25, 2025
@juskeeratanand juskeeratanand marked this pull request as ready for review September 29, 2025 20:27
@juskeeratanand juskeeratanand requested review from a team as code owners September 29, 2025 20:27
@juskeeratanand juskeeratanand requested a review from a team September 29, 2025 20:47
@juskeeratanand juskeeratanand marked this pull request as draft September 30, 2025 17:33
@juskeeratanand juskeeratanand marked this pull request as ready for review September 30, 2025 18:28
Copy link

@urnfdog urnfdog left a comment

Choose a reason for hiding this comment

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

WIP, just a couple comments.

:param headers: Header parameters dict to be updated.
:raises: ApiValueError if delegated token authentication fails
"""
from datetime import datetime
Copy link

Choose a reason for hiding this comment

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

Thought: Is this necessary, or can it be rolled up into a more global import?

:return: User agent string
"""
import platform
Copy link

Choose a reason for hiding this comment

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

Thought: Do we need this import at the function level?

Comment on lines 465 to 467
# Check if we have cached credentials
if not hasattr(self.configuration, "_delegated_token_credentials"):
self.configuration._delegated_token_credentials = None
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Check if we have cached credentials
if not hasattr(self.configuration, "_delegated_token_credentials"):
self.configuration._delegated_token_credentials = None

Looks like this variable is already initialized as None.

Comment on lines 347 to 350
# Delegated token configuration
self.delegated_token_config = None

# Load default values from environment
Copy link
Member

Choose a reason for hiding this comment

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

Looks like constructors are missing in the config for fields such as delegated_auth_provider and delegated_auth_org_uuid

Comment on lines 475 to 479
config = DelegatedTokenConfig(
org_uuid=self.configuration.delegated_auth_org_uuid,
provider="aws", # This could be made configurable
provider_auth=self.configuration.delegated_auth_provider,
)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure how often the token refreshes but we should move this up to class initialization as it seems to be a static config for the most part.

url = get_delegated_token_url(config)

# Create REST client
rest_client = rest.RESTClientObject(config)
Copy link
Member

Choose a reason for hiding this comment

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

Can we pass the rest client initialized in the api_client? If not we should initialize this once and store it for future use

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Oct 22, 2025
@juskeeratanand juskeeratanand marked this pull request as draft October 22, 2025 17:05
@juskeeratanand juskeeratanand marked this pull request as ready for review October 23, 2025 15:05
@DataDog DataDog deleted a comment from chatgpt-codex-connector bot Oct 23, 2025
Copy link

@urnfdog urnfdog left a comment

Choose a reason for hiding this comment

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

I'm assuming that signing mechanisms (especially HMAC) are all taken directly from AWS specs

"""
try:
token_response = json.loads(response_data)
except json.JSONDecodeError as e:
Copy link

Choose a reason for hiding this comment

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

💭 Do we need to catch other kinds of errors here, and is there a reason we handle JSONDecodeError specifically?

Comment on lines +887 to +888
if auth_setting["in"] == "header":
if auth_setting["type"] != "http-signature":
Copy link

Choose a reason for hiding this comment

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

Nit:

Suggested change
if auth_setting["in"] == "header":
if auth_setting["type"] != "http-signature":
if auth_setting["in"] == "header" && auth_setting["type"] != "http-signature":

# Use regular authentication
for auth in self.settings["auth"]:
auth_setting = self.api_client.configuration.auth_settings().get(auth)
if auth_setting:
Copy link

Choose a reason for hiding this comment

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

Nit: Can make this a guard clause if we want to avoid one level of nesting. But not necessary.

Suggested change
if auth_setting:
if not auth_setting:
continue

"""
try:
token_response = json.loads(response_data)
except json.JSONDecodeError as e:
Copy link

Choose a reason for hiding this comment

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

Similar question around if we need to handle other types of errors

Comment on lines +130 to +132
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
"AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"AWS_SESSION_TOKEN": "test-session-token",
Copy link

Choose a reason for hiding this comment

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

Note: These are the example access key values from AWS docs, including GetAccessKeyInfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants