Connecting pyrit_scan and pyrit_shell to a remote CoPyRIT backend

Point the PyRIT CLI at a shared CoPyRIT server using a config file, Entra device-code sign-in and an encrypted token cache, and avoid the broader permissions that come with Azure CLI token mode.

On this page

Why teams connect pyrit_scan to a shared CoPyRIT backend

A red team that runs pyrit_scan from individual laptops or a CI pipeline ends up with results scattered across machines, each one holding its own memory store. Pointing the CLI at a shared CoPyRIT server solves that by sending scan activity to one backend that the whole team can query. The connection is set in a config file through a server url and an auth_mode value, so the scanner runs as before while its results land where the team reviews them. It is the command-line counterpart to the CoPyRIT web GUI, which human testers use for interactive work. Both point at the same backend, so a scripted scan and a manual session can appear in one shared record.

The decision behind this connection is less about the scanner and more about two questions: who is allowed to run scans against the backend, and where the results must live. Connecting the CLI means every scan is tied to a signed-in identity rather than to whoever holds a shared secret, which makes the access rules and audit trail of the backend apply to CLI activity as well. Teams with a shared backend should confirm which Entra ID group gates CLI access, whether scans from CI use an interactive sign-in or a different credential path, and whether the backend's memory store is the system of record for findings. If results are meant to stay on a workstation for a single tester, a local setup may fit better, and the answer should be settled before scripts are written against a remote URL.

The auth mode matters for that identity decision. The default automatic mode uses a device-code sign-in with the Microsoft Graph User.Read scope and keeps an encrypted, persistent token cache, so a tester signs in once and the CLI reuses the token. The azure_cli mode is an explicit compatibility option, and its Graph token can carry permissions beyond User.Read, which is why the PyRIT documentation prefers device-code authentication. Before rollout, confirm the scopes your tenant will grant, check how long cached tokens persist on shared or CI hosts, and document which mode each team member and pipeline uses so access reviews can account for them. The PyRIT Scanner documentation sets out the exact config keys and sign-in steps.

How a CLI request reaches the shared backend

A request starts on the operator's workstation, where pyrit_scan or pyrit_shell reads the server URL and auth_mode from the config file. In automatic mode the CLI runs an Entra device-code sign-in with the Microsoft Graph User.Read scope and stores the resulting token in an encrypted persistent cache on the workstation. The trust boundary sits at the HTTPS call to the CoPyRIT backend, where Entra ID group membership gates access before any request reaches the shared memory store. Check that the token cache stays on the operator's machine and that the backend's group gating is in place before a team relies on it.

Request path from the operator workstation through Entra ID to the shared backend.

Auth mode options and when each fits

This table compares the two sign-in modes the PyRIT CLI offers for a remote CoPyRIT backend: automatic device-code mode and the azure_cli compatibility mode. Read each row against your own identity setup, since the token scope and cache behavior determine what the CLI can reach and how sign-in is handled on shared workstations. The main takeaway is that device-code sign-in is the documented default, and azure_cli should be used only when you can name the reason and accept its wider token.

OptionHow it signs inToken scopeWhen it fitsMain trade-off
Automatic mode (device code)Entra device code sign-in, with the user completing the prompt in a browserMicrosoft Graph User.ReadDefault for most users connecting pyrit_scan or pyrit_shell to a shared CoPyRIT serverUser must complete the device code prompt, and the token cache must be protected on each workstation
Encrypted persistent token cacheToken is stored encrypted on the local machine after sign-inSame as automatic mode, User.ReadEngineers who run the CLI repeatedly and want fewer sign-in promptsCache lives on the workstation, so device hygiene and account offboarding must cover it
azure_cli compatibility modeReuses the token from an existing Azure CLI sessionGraph token may carry permissions beyond User.ReadOnly where device code cannot be used and the team has reviewed the broader tokenToken can carry more permissions than the CLI needs, and the docs prefer device-code authentication
Choosing the mode in the config fileSet the auth_mode key alongside the server urlDepends on the selected modePinning one mode per team so every engineer connects the same wayMixed modes across workstations make support and access reviews harder to follow

