VPC Service Controls — Making it smarter

Imran Roshan
Google Cloud - Community
5 min readJul 16, 2024

Integrating VPC SC with AI capabilities.

In the ever-evolving landscape of cloud security, protecting your virtual private cloud (VPC) is paramount. Security groups, as the firewall for your instances, play a crucial role in this defense. Traditionally, managing security groups has been a manual, error-prone process. However, with the advent of Security Command Center (SCC) and the integration of Artificial Intelligence (AI), we can now create “smart” security groups that are not only efficient but also adaptive to evolving threats.

This blog delves into the intricacies of constructing such smart security groups, leveraging the capabilities of SCC and AI. We’ll cover the fundamentals of VPC security groups, the role of SCC in security posture management, and the power of AI in enhancing security group management.

Let’s first examine the technological elements and then examine the difficulties with typical VPC security:

  • Complex Environments: Because VPCs are complex networks with many resources, creating rules and managing them manually can be difficult.
  • Dynamic Threats: As a result of the quick changes in the threat landscape, security policies must be flexible.
  • Human Error: Vulnerabilities may arise from configuration errors and oversights.
  • Compliance Challenges: It takes a lot of effort and time to comply with different security requirements.

To tackle these issues, Smart VPC Service Controls do the following:

  • Automation: Creating rules and automating repetitive processes.
  • Intelligence: Applying AI to threat analysis and control adaptation.
  • Being Proactive: Preventive security involves detecting weaknesses before they are taken advantage of.
  • Being compliant: Enforcing compliance with security requirements is known as compliance enforcement.

Some Common Integrations

Here are some common integrations with VPC service controls helping make your abilities with VPC make new advancements.

Security Command Center

The main component of our solution is SCC. It interacts with multiple security technologies, gives you a consolidated view of your security posture, and has features that allow you to:

  • Identify and manage cloud resources with Asset Inventory.
  • Prioritize and identify issues using vulnerability management techniques.
  • Recognize and address threats.
  • Make incident management more efficient.

Here’s a sample code snippet utilizing SCC to retrieve asset inventory

import googleapiclient.discovery

def get_scc_assets(project_id):
"""Retrieves assets from Security Command Center."""
service = googleapiclient.discovery.build('securitycenter', 'v1')
parent = f"organizations/{project_id}"
request = service.organizations().assets().list(parent=parent)
response = request.execute()
return response['assets']

AI

AI/ML models have the potential to greatly improve VPC security:

  • Threat Detection: Spotting unusual or suspicious behavior.
  • Anomalies: Finding deviations from typical behavior is known as anomaly detection.
  • Potential dangers are predicted via predictive analysis.
  • Optimal security rule configurations are suggested through rule optimization.

Heres a simple overview on detecting deviations on VPC flow logs.

import pandas as pd
from sklearn.ensemble import IsolationForest

def detect_anomalies(flow_logs):
"""Detects anomalies in VPC flow logs using Isolation Forest."""
df = pd.DataFrame(flow_logs)
# Preprocess data
# Train Isolation Forest model
model = IsolationForest(contamination=0.01)
model.fit(df)
# Predict anomalies
predictions = model.predict(df)
anomalies = df[predictions == -1]
return anomalies

Custom Security Rules

SCC provides a foundation, but custom rules offer granular control. Consider rules for:

  • Ingress/Egress traffic filtering
  • IP whitelisting/blacklisting
  • Port restrictions
  • Protocol limitations

For example creating a custom rule using the GCE API

import googleapiclient.discovery

def create_firewall_rule(project_id, network_name, rule_name, source_ranges, target_tags):
"""Creates a firewall rule."""
service = googleapiclient.discovery.build('compute', 'v1')
firewall_rule = {
'name': rule_name,
'network': f'projects/{project_id}/global/networks/{network_name}',
'sourceRanges': source_ranges,
'targetTags': target_tags,
# ... other rule properties
}
request = service.firewalls().insert(project=project_id, body=firewall_rule)
response = request.execute()
return response

Creating a Smart System with Vertex AI

