The Python script for updating rules in the Cloud Armor in Google Cloud Platform by REST API

simhumileco

I want to write a Python script that will update or add new rules to Cloud Armor in Google Cloud Platform using the Compute Engine REST API.

But I have several doubts:

  • Is the official Google Cloud Client Library for Python suitable for this purpose (if not what you propose)?

  • Which Python package should I install for this purpose?

  • Is this standard authentication (JSON file that contains my private key and correctly setting the environment variable GOOGLE_APPLICATION_CREDENTIALS) enough to connect to this API for the purpose that I want to achieve?

I am asking for directions.

Samuel N

A Python script would be a good way to go, and you can use the Google APIs Python client library to achieve this.

The Google Cloud Client Library for Python may not be sufficient, but the Google Cloud Client Libraries are the latest and recommended client libraries for calling Google Cloud APIs.

Compute Engine v1 securityPolicies REST API resource provides a list of methods that you need, such as addRule, getRule and patchRule to add a new rule, retrieve and update an existing rule respectively.

Checkout the PyDoc reference for the Compute Engine API for a full list of methods with explanations on how to use them.

Also, the Python Package (Google API Python Client Library) is what you need to use.

The standard authentication you mentioned provides a useful method for authorizing requests to the Compute Engine API via the Python Client Library.

According to the official doc: GCP client libraries use a strategy called Application Default Credentials (ADC) to find your application's credentials. When your code uses a client library, the strategy checks for your credentials in the following order:

  1. First, ADC checks to see if the environment variable GOOGLE_APPLICATION_CREDENTIALS is set. If the variable is set, ADC uses the service account file that the variable points to. The next section describes how to set the environment variable.
  2. If the environment variable isn't set, ADC uses the default service account that Compute Engine, Kubernetes Engine, App Engine, and Cloud Functions provide, for applications that run on those services.
  3. If ADC can't use either of the above credentials, an error occurs.

Finally, ensure that the user accounts you choose to use have the correct IAM permissions required to configure Cloud Armor on Compute engine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Google Cloud Platform - cloud functions API - 401 Unauthorized

From Dev

Adding roles to service accounts on Google Cloud Platform using REST API

From Dev

Authentication in Google Cloud Platform

From Dev

In layman terms: Relation between Google Apps Script and Google Cloud Platform

From Dev

Securing SpringBoot REST endpoints in Google Cloud Platform

From Dev

Google Cloud Armor: Cannot add targets using cloud armor

From Dev

Google Cloud Armor/Kubernetes : BackendConfig ignored by ingress

From Dev

How to access Cloud Platform for a Google Apps Script when the link is missing

From Dev

Issues Enabling Google Ads API on Google Cloud Platform Console

From Dev

Is Google Cloud Armor free with other Google Cloud products?

From Dev

How to know if the attack hit the preconfigure rules on google cloud armor?

From Dev

Detail mod security rules on Cloud Armor WAF

From Dev

Error Python API GCP Data Catalog - Google Cloud Platform

From Dev

Google Cloud Messaging VS Google Cloud Platform

From Dev

Google Cloud Platform with Firebase

From Dev

Google Cloud Platform - Datastore - Python ndb API

From Dev

Google Cloud Platform architecture

From Dev

Unable to run startup script when creating instance on Google Cloud Platform

From Dev

Google Cloud AutoML API REST call

From Dev

Google cloud platform support plan from API

From Dev

Google Cloud Text To Speech REST API Authentication

From Dev

What is network URI in google cloud rest API

From Dev

Google Cloud Platform SDK with Python

From Dev

Why some rule actions are disabled in google cloud armor?

From Dev

Displaying Guest Policies Applied to a Google Cloud Platform Compute Engine Instance Using the REST API

From Dev

how to make Google Cloud Armor interpret recaptcha score

From Dev

REST API using Google Cloud Functions

From Dev

Unable to create SecurityPolicy with Adaptive Protection in Google Cloud Armor via Pulumi using Python

From Dev

How to view and configure log retention of Security Policies in Google Cloud Armor?

Related Related

  1. 1

    Google Cloud Platform - cloud functions API - 401 Unauthorized

  2. 2

    Adding roles to service accounts on Google Cloud Platform using REST API

  3. 3

    Authentication in Google Cloud Platform

  4. 4

    In layman terms: Relation between Google Apps Script and Google Cloud Platform

  5. 5

    Securing SpringBoot REST endpoints in Google Cloud Platform

  6. 6

    Google Cloud Armor: Cannot add targets using cloud armor

  7. 7

    Google Cloud Armor/Kubernetes : BackendConfig ignored by ingress

  8. 8

    How to access Cloud Platform for a Google Apps Script when the link is missing

  9. 9

    Issues Enabling Google Ads API on Google Cloud Platform Console

  10. 10

    Is Google Cloud Armor free with other Google Cloud products?

  11. 11

    How to know if the attack hit the preconfigure rules on google cloud armor?

  12. 12

    Detail mod security rules on Cloud Armor WAF

  13. 13

    Error Python API GCP Data Catalog - Google Cloud Platform

  14. 14

    Google Cloud Messaging VS Google Cloud Platform

  15. 15

    Google Cloud Platform with Firebase

  16. 16

    Google Cloud Platform - Datastore - Python ndb API

  17. 17

    Google Cloud Platform architecture

  18. 18

    Unable to run startup script when creating instance on Google Cloud Platform

  19. 19

    Google Cloud AutoML API REST call

  20. 20

    Google cloud platform support plan from API

  21. 21

    Google Cloud Text To Speech REST API Authentication

  22. 22

    What is network URI in google cloud rest API

  23. 23

    Google Cloud Platform SDK with Python

  24. 24

    Why some rule actions are disabled in google cloud armor?

  25. 25

    Displaying Guest Policies Applied to a Google Cloud Platform Compute Engine Instance Using the REST API

  26. 26

    how to make Google Cloud Armor interpret recaptcha score

  27. 27

    REST API using Google Cloud Functions

  28. 28

    Unable to create SecurityPolicy with Adaptive Protection in Google Cloud Armor via Pulumi using Python

  29. 29

    How to view and configure log retention of Security Policies in Google Cloud Armor?

HotTag

Archive