Configuring the CLI to reach the shared server

This sequence installs PyRIT, points the CLI at the shared CoPyRIT backend through a config file, and completes a first device-code sign-in. The result is a working CLI session that the server accepts for your account.

  1. Confirm the Python version and install PyRIT

    Check that the workstation runs a Python version the PyPI package supports, which is 3.10 up to but not including 3.15. The PyRIT documentation recommends Python 3.13. Create a virtual environment and install the package with pip so that the pyrit_scan and pyrit_shell commands are available inside it. Run the version check and confirm that pyrit_scan --help prints usage without errors. If the command is not found, the environment is not active or the install did not complete, so repeat the install before moving on.

  2. Request the server URL and group access from the platform owner

    Before editing any file, ask the platform owner for the exact server URL of the CoPyRIT backend that your team uses. Also ask which Entra ID group grants access to that instance and whether a separate admin group applies to your role. Do not guess the URL from a deployment name, since separate team instances can have different addresses. Record the answers in your notes. This step is complete when you hold a written URL and the name of the group your account must belong to.

  3. Create the config file with automatic authentication

    Create the PyRIT configuration file that the CLI reads and set the server URL and auth_mode to automatic. Use the key names shown in the PyRIT Scanner documentation, and keep the file in the user profile location PyRIT already reads for its settings. Do not put tokens, client secrets or passwords in this file. Check the result by printing the file back and confirming that the URL matches the value from the platform owner exactly, including the scheme and any path.

  4. Run a first scan to start device-code sign-in

    Run a small pyrit_scan command against the shared backend. The CLI requests an Entra device code with the Microsoft Graph User.Read scope and prints a code and a sign-in address. Open the address in a browser, enter the code, and sign in with your organizational account. Complete any multi-factor prompt your tenant requires. The step is done when the terminal reports that authentication succeeded and the scan begins or returns a response from the backend rather than a sign-in error.

  5. Confirm the encrypted token cache exists

    After sign-in, check that the CLI created a persistent token cache in the PyRIT user directory. The documentation states that the cache is encrypted. Confirm that the file exists and that its contents are not readable as plain JSON or as a readable token string. Run the scan a second time without signing in again to confirm the cached token is reused. If the CLI prompts for sign-in on every run, the cache is not persisting, so check directory permissions and the file location before going further.

  6. Verify backend reachability and group membership

    Run a read-only check against the backend, such as the command the platform owner names for a health or status request, or the first pyrit_shell command that lists available targets. A successful response shows the CLI reaches the server and that the token is accepted. If the response is a 401 or 403, confirm with the platform owner that your account is in the allowed group, that the group is assigned to the application, and whether the Graph permission on the backend covers your sign-in. Do not share the token cache to work around an access error.

  7. Confirm admin access separately if needed

    Only run configuration or admin operations if your role was granted the separate admin group. Ask the platform owner to confirm in writing which commands require that group and whether your account is a member. Attempt one admin-only action in a test context and expect a denial if you are not a member. This step is done when you know which commands your account can run and the platform owner has confirmed the group mapping for your role.

Why device-code sign-in beats Azure CLI token mode

The device-code flow is the preferred sign-in method for the PyRIT CLI because the azure_cli auth mode is an explicit compatibility mode, not a default. When auth_mode is set to azure_cli, the CLI reuses the token that the Azure CLI already holds. The Microsoft Graph token obtained that way can carry permissions beyond the User.Read scope that automatic mode requests. The PyRIT documentation therefore prefers device-code authentication, which requests only User.Read and stores the result in an encrypted persistent token cache. Read the current scanner documentation at the PyRIT Scanner page before you choose a mode, and confirm what each mode requests in your own tenant.

The practical risk is over-broad tokens on shared machines. A developer workstation, a jump host or a CI runner that already has an Azure CLI session may let any process running as that user, or any pipeline step, pick up a Graph token with more rights than CoPyRIT needs. The scope of that token is set by the Azure CLI login and the consent granted to it, not by the PyRIT config file, so a team can believe it has least privilege while the CLI is using something broader. Before you enable azure_cli anywhere, check which account and consent the Azure CLI is using on that host, remove stale sessions from shared runners, and keep CI secrets for CoPyRIT separate from any interactive Azure CLI login.

