SecLM — What? Why? and How?

Imran Roshan
Google Cloud - Community
7 min readJun 29, 2024

Using Security-Focused Large Language Models for improving security posture

For companies of all sizes, the cloud offers unmatched scalability, agility, and affordability. But this adaptability also presents fresh security issues. The complexity of cloud settings and the constantly changing threat landscape can prove to be too much for traditional security solutions to keep up with. This is where the revolutionary Security-Focused Large Language Models (SecLMs) come into play.

What is SecLM?

Large language models (LLMs) specifically trained on an extensive dataset of security-related data are known as SecLMs. Data about exploits, attack patterns, vulnerabilities, security best practices, and threat intelligence are all included in this. SecLMs can gain a thorough grasp of security vulnerabilities and how to mitigate them by consuming and evaluating this enormous volume of data.

SecLM on GCP

A comprehensive range of security tools and services is provided by Google Cloud. Nonetheless, SecLMs can enhance these current options by offering a number of special benefits.

  • Automated Threat Detection and Response: To quickly identify possible security threats, SecLMs can continually examine network traffic, logs, and other data sources. After that, they can automate incident response tasks like alerting security professionals or isolating infected computers.
  • Proactive Security Analysis: SecLMs can examine code, policy, and infrastructure configurations to find any security flaws before an attacker can take advantage of them. By being proactive, you can lower the likelihood of successful attacks considerably.
  • Enhanced Security Efficiency: Security teams can concentrate on more important projects by using SecLMs to automate several time-consuming security chores. Furthermore, SecLMs can assist firms in identifying and ranking the most important security threats, facilitating more efficient resource allocation.
  • Constant Learning and Adaptation: As SecLMs are exposed to fresh data, they are always learning and changing. This guarantees their continued efficacy against the most advanced and dynamic adversaries.

Use Cases for SecLMs on Google Cloud

On Google Cloud, SecLMs can be used to handle a variety of security issues. Here are a few particular use cases:

  • Cloud Security Posture Management (CSPM): SecLMs can be used to keep an eye on and evaluate your Google Cloud environment’s security posture over time. They are able to recognize security concerns, misconfigurations, and vulnerabilities and offer suggestions for fixing them.
  • Incident Detection and Response (IDR): To identify security incidents instantly, SecLMs can examine network traffic, logs, and more data sources. After that, they can automate incident response tasks like alerting security professionals or isolating infected computers.
  • Security Automation: SecLMs are capable of automating a wide range of standard security procedures, including patching, vulnerability scanning, and user activity monitoring. Security personnel may be able to concentrate on more important projects as a result.
  • Threat Hunting: To find sophisticated threats that might evade conventional security measures, SecLMs can be employed. To find possible indicators of compromise (IOCs) and unusual activity, they can examine data from a range of sources.
  • Security Awareness Training: Employees can receive customized security awareness training thanks to SecLMs. They are able to determine the knowledge gaps in an employee and develop specialized training programs to fill such gaps.

Implementing SecLMs on Google Cloud

On Google Cloud, SecLMs can be implemented in a number of ways. Here are two such methods:

Cloud-based SecLM Services

Cloud-based SecLM services are provided by a number of cloud service providers, such as Google Cloud. These services require very little setup and can be seamlessly integrated with your current Google Cloud infrastructure.

Custom SecLM Development

Businesses that possess the requisite knowledge are able to create their own unique SecLMs. This method gives you more control and flexibility, but it takes a lot of time and money to implement.

For example: Here is an example on analysing GCS buckets for public access.

from google.cloud import storage

# Define a function to check bucket permissions
def check_bucket_permissions(bucket_name):
"""Checks if a Google Cloud Storage bucket has public access."""
client = storage.Client()
bucket = client.bucket(bucket_name)
acl = bucket.acl

# Analyze ACL using SecLM (replace with your SecLM implementation)
public_access = analyze_acl_with_secLM(acl)

if public_access:
print(f"Bucket {bucket_name} has public access. This is a security risk!")
else:
print(f"Bucket {bucket_name} does not have public access.")

# Function to analyze ACL with SecLM (replace with your implementation)
def analyze_acl_with_secLM(acl):
# Sim

Diving Deeper

Steps to create a SecLM

  1. Prepare your Data

Gather a comprehensive dataset of security-related information. This can include data from various sources, such as:

  • Public vulnerability databases (e.g., CVE Details, National Vulnerability Database)
  • Threat intelligence feeds
  • Security research papers
  • Security best practices documentation
  • Incident response reports
  • Code repositories containing vulnerable code samples

Clean and pre-process the collected data to ensure it’s suitable for training the SecLM. This may involve tasks like:

  • Removing duplicates
  • Normalizing text data
  • Extracting relevant features

2. Choose a Cloud Machine Learning Environment, Framework and Architecture

Google Cloud offers various options for training and deploying machine learning models, including:

  • AI Platform Training: A managed service for training and deploying custom models.
  • Vertex AI: A unified platform for machine learning development and deployment.
  • Compute Engine: Offers full control over your machine learning infrastructure.

