Skip to content

FIX replace api key in scenarios#1435

Merged
hannahwestra25 merged 2 commits intomicrosoft:mainfrom
hannahwestra25:hawestra/update_api_key_scenarios
Mar 3, 2026
Merged

FIX replace api key in scenarios#1435
hannahwestra25 merged 2 commits intomicrosoft:mainfrom
hannahwestra25:hawestra/update_api_key_scenarios

Conversation

@hannahwestra25
Copy link
Copy Markdown
Contributor

Description

related to https://github.com/Azure/PyRIT/pull/1404/changes#diff-442e236a7a76cf9158b71263202359f1287cd07557b1a5467fe5c2719c891bf0
Removes API key (local auth) dependencies for all Azure Cognitive Services targets in scenarios and in favor of Entra ID (Azure AD) token-based authentication.

Tests and Documentation

Copilot AI review requested due to automatic review settings March 3, 2026 17:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes API key authentication dependencies from Azure Cognitive Services targets in PyRIT scenario files, replacing direct os.environ.get("AZURE_OPENAI_GPT4O_UNSAFE_CHAT_KEY") calls with get_azure_openai_auth(endpoint) to enable Entra ID (Azure AD) token-based authentication. This is a follow-on to PR #1404 which made the same change in initializers and notebooks.

Changes:

  • Replaced api_key=os.environ.get("..._KEY") with api_key=get_azure_openai_auth(endpoint) in six AIRT scenario files and one Foundry scenario file, caching the endpoint in a local variable to avoid redundant os.environ.get() calls.
  • Renamed the G NetworkX graph variable to g in 1_anecdoctor_generator.py (and its .ipynb pair), aligning with PEP8 lowercase variable naming.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pyrit/scenario/scenarios/foundry/red_team_agent.py Replaces API key with get_azure_openai_auth for adversarial target and default scoring config; imports from submodule path instead of package root
pyrit/scenario/scenarios/airt/scam.py Replaces API key with get_azure_openai_auth in objective scorer and adversarial target methods; imports from submodule path
pyrit/scenario/scenarios/airt/psychosocial_scenario.py Replaces API key with get_azure_openai_auth in adversarial target and scorer; imports from submodule path
pyrit/scenario/scenarios/airt/leakage_scenario.py Replaces API key with get_azure_openai_auth in default objective scorer and adversarial target; imports from submodule path
pyrit/scenario/scenarios/airt/jailbreak.py Replaces API key with get_azure_openai_auth in default scorer and adversarial target; imports from submodule path
pyrit/scenario/scenarios/airt/cyber.py Replaces API key with get_azure_openai_auth; correctly imports from pyrit.auth package root
pyrit/scenario/scenarios/airt/content_harms.py Replaces API key with get_azure_openai_auth in default adversarial target and scorer; imports from submodule path
doc/code/executor/promptgen/1_anecdoctor_generator.py Renames graph variable Gg for PEP8 compliance
doc/code/executor/promptgen/1_anecdoctor_generator.ipynb Notebook sync of Gg rename

@hannahwestra25 hannahwestra25 merged commit 769bb24 into microsoft:main Mar 3, 2026
38 checks passed
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