You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make api_key and identity auth modes disjoint by deprecating the implicit Entra fallback #3029
api_key authentication mode can currently resolve to identity. The chain in pyrit/auth/openai_auth.py::resolve_openai_auth is:
token-provider callable passed as api_key
explicit api_key string
the target's API key environment variable
fallback: an Entra token, for recognized Azure endpoints only
Step 4 is why "no api_key passed" was ambiguous in the first place — it can mean "the user chose identity" or "no key is available, mint a token." #3010 fixed the user-facing symptom by adding an explicit auth_mode, but left the underlying fallback in place for backward compatibility, so the two modes still overlap rather than being disjoint.
The same inlined chain exists in AzureMLChatTarget and PromptShieldTarget.
Describe the solution you'd like
Make the two modes disjoint:
auth_mode="api_key" requires a key or an explicitly supplied token provider, and fails clearly when neither is present. No implicit identity fallback.
This is a breaking change: OpenAIChatTarget(endpoint=<azure endpoint>) with no key plus az login works silently today and is documented that way, so it should go through a deprecation cycle rather than being removed outright:
One release emitting a DeprecationWarning when the implicit fallback is taken, naming auth_mode="identity" as the replacement.
Removal in the following release, called out in the release notes and migration guidance.
Two cleanups land with this:
TargetService._accepts_auth_mode can be deleted. It exists solely because AzureBlobStorageTarget has no auth_mode parameter; once every identity-advertising target accepts the explicit mode, a target that cannot meet that contract should fail loudly instead of being quietly skipped. This is blocked on FEAT: Add custom params to new targets in CoPYRIT #2846, which adds explicit auth-mode support to AzureBlobStorageTarget.
doc/code/setup/1_configuration.py / .ipynb and the per-target notebooks that describe keyless Azure auth need updating.
Describe alternatives you've considered, if relevant
Add an explicit auto mode that keeps today's chain, leaving api_key and identity strict. Preserves the behavior under an honest name, but adds a third mode to document and reason about; only worth it if the keyless path turns out to be widely depended upon.
Additional context
Ordering: this should land after #2846, which supplies the AzureBlobStorageTarget half and unblocks removing _accepts_auth_mode. #2846 and #3010 also introduce two overlapping mechanisms for the same concern (a per-class get_auth_mode_parameters hook vs. an explicit auth_mode constructor argument); reconciling those into one belongs in the same pass.
Related: #3010, #2846, #2235 (which introduced the fallback — correctly, for its original purpose as a last resort when no key exists).
Is your feature request related to a problem? Please describe.
Follow-up to review feedback on #3010 (thread).
api_keyauthentication mode can currently resolve to identity. The chain inpyrit/auth/openai_auth.py::resolve_openai_authis:api_keyapi_keystringStep 4 is why "no api_key passed" was ambiguous in the first place — it can mean "the user chose identity" or "no key is available, mint a token." #3010 fixed the user-facing symptom by adding an explicit
auth_mode, but left the underlying fallback in place for backward compatibility, so the two modes still overlap rather than being disjoint.The same inlined chain exists in
AzureMLChatTargetandPromptShieldTarget.Describe the solution you'd like
Make the two modes disjoint:
auth_mode="api_key"requires a key or an explicitly supplied token provider, and fails clearly when neither is present. No implicit identity fallback.auth_mode="identity"uses identity and ignores keys (already true as of FIX: Make auth mode an explicit choice instead of an inferred one #3010).This is a breaking change:
OpenAIChatTarget(endpoint=<azure endpoint>)with no key plusaz loginworks silently today and is documented that way, so it should go through a deprecation cycle rather than being removed outright:DeprecationWarningwhen the implicit fallback is taken, namingauth_mode="identity"as the replacement.Two cleanups land with this:
TargetService._accepts_auth_modecan be deleted. It exists solely becauseAzureBlobStorageTargethas noauth_modeparameter; once every identity-advertising target accepts the explicit mode, a target that cannot meet that contract should fail loudly instead of being quietly skipped. This is blocked on FEAT: Add custom params to new targets in CoPYRIT #2846, which adds explicit auth-mode support toAzureBlobStorageTarget.doc/code/setup/1_configuration.py/.ipynband the per-target notebooks that describe keyless Azure auth need updating.Describe alternatives you've considered, if relevant
api_keymode able to silently produce identity auth, which is the ambiguity FIX: Make auth mode an explicit choice instead of an inferred one #3010 set out to remove.automode that keeps today's chain, leavingapi_keyandidentitystrict. Preserves the behavior under an honest name, but adds a third mode to document and reason about; only worth it if the keyless path turns out to be widely depended upon.Additional context
Ordering: this should land after #2846, which supplies the
AzureBlobStorageTargethalf and unblocks removing_accepts_auth_mode. #2846 and #3010 also introduce two overlapping mechanisms for the same concern (a per-classget_auth_mode_parametershook vs. an explicitauth_modeconstructor argument); reconciling those into one belongs in the same pass.Related: #3010, #2846, #2235 (which introduced the fallback — correctly, for its original purpose as a last resort when no key exists).