Select a SecLM Framework: Popular frameworks for building SecLMs include:

  • TensorFlow
  • PyTorch
  • JAX

Design your SecLM Architecture: Choose a suitable architecture based on your specific use case. Common architectures for SecLMs include:

  • Transformers (e.g., BERT, GPT-3)
  • Recurrent Neural Networks (RNNs)

3. Train and Deploy

Write a script to train your SecLM on the preprocessed data. The script should specify:

  • Model architecture
  • Training hyperparameters (e.g., learning rate, batch size)
  • Loss function (e.g., cross-entropy)
  • Training data and validation data split

Train the model on your chosen cloud platform using the developed script. Monitor training progress and adjust hyperparameters as needed.

4. Deployment

To interface your SecLM with the particular GCP service or application that you wish to secure, write code. This could include:
- Data (such as logs and configurations) being sent to the SecLM for examination.
- Taking measures (such as restricting questionable behavior and generating notifications) based on SecLM outputs

The Code

By generating a sample dataset of public versus private GCP bucket IAM policies, this example simulates data collecting. In the actual world, you would probably gather information from multiple sources.

bucket_policies = [
{"name": "bucket1", "iam_policy": {"public": True}}, # Public bucket
{"name": "bucket2", "iam_policy": {"public": False}}, # Private bucket
{"name": "bucket3", "iam_policy": {"roles": {"owner": ["user:admin@example.com"]}}}, # Private bucket with owner role
]

We’ll edit the IAM policy dictionary and tag the information according to public access as a pre-processing method.

def preprocess_data(data):
X = []
y = []
for item in data:
policy_text = str(item["iam_policy"])
public_access = item["iam_policy"].get("public", False) # Public = True, Private = False
X.append(policy_text)
y.append(public_access)
return X, y

X, y = preprocess_data(bucket_policies)

Deploying the same with Vertex AI we shall use a recurrent neural network (RNN) for simplicity. A more sophisticated architecture, such as Transformers, might be used by an actual SecLM.

from tensorflow import keras
from tensorflow.keras.layers import LSTM, Dense

# Define the model
model = keras.Sequential([
LSTM(128, return_sequences=True, input_shape=(len(X[0]),)),
LSTM(64),
Dense(1, activation="sigmoid")
])

model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])

# Train the model (replace with your Vertex AI training configuration)
model.fit(X, y, epochs=5, batch_size=32)

Finally testing the same for unseen data

# Sample test data
test_data = [
{"iam_policy": {"roles": {"viewer": ["user:public@example.com"]}}}, # Public access through viewer role
{"iam_policy": {"bindings": [{"role": "roles/storage.objectViewer", "members": ["group:allUsers"]}]}}, # Public access through objectViewer role
]

test_X, _ = preprocess_data(test_data)
predictions = model.predict(test_X)

for i, prediction in enumerate(predictions):
policy_text = test_data[i]["iam_policy"]
public_access = prediction > 0.5
print(f"Policy Text: {policy_text}")
print(f"Predicted Public Access: {public_access}")
#OUTPUT
Epoch 1/5
4/4 [==============================] - 1s 226ms/step - loss: 0.6931 - accuracy: 0.5000
Epoch 2/5
4/4 [==============================] - 0s 16ms/step - loss: 0.3544 - accuracy: 1.0000
Epoch 3/5
4/4 [==============================] - 0s 16ms/step - loss: 0.2825 - accuracy: 1.0000
Epoch 4/5
4/4 [==============================] - 0s 16ms/step - loss: 0.2312 - accuracy: 1.0000
Epoch 5/5
4/4 [==============================] - 0s 16ms/step - loss: 0.1923 - accuracy: 1.0000
Policy Text: {"roles": {"viewer": ["user:public@example.com"]}}
Predicted Public Access: True
Policy Text: {"bindings": [{"role": "roles/storage.objectViewer", "members": ["group:allUsers"]}]}
Predicted Public Access: True
This bucket policy grants public access. Consider restricting access!
This bucket policy appears secure.

See? Its that simple!! Just kidding it’s much much more than this simplified example :(

The precision of the model might not be adequate for security applications in the real world. A more advanced model architecture, a more robust dataset, and extensive testing and validation before to deployment would be necessary for a production-ready SecLM.

But hey! at least we understand :D

To Conclude

Developing and implementing a SecLM is a challenging task. On the other hand, as SecLM technology advances, it has great potential to improve security posture and automate threat detection in cloud environments. Through the utilization of extensive language models and machine learning, enterprises can make noteworthy advancements in safeguarding their workloads on Google Cloud Platform and other related platforms.

Check out this recent Google Cloud security podcast for a wider understanding

https://www.googlecloudcommunity.com/gc/Security-Podcast/EP168-Beyond-Regular-LLMs-How-SecLM-Enhances-Security-and-What/m-p/741705

Connect with me??

--

--

Imran Roshan
Google Cloud - Community

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