The compatibility mode still has a place when device-code sign-in cannot run. Some hosts cannot complete an interactive prompt, and some existing automation was built around an Azure CLI login that already exists. In those cases, the team should document why azure_cli is needed, limit it to a dedicated service identity or a single-purpose runner, and confirm with the CoPyRIT owner which Graph permissions that identity holds. Ask your tenant administrator to review the consent granted to the Azure CLI application, and check that the group membership controlling CoPyRIT access still applies to the identity that signs in.

Security considerations for remote CLI access

A CLI connection to a shared CoPyRIT server puts a token cache, a config file and a sign-in flow on the machine running pyrit_scan or pyrit_shell. The cards below separate what the client protects from what the backend must enforce, and what your team has to confirm in its own environment.

Encrypted token cache on shared hosts

With automatic mode, the CLI keeps a persistent, encrypted token cache so users do not sign in on every run. On a shared jump host or build server, anyone with access to the same operating system account may be able to reach the cache file. Confirm where the cache is stored for your platform, which accounts can read that location, and whether a sign-out or cache clear step is part of your offboarding for shared machines.

PyRIT Scanner docs

Least-privilege Graph scope

Automatic mode requests the Microsoft Graph User.Read scope through the Entra device code flow. That scope is narrow compared with the broader token carried by azure_cli mode. Review the app registration and consent settings for the CLI sign-in so that users do not gain extra Graph permissions through the client, and confirm that your tenant policy matches what the documentation describes.

Group gating enforced by the backend

Access to CoPyRIT is decided by the server, which checks the caller against the allowed Entra groups. A config file on the client can point to the right server, but editing it cannot grant membership. Test this directly: sign in as a user outside the allowed group, confirm the backend refuses the request, and confirm that admin configuration routes stay blocked for users outside the admin group.

Config file and credentials in ~/.pyrit

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf, so a shared home directory or copied profile can expose the server URL, auth mode and any secrets stored there. Set file permissions so only the owning user can read them, keep API keys out of shared configuration templates, and check that version control and CI logs do not capture these files.

Revoking access when people leave

Removing someone from the allowed Entra group blocks new server requests, but any cached token on a laptop or runner stays on that machine until it expires or is cleared. Build offboarding steps that remove group membership, clear the CLI token cache, and delete copies of ~/.pyrit on personal or shared devices. Ask your identity team how long issued tokens remain usable after group removal in your tenant.

Keeping CI runners off interactive sign-in

Device-code sign-in needs a person at a browser, so it does not fit unattended pipelines. Keep scheduled or CI runs on a dedicated identity with its own group membership, and do not place a personal token cache on a shared runner image. Confirm with your platform team which non-interactive method your runners will use and that its credentials are scoped, rotated and stored in your secrets manager.

Questions teams ask before connecting the CLI

Can our team connect pyrit_scan to a shared CoPyRIT server without outside help?

Yes, if your team already runs PyRIT and has someone comfortable with Python environments, configuration files and Microsoft Entra ID sign-in. The work is a local config file that sets the server URL and auth mode, followed by a device-code sign-in that stores an encrypted token cache on the workstation. The harder part is usually not the CLI itself but the surrounding decisions: which Entra app registration the backend trusts, which groups can reach the server, and who owns the config template across the team. If those are already settled, an internal engineer can usually complete the connection. If they are not, expect the identity and server decisions to take more time than the CLI change. Confirm the exact steps against the PyRIT Scanner documentation for your version.

What effort does the CLI connection take, and what drives it up?

The CLI step itself is small. Effort rises with the number of people and machines involved, the state of your identity setup, and how many backends your team needs to reach. The main drivers are:

  • Whether the Entra tenant, client and allowed group IDs for the CoPyRIT backend are already documented and stable
  • How many workstations need the config file, and whether a shared template exists
  • Whether your security team requires a review of token caching on laptops before users sign in
  • How many separate CoPyRIT instances the team uses, since each may need its own URL and sign-in

