FIX replace api key in scenarios#1435
Merged
hannahwestra25 merged 2 commits intomicrosoft:mainfrom Mar 3, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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")withapi_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 redundantos.environ.get()calls. - Renamed the
GNetworkX graph variable togin1_anecdoctor_generator.py(and its.ipynbpair), 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 G → g for PEP8 compliance |
doc/code/executor/promptgen/1_anecdoctor_generator.ipynb |
Notebook sync of G → g rename |
romanlutz
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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