Skip to content

Supporting WorkloadIdentity auth type - #519

Merged
Rodrigo Brandão (rodrigobr-msft) merged 5 commits into
mainfrom
users/robrandao/workload-identity
Aug 4, 2026
Merged

Supporting WorkloadIdentity auth type#519
Rodrigo Brandão (rodrigobr-msft) merged 5 commits into
mainfrom
users/robrandao/workload-identity

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request adds support for Workload Identity authentication by introducing a new workload_identity authentication type and handling federated token files. The main changes involve updating the authentication configuration to accept a federated token file and modifying the MSAL authentication logic to use this file when the new authentication type is selected.

Workload Identity Authentication Support

  • Added a new workload_identity value to the AuthTypes enum to represent the new authentication type.
  • Updated AgentAuthConfiguration to include a FEDERATED_TOKEN_FILE field and accept it during initialization, allowing configuration of the federated token file path. [1] [2] [3]

MSAL Authentication Logic

  • Modified the MSAL authentication flow to handle the workload_identity type: reads the federated token from the configured file and uses it as the client assertion for authentication. Raises a clear error if the federated token file is not set.

Copilot AI lite review requested due to automatic review settings August 4, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The new workload identity token-file assertion logic should defensively strip/validate file contents and provide clearer read errors, and the new config alias should be excluded from provider_settings per existing conventions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR adds Workload Identity authentication support to the Microsoft 365 Agents SDK for Python by introducing a new workload_identity auth type, extending auth configuration to accept a federated token file path, and updating the MSAL auth flow to use that token as a client assertion.

Changes:

  • Added workload_identity to AuthTypes.
  • Extended AgentAuthConfiguration with FEDERATED_TOKEN_FILE / federated_token_file initialization support.
  • Updated MSAL client creation to read a federated token file and use it for client_assertion when AUTH_TYPE is workload_identity.
File summaries
File Description
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/auth_types.py Adds the new workload_identity auth type enum value.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/agent_auth_configuration.py Adds configuration support for a federated token file path used by workload identity.
libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py Implements workload identity MSAL client_assertion creation by reading the federated token file.
Review details

Suppressed comments (1)

libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py:290

  • The federated token file is read verbatim and may include trailing newlines/whitespace; that would change the JWT string and can cause assertion auth to fail. Also, if the file can’t be read, the current error will be an unhelpful FileNotFoundError/OSError. Consider stripping the token and raising a clearer ValueError that includes the configured path.
                if not self._msal_configuration.FEDERATED_TOKEN_FILE:
                    raise ValueError(
                        "FEDERATED_TOKEN_FILE must be set in configuration."
                    )

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@rodrigobr-msft Rodrigo Brandão (rodrigobr-msft) changed the title Workload identity support Supporting WorkloadIdentity auth type Aug 4, 2026
Copilot AI review requested due to automatic review settings August 4, 2026 17:16
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) marked this pull request as ready for review August 4, 2026 17:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The workload identity token file should be read defensively (at least stripping whitespace) and the new configuration field should be reflected in the configuration docstring for discoverability.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py:296

  • The workload identity client_assertion reads the token file verbatim, so any trailing newline/whitespace in the projected file will be included in the assertion string. That can result in an invalid JWT being sent to Entra; it’s safer to read as text and strip surrounding whitespace before returning it.
                federated_token_file = self._msal_configuration.FEDERATED_TOKEN_FILE

                def get_assertion() -> str:
                    with open(federated_token_file, "rb") as f:
                        return f.read().decode("utf-8")

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/agent_auth_configuration.py:101

  • AgentAuthConfiguration’s docstring lists the supported configuration fields, but the newly introduced FEDERATED_TOKEN_FILE field isn’t documented there. This makes the configuration surface harder to discover for consumers.
    AZURE_REGION: str | None
    IDPM_RESOURCE: str | None
    ANONYMOUS_ALLOWED: bool = False
    VALIDATE_ISSUER: bool = False
    FEDERATED_TOKEN_FILE: str | None
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 4, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

There are functional issues in auth-type normalization and token-file assertion parsing that can prevent Workload Identity from working when configured via env-style keys.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/agent_auth_configuration.py:138

  • AUTH_TYPE is assigned directly from kwargs["AUTHTYPE"], which is typically a string (e.g. "WorkloadIdentity"). That leaves AUTH_TYPE as a plain str, so comparisons like AUTH_TYPE == AuthTypes.workload_identity will fail and the Workload Identity branch in MSAL auth won’t execute when configured via env-style keys.
        federated_token_file: str | None = None,
        **kwargs: Any,
    ):

        self.AUTH_TYPE = auth_type or kwargs.get("AUTHTYPE", AuthTypes.client_secret)

libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py:295

  • The projected federated token file commonly ends with a trailing newline. Returning the raw file contents (including whitespace) can break client assertion parsing. Read as text and strip surrounding whitespace/newlines before returning the assertion.
                federated_token_file = self._msal_configuration.FEDERATED_TOKEN_FILE

                def get_assertion() -> str:
                    with open(federated_token_file, "rb") as f:
                        return f.read().decode("utf-8")
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 4, 2026 17:33
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit afb2433 into main Aug 4, 2026
11 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/workload-identity branch August 4, 2026 17:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

There are correctness/documentation gaps around the Workload Identity token-file handling that should be addressed to avoid misconfiguration and hard-to-diagnose runtime failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/agent_auth_configuration.py:86

  • The docstring describes FEDERATED_TOKEN_FILE as being for "federated credentials authentication", but this field is actually consumed by the new AuthTypes.workload_identity path (msal_auth.py). This mismatch can mislead users configuring Workload Identity.
    ANONYMOUS_ALLOWED: Whether anonymous access is allowed (default False).
    FEDERATED_TOKEN_FILE: The path to the federated token file (if using federated credentials authentication).

libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py:295

  • get_assertion() reads and strips the federated token file, but it can return an empty string if the file is empty/whitespace-only, which will cause downstream MSAL/AAD failures that are harder to diagnose. Consider validating that the read token is non-empty and raising a clear error (and optionally wrapping file I/O errors) before returning it.
                federated_token_file = self._msal_configuration.FEDERATED_TOKEN_FILE

                def get_assertion() -> str:
                    with open(federated_token_file, encoding="utf-8") as f:
                        return f.read().strip()
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

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.

Add workload identity as an authentication option

3 participants