Costs come from internal staff time or from a fixed-scope engagement agreed in writing. Ask any partner for a quote that lists each of these drivers separately.

What do we need from the identity team before users can sign in?

You need the identity team to confirm the Entra app registration that CoPyRIT uses, the tenant and client identifiers that go into the config, and the group identifiers that decide who may use the scanner. Device-code sign-in requests the Microsoft Graph User.Read scope, so the identity team should confirm that the tenant allows users to consent to that scope and that the backend's app registration is configured for device-code flow. They should also confirm how access is removed when someone leaves the team, because the token cache lives on each workstation. Ask them to review the group model in the CoPyRIT access documentation before rollout rather than after the first sign-in failure.

How is connecting the CLI different from running CoPyRIT locally?

A local CoPyRIT run starts the backend on one workstation for one red teamer, so there is no shared server and no remote sign-in. Connecting the CLI to a remote backend means the CLI sends requests to a server that other people use, so identity, access groups and network exposure become part of the design. The shared server also holds shared memory and results, which makes who-can-see-what a real question. Local mode is simpler to start but cannot give a team a common record of attacks and findings. Read the local-mode guidance before choosing, because a local server must not be exposed to the network.

Can CI pipelines sign in to a remote CoPyRIT backend?

Device-code sign-in expects a person to complete a browser step, so it is designed for interactive workstation use. A pipeline that needs to run pyrit_scan unattended will need a different sign-in design, and your identity team should decide that design before anyone builds it. Confirm with the PyRIT Scanner documentation which auth modes are supported for non-interactive use in your version, and treat any unattended credential as a secret that needs rotation, storage and an owner. Do not assume that a workstation token cache can be copied to a runner.

What breaks if we use the azure_cli auth mode?

The azure_cli mode is an explicit compatibility option, and the documentation prefers device-code authentication for good reason. Its Graph token can carry permissions beyond User.Read, which means a user may hold broader access than the scanner needs. That widens what a compromised laptop or a misconfigured session can do, and it can complicate an access review because the effective permissions depend on the Azure CLI session rather than the scanner's documented scope. Teams that already use azure_cli for other work should test which permissions the token carries before they rely on it. If your security team asks for least privilege, device-code mode is the easier position to defend.

How does DeployOpen scope work on CoPyRIT connections?

DeployOpen scopes this work in writing before it starts. A typical written scope lists the PyRIT and CoPyRIT versions in use, the server URLs and auth modes to configure, the Entra artifacts the identity team must supply, the workstations or groups in scope, and the verification steps that show each user can sign in and that unauthorized users cannot. It also states what is excluded, such as CI sign-in design or changes to the backend itself. DeployOpen plans, implements, documents and supports self-hosted open-source platforms in infrastructure you control, and runs security testing that can be included if you want the setup reviewed. Ask for a quote that follows from that written scope.

Limits to confirm in your environment

The CLI connection depends on several moving parts: the CLI and server versions, your tenant's sign-in policies, the machines where tokens are cached, and the network path to the server. Confirm each item below with the PyRIT documentation or your own tests before you hand the setup to a red team.

CLI and server version compatibility

The CLI and the CoPyRIT backend must agree on how they exchange requests and tokens, so a mismatch can fail in ways that look like sign-in errors. Check which PyRIT release your CLI installs and which release your CoPyRIT server runs, and confirm the pairing in the release notes for the version you deploy. Run one pyrit_scan job against a test server after every upgrade on either side.

PyRIT releases

Device-code flow in your tenant

Device-code sign-in only works if your Entra tenant allows the flow for the client application that CoPyRIT uses. Some tenants block it by policy, and the error appears only when a user first signs in. Ask your identity team whether device-code authentication is permitted for the app registration and for the Microsoft Graph User.Read scope before you give the setup to users.

Conditional Access prompts during sign-in

Conditional Access policies can require MFA, a compliant device or a trusted location at each sign-in, which interrupts a CLI session that expects to finish without help. Test the sign-in from a standard red team workstation and from a restricted network segment. Record which policies fire, how often users are prompted again, and whether a session token lasts long enough for a full scan.

