Prisma Cloud CLI
Project description
Prisma Cloud CLI
The Prisma Cloud CLI is a command line interface for Prisma Cloud by Palo Alto Networks.
Community Supported
This template/solution is released under an as-is, best effort, support policy. These scripts should be seen as community supported and Palo Alto Networks will contribute our expertise as and when possible. We do not provide technical support or help in using or troubleshooting the components of the project through our normal support options such as Palo Alto Networks support teams, or ASC (Authorized Support Centers) partners and backline support options. The underlying product used (Prisma Cloud) by the scripts or templates are still supported, but the support is only for the product functionality and not for help in deploying or using the template or script itself.
Unless explicitly tagged, all projects or work posted in our GitHub repository (at https://github.com/PaloAltoNetworks) or sites other than our official Downloads page on https://support.paloaltonetworks.com are provided under the best effort policy.
Getting started
Requirements
- Python >= 3.8
- Pip3
Installation
pip3 install prismacloud-cli
Installation on Alpine:
sudo pip3 install --upgrade pip && pip3 install --upgrade setuptools
sudo pip3 install prismacloud-cli
Installation on Ubuntu:
sudo apt update
sudo apt install -y python3-venv python3-pip jq
mkdir python_virtual_environments/
cd python_virtual_enviornments/
python3 -m venv prisma_cli_env
source prisma_cli_env/bin/activate
pip3 install prismacloud-cli
Run the script
Run the pc cli script. If you don't have a config file yet, it will help you to create one.
pc version
This process looks like the screenshot below. the prismacloud-cli asks you for some details, stores it in the credentials file and uses that file when it is already available.
Create your own configuration
Create an access key from Settings then Access key Get the path to console from Compute tab, System, Utilities
Create a file into home directory .prismacloud/credentials.json with the following structure.
{
"url": "__REDACTED__",
"identity": "__REDACTED__",
"secret": "__REDACTED__"
}
You can add additional configurations which you can call by using --config. For example, create a file called ~/.prismacloud/demo.json with the contents above.
Add --config demo
to your cli commands.
For example:
pc --config demo -o csv policy
Use environment variables for configuration
By setting the environment variables:
PC_ACCESS_KEY
PC_SAAS_API_ENDPOINT
PC_SECRET_KEY
And then run pc referring to a configuration called environment:
pc --config environment <command>
How to use the Prisma Cloud CLI in pipelines (e.g. Github Actions)
See Prisma Cloud CLI in GitHub Actions
How to enable or disable policies at scale via CSV
See How to enable or disable policies at scale via CSV
Examples
pc -o csv policy
pc -o json policy | jq
pc tags
pc stats dashboard
pc -o json stats dashboard
pc cloud name
pc --columns defendersSummary.host stats dashboard
Global options
The following global options are available
Options:
-v, --verbose Enables verbose mode.
-vv, --very_verbose Enables very verbose mode.
-o, --output [text|csv|json|html|clipboard|markdown|columns]
-c, --config TEXT Select configuration
~/.prismacloud/[CONFIGURATION].json
--columns TEXT Select columns for output
--help Show this message and exit.
Use -o columns to get a list of columns available for --columns, e.g.:
pc -o columns images
pc --columns hostname,repoTag.repo,osDistro -o csv images -l 1
Environment variables
To overwrite the default output settings, use environment variables MAX_WIDTH (console output), MAX_ROWS, MAX_COLUMNS and MAX_LINES.
- MAX_LINES is used to defined the maximum number of lines within a cell when wrapping the contents.
Commands
The cli has several commands to work with, see the screenshot below for an example, but use pc --help
to see the latest list for your version.
Use cases
Log4J Impacted Resources
pc -o json stats vulnerabilities --cve CVE-2021-44228 | jq
pc stats vulnerabilities --cve CVE-2021-44228
Use something similar for getting the Spring Shell impacted resources.
Search scan reports for images scanned by the Jenkins plugin or twistcli.
pc scans --help
Select only specific columns for the output:
pc --columns entityInfo.repoTag.registry,entityInfo.repoTag.repo,entityInfo.repoTag.tag,entityInfo.vulnerabilitiesCount scans -l 20 -s nginx
You might also want to add some additional columns and save the output as html:
pc --config local -o html --columns entityInfo.repoTag.registry,entityInfo.repoTag.repo,entityInfo.repoTag.tag,entityInfo.vulnerabilitiesCount,entityInfo.vulnerabilityDistribution.critical,entityInfo.vulnerabilityDistribution.high,entityInfo.vulnerabilityDistribution.medium scans -l 20 -s nginx > /tmp/results.html
Then, open /tmp/results.html:
Enable CSPM policies with Prisma Cloud CLI
pc policy set --help
pc -vv policy set --status enable --compliance_standard 'CIS v1.4.0 (AWS)'
Disable CSPM policies with Prisma Cloud CLI
pc -vv policy set --status disable --compliance_standard 'CIS v1.4.0 (AWS)'
Code Security
The below examples are using Github as integration but it works as well with other integration:
- Bitbucket
- Gitlab
- AzureRepos
- Github Enterprise
- Gitlab Enterprise
- Bitbucket Enterprise
Count the number of unique git authors across all Github repositories:
pc -ojson repositories count-git-authors -i Github | jq .
Get the details of all CVE across all Github repositories:
pc -o json repositories search -i Github -c Vulnerabilities -t packageCve --details | jq .
Get all secrets across all Github repositories:
pc -o json repositories search -i Github -c Secrets -t violation | jq .
Get all drift across all Github repositories:
pc repositories search --integration_type Github --categories Drift
Container registries
Listing registries
To list all container registries:
pc registry list
Triggering Scans
To trigger scans on all registries:
pc registry scan
Including Specific Registries
To include specific registries or repositories in the scan:
pc registry scan --include "registry_name/repo_name" --i "another_registry"
Excluding Specific Registries
To exclude specific registries or repositories from the scan:
pc registry scan --exclude "registry_name/repo_name" --e "another_registry"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file prismacloud_cli-0.8.11.tar.gz
.
File metadata
- Download URL: prismacloud_cli-0.8.11.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4faec6aac131af61b6d5145860c2f99ffcea8dd267e85cc05f71cc578203d1d |
|
MD5 | 569c0e7e534577874a615327481455c9 |
|
BLAKE2b-256 | 9d540a96e0da5a83904e0bb5e0e05ac0b8197817065b1f4ed06e69c28856b456 |
File details
Details for the file prismacloud_cli-0.8.11-py3-none-any.whl
.
File metadata
- Download URL: prismacloud_cli-0.8.11-py3-none-any.whl
- Upload date:
- Size: 58.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d6f91e0ff4f43d0d99c29c539e2ef9d256f740e7b602919f7b4ac7a64b0c19b |
|
MD5 | 8f959f02441955599ae0c713405a91f1 |
|
BLAKE2b-256 | 44e1e2d286b4ccfea3378b7d8f699a5ec30d6fb01a0946de3060291ec342d4df |