Skip to content

FEAT: Let users pick a server credential for a target (part 19) - #4070

Open
varunj-msft wants to merge 357 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Server-Credentials
Open

varunj-msft wants to merge 357 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Server-Credentials

Conversation

@varunj-msft

@varunj-msft varunj-msft commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part 19 of saving Registry entries across restarts. A side branch stacked on part 9 (#4027); part 17 (#3984), which it also builds on, is merged. Nothing builds on it. This PR's own changes: varunj-msft/PyRIT@varunj-msft/13178-Save-From-Registry...varunj-msft/13178-Server-Credentials

Design: 4.4 Credentials, 5. How an admin sets up credentials. Where every part fits: PR map.

This is one of the changes for saving Registry entries across restarts. Until the earlier PRs merge, the diff here also shows their changes.

A saved target can't hold a key, so a target that needs an API key could only be Temporary. An administrator can now list keys from the server's environment that users pick by name, each tied to the only endpoint it is sent to.

  • .pyrit_conf takes server_credentials: a list of entries with a name users pick, the env_var that holds the key, and the endpoint the key is sent to. Each name can be listed once. The endpoint must be a full http(s) address with no user name, password, query or fragment.
  • GET /api/targets/types lists each credential's name and endpoint for the types that can use one (the OpenAI targets for now), never the variable or the key.
  • POST /api/targets takes "server_credential": "<name>" with auth_mode api_key and no api_key of its own, and not with source (422 otherwise). The key is used only when the target's endpoint is the credential's endpoint, compared with the scheme and host lowercased and a default port and trailing slash removed. A credential that isn't listed or set, or another endpoint, gets a 400.
  • A saved target stores the credential's name, never the key, and reads the key again at every start, so a rotated value takes effect at the next start. Restore refuses a saved target whose credential is no longer listed or set.
  • The New Target dialog offers Server credential as an authentication choice when the type has one. Picking one sets the endpoint to the credential's endpoint, read-only, sends the name with no key, and lets the target be saved. The dialog's saveability check sends the picked credential too, so it answers as the save would.
  • .pyrit_conf_example, doc/getting_started/pyrit_conf.md, the backend README and the GUI doc describe the setting. They say to list a variable that holds only that key: a variable a target reads on its own, such as OPENAI_CHAT_KEY, can still reach any endpoint through a Temporary target created without a key.

What stays the same: without server_credentials in .pyrit_conf, nothing changes; the types list has empty lists and the dialog offers no new choice. A typed key still makes a Temporary target, and a Temporary target without a key still uses this server's own key variable, as the backend README describes.

Screenshots: the New Target dialog with Server credential chosen, and the saved target in the Targets table.
credentials_1_new_target_server_credential
credentials_2_saved_target_row

Not covered:

The dialog asks for a registry name and suggests one, saves the target by
default, and creates a Temporary target only when it can't be saved, saying
why before it is created. The Targets table labels each target Saved, From
configuration or Temporary.
# Conflicts:
#	pyrit/registry/registry_recipe_restore.py
# Conflicts:
#	tests/unit/registry/test_instance_registry.py
# Conflicts:
#	pyrit/backend/services/runtime_lifecycle.py
#	tests/unit/backend/test_runtime_lifecycle.py
# Conflicts:
#	pyrit/setup/initializers/tools.py
#	tests/unit/backend/test_scenario_run_service.py
#	tests/unit/backend/test_scenario_suite_execution_service.py
#	tests/unit/registry/test_attack_technique_registry.py
#	tests/unit/registry/test_instance_registry.py
#	tests/unit/registry/test_registry_recipe_restore.py
create_named_instance checks the name before it builds, and the technique
registry checks names case-insensitively before it registers. Both raised the
duplicate-name error without recording the clash, so a launch script that
caught either one could still leave a saved entry in place of its own. The name
check now records the clash itself, as register already did, and the technique
check records it too.
# Conflicts:
#	tests/unit/registry/test_registry_recipe_restore.py
The dialog keeps the type's own reasons from the type list and gets the rest from POST /api/targets/saveability,
which runs create's checks and the library's save checks without building or saving anything, so the warning and
the save share one policy. The Entra ID endpoint message shows on the Endpoint URL field after it loses focus.
Saved-entry storage failures now pass their traceback through redact_urls, and code scanning flags the scheme pattern
as slow on a long run of letters. A scheme is short, so bounding it keeps the match linear.
… a saveability answer once its request goes away

The private-target test now controls the debounce clock, so a slow run can't check the values chosen before Only me.

This branch has not been deployed

No deployments
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