Token cache on shared or ephemeral machines

The CLI keeps an encrypted token cache so users do not sign in on every run. On shared jump hosts, disposable CI runners or reimaged VMs, that cache may persist longer than intended or disappear without warning. Confirm where the cache is written, how the encryption key is protected on each machine type, and whether your offboarding process clears it when a red teamer leaves.

Network reachability to the server

The CLI must reach the CoPyRIT server URL from every machine that runs it, including CI agents and VPN-connected laptops. If the server sits behind a private endpoint or a restricted egress path, a connection that works from one subnet can fail from another. Test name resolution, TLS and the routing path from each client location, and confirm which outbound addresses the server sees.

Admin routes exposed to CLI callers

CoPyRIT separates configuration routes behind an admin group, so the CLI token should not reach them unless the user is in that group. Confirm with a test account that a standard CLI sign-in gets refused on admin routes, and check whether the azure_cli mode changes that result. A token with broader Graph permissions can make the boundary weaker than the group model assumes.

PyRIT Scanner docs

How this fits with other CoPyRIT deployment choices

The CLI connection is the last step in a chain, not a standalone setting. Before you write a server URL and auth_mode into a config file, the backend must already exist at a fixed address, and the hosting choice decides what that address is. A CoPyRIT instance on Azure Container Apps gives you an ingress endpoint that depends on how the Bicep deployment exposes the app, while a Docker or local server gives you a host name that is only reachable from machines that can route to it. Confirm the final URL with the team that owns the deployment and test it from a laptop before you distribute any config file, because a wrong URL will fail in the same way as a wrong sign-in.

Entra ID group access determines whether the CLI sign-in succeeds for a given user, even when the URL is correct. The device-code flow signs the user in with the Microsoft Graph User.Read scope, but the backend still checks the allowed group IDs before it serves CoPyRIT routes. Ask whether the test account is in the allowed group and not only in the admin group, because the admin group controls configuration routes and should not be the default for everyday CLI use. Also confirm with the identity team which Graph permission the backend needs, since a CLI user who signs in successfully can still get a refusal if the backend cannot validate the group membership. Plan the group setup and the CLI rollout in that order.

If your organization runs separate CoPyRIT instances for each red team, product group or partner, each instance has its own server URL, app registration and allowed groups. A config file therefore points at one backend only. Give each team its own config and token cache, and do not reuse one .pyrit_conf across instances, since a token issued for one app registration will not be accepted by another. Map each team to its instance before rollout, and record which tenant and client ID each config expects so that a support request can be traced to the right backend.

How DeployOpen works on this

DeployOpen treats the connection between your CLI users and your shared CoPyRIT backend as a defined piece of work: who signs in, through which tenant and groups, and how tokens are cached on each workstation. The written scope fixes what is configured, tested and documented before any team member relies on it.

How we scope

  • Confirm the CoPyRIT server URL, the Entra tenant and the sign-in mode each team will use.
  • Agree in writing which pyrit_scan and pyrit_shell users need access and how workstations are set up.
  • Record whether any team will be offered azure_cli mode and the justification for that exception.
  • Fixed-scope engagements set deliverables and timelines in writing before work starts.

How we build

  • Write the shared config file template with server url and auth_mode, and test it on representative workstations.
  • Verify the device-code sign-in flow, the Microsoft Graph User.Read scope and the encrypted persistent token cache.
  • Test that users outside the allowed Entra groups are refused by the backend and that pyrit_shell behaves as documented.
  • Check that no shared secrets or tokens are placed in config files or shell history.

How we hand over

  • Deliver a written runbook covering setup steps, sign-in, token cache location, sign-out and token clearing.
  • Document the troubleshooting steps for failed device-code sign-in, expired sessions and group membership changes.
  • Walk operators through the procedure for onboarding and offboarding users on the shared backend.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover.
  • Retainers can cover re-testing the CLI connection when PyRIT or CoPyRIT versions change.
  • Ask any provider to confirm the support scope, response expectations and upgrade handling in the quote.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.