Vertex AI delivers sophisticated machine learning capabilities, while VPC SC establishes network security perimeters. When combined, they provide a strong barrier against changing attacks. Now! Let’s dive deep

Integration plan

  • Identify Critical Assets: In your GCP environment, identify the workloads and data that are most sensitive. These are going to be the main targets for defense.
  • Establish Service Limitations: Establish service parameters for the designated critical assets. To limit access, carefully set up egress and influx traffic restrictions.
  • Data intake and processing: Gather pertinent data from many sources, such as security records and network traffic. Prepare and purify the data in advance of machine learning.
  • Engineering Features: Take significant features out of the prepared data. The machine learning model will use these features as input.
  • Model Creation and Instruction: Using the prepared data, train a machine learning model to find any security vulnerabilities. For this, Vertex AI’s AutoML or customized training can be applied.
  • Model Deployment: For real-time threat detection, deploy the trained model to a Vertex AI endpoint.
  • Integration with VPC SC: To initiate automated reactions to threats identified, integrate the threat detection model with VPC SC.
  • Constant Monitoring and Improvement: Keep an eye on the integrated system’s performance and update the model in response to fresh information and threats.
import googleapiclient.discovery
from google.cloud import aiplatform

def create_service_perimeter(project_id, service_perimeter_name, resources):
# Create a service perimeter
service_perimeter_body = {
"name": f"projects/{project_id}/locations/global/servicePerimeters/{service_perimeter_name}",
"perimeterType": "PERIMETER_TYPE_RESTRICTED",
"resources": resources,
# ... other configuration options
}

service = googleapiclient.discovery.build('securitycenter', 'v1')
request = service.organizations().servicePerimeters().create(
parent=f"organizations/{project_id}", body=service_perimeter_body)
response = request.execute()
print(response)

def train_threat_detection_model(project_id, region, dataset_name, model_name):
# Create a dataset
dataset = aiplatform.Dataset(
display_name=dataset_name,
location=region,
metadata_schema_uri="gs://google-cloud-aiplatform/schema/dataset/metadata/tfx-v1.0.0.json",
)
dataset.create()

# Create a training job
training_job = aiplatform.TrainingJob(
display_name=model_name,
location=region,
training_task_definition=aiplatform.training_job.TrainingTaskDefinition(
image_uri="gcr.io/cloud-aiplatform/training/tf-cpu.2-7:latest",
script_path="training/task.py", # Replace with your training script
args=["--dataset", dataset.resource_name],
),
)
training_job.run()

# Example usage:
project_id = "your-project-id"
service_perimeter_name = "my-service-perimeter"
resources = [
# List of resources to include in the service perimeter
]
dataset_name = "threat_detection_dataset"
model_name = "threat_detection_model"

create_service_perimeter(project_id, service_perimeter_name, resources)
train_threat_detection_model(project_id, "us-central1", dataset_name, model_name)

create_service_perimeter:

  • Creates a VPC Service Perimeter with the given name and resources.
  • Constructs the service perimeter body with necessary information.
  • Uses the googleapiclient.discovery to build the Security Center service and create the service perimeter.

train_threat_detection_model:

  • Trains a threat detection model using Vertex AI.
  • Creates a dataset for the training data.
  • Defines a training job with the necessary parameters.
  • Starts the training job.

Caveats

The code provides a basic outline, real-world implementations would require more complex configurations and error handling. The resources list in the create_service_perimeter function needs to be populated with actual resource names or patterns. The training script (training/task.py) and its dependencies are not included in this code snippet. Further, The code assumes you have the necessary permissions to create service perimeters and train models in your GCP project.

To Conclude

Integration to perimeter definitions enhanced with AI makes a great team to provide with robust features for resilience. However, this is a tiny example that shows the fundamental input and output structure. The data, setups, and outputs involved in actual implementations would be far more intricate. So go ahead, find your poison, let me know if anything new pops up!!

Connect with me

--

--

Imran Roshan
Google Cloud - Community

Your security sherpa | Google Developer Expert (GCP) | Ethical Hacker | Cloud Security