Installing and using the Patrol CLI
The Patrol CLI (patrol) lets you connect cloud accounts to Patrol from the command line — automating the IAM role and service principal setup that would otherwise require manual steps in the cloud console.
Installation
Section titled “Installation”The CLI is distributed as an npm package:
npm install -g @patrol/cliVerify the installation:
patrol --versionPrerequisites
Section titled “Prerequisites”Which cloud tools you need depends on what you’re connecting:
| Cloud | Prerequisite |
|---|---|
| AWS | AWS CLI configured with credentials for the target account |
| Azure | Azure CLI (az login completed) |
| GCP | gcloud CLI authenticated with the target project |
Authentication
Section titled “Authentication”Before connecting cloud accounts, log in to your Patrol instance:
patrol loginThis prompts for your Patrol API URL and credentials, then stores a token locally for subsequent commands.
To log out and remove the stored token:
patrol logoutConnecting cloud accounts
Section titled “Connecting cloud accounts”The fastest path is to use the setup command generated directly from Patrol’s UI. On any cloud account’s detail page, click Generate setup command — this produces a one-time token baked into a ready-to-run command.
# Using the one-time token from Patrol's UI (recommended)patrol connect aws --token <token>
# Without a token — prints credentials for you to enter manuallypatrol connect awsWhat it does:
- Creates (or updates) an IAM role — default name
PatrolReadOnly - Attaches
SecurityAuditandViewOnlyAccessmanaged policies - Sets a trust policy scoped to Patrol’s AWS account with an
sts:ExternalIdcondition (confused-deputy protection) - Reports the Role ARN back to Patrol automatically (when using
--token)
Options:
--profile <name>— AWS profile to use (defaults to the AWS CLI default)--role-name <name>— IAM role name (defaults toPatrolReadOnly)
# Using the one-time token from Patrol's UI (recommended)patrol connect azure --token <token>
# Without a token — prints credentials for you to enter manuallypatrol connect azureWhat it does:
- Creates a Service Principal (default name
PatrolReadOnly) with the Reader role on the subscription - Generates a client secret
- Saves the credentials back to Patrol automatically (when using
--token)
Options:
--subscription <id>— Azure subscription ID (defaults to the currentazCLI subscription)--sp-name <name>— Service Principal display name (defaults toPatrolReadOnly)
See Connecting Azure accounts for a full walkthrough.
Setting up Azure deployment prerequisites
Section titled “Setting up Azure deployment prerequisites”If you’re deploying to Azure via Terraform, the CLI can provision the Azure-side infrastructure Patrol needs:
patrol setup azureThis creates:
- A resource group (
patrol-infra) for Patrol infrastructure - A storage account with a
tfstatecontainer for Terraform state - A Service Principal with Contributor role and OIDC federated credentials for GitHub Actions
Options:
--subscription <id>— Azure subscription ID--region <region>— Azure region (defaults touksouth)--storage-account <name>— storage account name--repo <org/repo>— GitHub repository that will deploy
One-step register and connect
Section titled “One-step register and connect”patrol register combines adding the cloud account to Patrol and setting up cloud access in a single command:
patrol register awspatrol register azureThis is equivalent to adding the account in Patrol’s UI and then running patrol connect, all in one step.