Package: pybanyan
API library and command-line interface for Banyan SecurityPrerequisitesPython 3.7+ must be installed.InstallationInstalling the easy way$pipinstallpybanyanInstalling the hard way$gitclonehttps://github.com/banyansecurity/pybanyan.git$cdpybanyan$pipinstall-rrequirements.txt$pythonsetup.pyinstall--userUsageThis package contains both an API client and a CLI tool.
To use either one, you need togeneratean API credential from the Banyan Command Center.API libraryHere's a sample script that uses the library to print the names of every hosted website service registered in Banyan:frombanyan.apiimportBanyanApiClientc=BanyanApiClient()forserviceinc.services_web.list():print(service.name)Output:$pythonexamples/list_services.pyjirajupyterkubemysqlrds-mysqlrds-pgsqlTheBanyanApiClientclass accepts optional arguments to specify the API server and API credential. If not provided,
it gets them from environment variables namedBANYAN_API_URLandBANYAN_API_KEY(you can also use a personal refresh token as your API credential.Full API documentation is available in thedocs.Banyan CLI toolBefore you use the CLI, create a file called~/.banyan.confin your home directory and paste in your API credential in theapi_keyfield (you can also use a personal refresh token as your API credential):[banyan]api_url=https://net.banyanops.comapi_key=MY_API_KEYThe CLI is invoked with thebanyantool. It contains a number of commands and sub-commands to help you work with policies, roles, services, users, and other objects in Banyan.Run thebanyantool by itself to see the available commands.$banyanusage: banyan [options] <command> <subcommand> [<subcommand> ...] [parameters]API library and command-line interface for Banyan Securityoptions:-h, --help            show this help message and exit-d, --debug           full application debug mode-q, --quiet           suppress all console output--version, -v         show program's version number and exit--api-url API_URL     URL for the Banyan API server. Can also be configured via the BANYAN_API_URL environment variable.--api-key API_KEY     API credential used for the authentication to the Banyan API server. Can also be configured via the BANYAN_API_KEY environmentvariable.--insecure-tls, -k    Allow connections to API servers with invalid TLS certificates.--output-format {table,json,yaml}, -o {table,json,yaml}desired output format (table, json, yaml)Commands:{netagent,service,shield,access-tier,api-key,audit,cloud-resource,connector,device,event,export,policy,role,service-infra,service-tunnel,service-web,user}netagent            (deprecated: use access-tier) manage netagentsservice             (deprecated: use service-web or service-infra) manage web and TCP services and workloadsshield              (deprecated) manage shield clustersaccess-tier         manage access tiersapi-key             manage API keysaudit               retrieve audit logscloud-resource      manage cloud resources discovered from IaaSconnector           manage connectorsdevice              manage devicesevent               report on security eventsexport              export all objects from an organizationpolicy              manage authorization policies for users and workloadsrole                manage user and workload rolesservice-infra       manage infrastructure servicesservice-tunnel      manage service tunnelsservice-web         manage hosted website servicesuser                manage usersEach of the commands has multiple subcommands. For example,banyan serviceallows you to list services, create/delete, enable/disable, etc. Run the command without any subcommand to see the options:$banyanservice-webusage: banyan service-web [-h]{attach-policy,create,delete,detach-policy,disable,enable,get,list,test,update}...optional arguments:-h, --help            show this help message and exitsub-commands:{attach-policy,create,delete,detach-policy,disable,enable,get,list,test,update}attach-policy       attach a policy to a servicecreate              create a new service from a JSON specificationdelete              delete a servicedetach-policy       detach the active policy from a servicedisable             disable a serviceenable              enable a serviceget                 show the definition of a registered servicelist                list registered servicestest                run sanity checks on a serviceupdate              update an existing service from a JSON specificationTo see the full help available for any command, just add the-hor--helpoption to the end of the command.
For example:$banyanservice-webattach-policy--helpusage: banyan service-web attach-policy [-h] [--permissive] [--enforcing]service_name_or_id policy_name_or_idpositional arguments:service_name_or_id  Name or ID of the service to attach a policy to.policy_name_or_id   Name or ID of the policy to attach to the service.optional arguments:-h, --help          show this help message and exit--permissive        Set the policy to permissive mode (allow all traffic andlog any unauthorized access).--enforcing         Set the policy to enforcing mode (deny unauthorizedaccess).IntegrationsYou can automate different types of workflows by integrating with external APIs. We provide pre-built integrations for 2 types of workflows:1. Synchronize cloud resources from your IaaS providerYou can discover and synchronize your IaaS (Infrastructure As A Service) resources into Banyan's inventory, so you can later publish some or all of them as Banyan services. Read ouroverview on how Banyan synchronizes IaaS resources, and then check out instructions to set up for your specific IaaS provider:AWSAzure CloudGCPOracle Cloud2. Bookmark Banyan services into your SSO catalogYou can publish Banyan services as bookmark applications in your SSO (Single Sign On) portal, so your end-user can access them via their SSO catalog. Check out the provider-specific link for setup instructions.OktaAzureADDevelopmentTo work on the pybanyan code, follow the instructions in thedocumentation.SupportThis API library and its accompanying CLI utility are provided free of charge and without support. To report
issues with the library, please create a newissue in Github.ContributionsWe welcome your contributions in the form of pull requests! Please follow the standardGithub pull request
workflow.