Skip to content

FEAT: PyRIT Config#1343

Open
ValbuenaVC wants to merge 21 commits intoAzure:mainfrom
ValbuenaVC:pyrit-config
Open

FEAT: PyRIT Config#1343
ValbuenaVC wants to merge 21 commits intoAzure:mainfrom
ValbuenaVC:pyrit-config

Conversation

@ValbuenaVC
Copy link
Contributor

@ValbuenaVC ValbuenaVC commented Jan 31, 2026

Description

Adds a config as ~/.pyrit_conf (~/.pyrit_conf_example included in repo) which can be loaded in by a new ConfigurationLoader to both make initializing pyrit less verbose and also parameterize pyrit the same way across the CLI and GUI. Configuration file support for the CLI tools enables more complex setups that were not possible or cumbersome previously. New features:

  • Initializers with arguments specified in the config file, which was not possible previously with the CLI
  • Configuration file with same fields as our initialize_pyrit_async method(s)
  • Auto-loading of config file if it exists
  • Config precedence (default config file < explicit config file < individual CLI args)

Tests and Documentation

Added as tests/unit/setup/test_configuration_loader.py.

@ValbuenaVC ValbuenaVC changed the title Pyrit Config [DRAFT] FEAT PyRIT Config Jan 31, 2026
initializer_names: Optional[list[str]] = None,
env_files: Optional[list[Path]] = None,
log_level: str = "WARNING",
log_level: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort of orthogonal to your changes but why isn't that an actual log level, as in the type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. Should we keep it as a string or refactor to use the logging types? I'm not sure if there's a reason it's this way and not even something like Literal["WARNING", "INFO", ...]

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically they're numbers, see https://docs.python.org/3/library/logging.html#logging-levels

I would definitely suggest just using logging.INFO etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use int in latest commit

self._initializer_names = initializer_names
self._env_files = env_files
self._log_level = validate_log_level(log_level=log_level)
from pyrit.setup import ConfigurationLoader
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: top of the file

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be in the latest commit

Initialize PyRIT context.

Configuration is loaded in the following order (later values override earlier):
1. Default config file (~/.pyrit/.pyrit_conf) if it exists
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure to update devcontainer configuration to get that file into the devcontainer (if it isn't already).

Copy link
Contributor Author

@ValbuenaVC ValbuenaVC Feb 6, 2026

Choose a reason for hiding this comment

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

It should be by default, but an explicit check has been added to the devcontainer shell script, as well as explicit creation of .pyrit_conf from .pyrit_conf_example.

@ValbuenaVC ValbuenaVC changed the title [DRAFT] FEAT PyRIT Config [DRAFT] FEAT: PyRIT Config Feb 5, 2026
@ValbuenaVC ValbuenaVC changed the title [DRAFT] FEAT: PyRIT Config FEAT: PyRIT Config Feb 5, 2026
@ValbuenaVC ValbuenaVC marked this pull request as ready for review February 5, 2026 19:54

MYPY_CACHE="/workspace/.mypy_cache"
VIRTUAL_ENV="/opt/venv"
PYRIT_CONFIG_DIR="/home/vscode/.pyrit"
Copy link
Contributor

@rlundeen2 rlundeen2 Feb 6, 2026

Choose a reason for hiding this comment

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

Should this be ~/.pyrit?

Copy link
Contributor

Choose a reason for hiding this comment

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

In the devcontainer that is the home directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, but I guess wondering if using ~ is more generic for diff containers.

Copy link
Contributor Author

@ValbuenaVC ValbuenaVC Feb 6, 2026

Choose a reason for hiding this comment

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

In my experience this tends to fail given that ~ can alias to home for the root user during the build process. But I don't know enough about our Docker build pipeline to confirm it

PYRIT_CONFIG_FILE="$PYRIT_CONFIG_DIR/.pyrit_conf"

# Create the .pyrit config directory and copy example config if not exists
if [ ! -d "$PYRIT_CONFIG_DIR" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be nice to have someone else weigh in on this. I'm hesitant about auto copying things over like this though. @romanlutz who is working on docker things

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. What I would expect to happen is that my directory at ~/.pyrit shows up at ~/.pyrit inside the container which is /home/vscode/.pyrit.

What is the copying logic meant to copy? The example file? What would that be useful for?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now it's also copying over the example if the file doesn't exist which probably isn't useful like you mention.

Would it make sense to copy over ~/.pyrit directory? Including the .env files there?

Copy link
Contributor Author

@ValbuenaVC ValbuenaVC Feb 6, 2026

Choose a reason for hiding this comment

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

What would be the most intuitive way to handle discovery and population of the config file in the Docker image? I'm not sure I understand Roman's original request to make sure the file is in the devcontainer, since if the example file is in the git repo then when the Docker image clones and builds it should be included. Is there something I'm missing?

Copy link
Contributor Author

@ValbuenaVC ValbuenaVC Feb 6, 2026

Choose a reason for hiding this comment

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

I feel like we have two main options:

  1. Leave .pyrit_conf_example and ask users to create .pyrit_conf using it like we do with our .env file(s)
  2. Deliberately create a .pyrit_conf file with certain values from the example as a template.
    I'm in favor of the first given that it's more consistent with how we do environment variables but as I said I think I'm misunderstanding the premise

Copy link
Contributor

@rlundeen2 rlundeen2 left a comment

Choose a reason for hiding this comment

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

My only concerns are I want someone else to look at the docker setup :)

Everything else looks good!

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