From 7d63d408f744e5ed098e7467398167ead3e989fb Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Mon, 29 Jun 2026 00:24:25 +0300 Subject: [PATCH 01/19] Enhance agents-cli observability with BigQuery ML diagnostics and export support Added advanced diagnostic capabilities for agent reasoning paths and a new CLI command to export metrics to BigQuery for ML-driven evaluation --- skills/cloud/google-agents-cli-onboarding/SKILL.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skills/cloud/google-agents-cli-onboarding/SKILL.md b/skills/cloud/google-agents-cli-onboarding/SKILL.md index 7917c19db9..4a0191836c 100644 --- a/skills/cloud/google-agents-cli-onboarding/SKILL.md +++ b/skills/cloud/google-agents-cli-onboarding/SKILL.md @@ -1,5 +1,4 @@ ---- -name: google-agents-cli-onboarding +Name: google-agents-cli-onboarding description: >- Onboarding entrypoint for agents-cli in Agent Platform. It should be used when the user wants to "create a new agent", "develop an agent", "build an agent using ADK", @@ -46,7 +45,7 @@ which skill to load for your current phase: | **4 — Evaluate** | `google-agents-cli-eval` | **Validate Quality.** Run systematic evaluations (LLM-as-judge). | | **5 — Deploy** | `google-agents-cli-deploy` | **Go Production.** Deploy to Agent Runtime (Vertex AI), Cloud Run, or GKE. | | **6 — Publish** | `google-agents-cli-publish` | **Register.** Make your agent available as a tool in Gemini Enterprise. | -| **7 — Observe** | `google-agents-cli-observability` | **Monitor.** Set up Cloud Trace, prompt-response logging, and BigQuery analytics. | +| **7 — Observe** | `google-agents-cli-observability` | **Monitor & Analyze.** Set up Cloud Trace, prompt-response logging, and advanced BigQuery ML diagnostics to evaluate agent reasoning paths. | ## Key CLI Commands @@ -60,6 +59,7 @@ lifecycle: | `agents-cli eval run` | Run the agent and grade the traces in a single step (generate + grade). | | `agents-cli deploy` | Deploy your agent to Google Cloud (Agent Runtime, Cloud Run, GKE). | | `agents-cli publish gemini-enterprise` | Register your deployed agent with Gemini Enterprise. | +| `agents-cli observe --export=bigquery` | Export agent execution logs, prompt costs, and latency metrics directly into BigQuery datasets for ML-driven evaluation. | *For the full list of available commands and global options, run `agents-cli --help`.* From 048f8ae7e8d7dfc3190360074bae73cb2760ea25 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Mon, 29 Jun 2026 01:19:45 +0300 Subject: [PATCH 02/19] Create SKILL.md --- skills/cloud/agent-security-audit/SKILL.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 skills/cloud/agent-security-audit/SKILL.md diff --git a/skills/cloud/agent-security-audit/SKILL.md b/skills/cloud/agent-security-audit/SKILL.md new file mode 100644 index 0000000000..23826a64aa --- /dev/null +++ b/skills/cloud/agent-security-audit/SKILL.md @@ -0,0 +1,7 @@ +# Agent Security Audit + +A proactive security tool for analyzing agent interaction logs using BigQuery to detect anomalies and potential prompt injection patterns. + +## Usage +```bash +agent-cli run agent-security-audit --dataset_id --table_id From 456ac36b06661367cdcf97cb048b5d200ed7fa7d Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Mon, 29 Jun 2026 01:22:11 +0300 Subject: [PATCH 03/19] Create audit.py --- skills/cloud/agent-security-audit/audit.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 skills/cloud/agent-security-audit/audit.py diff --git a/skills/cloud/agent-security-audit/audit.py b/skills/cloud/agent-security-audit/audit.py new file mode 100644 index 0000000000..008944a7d6 --- /dev/null +++ b/skills/cloud/agent-security-audit/audit.py @@ -0,0 +1,22 @@ +from google.cloud import bigquery +import json + +class AgentSecurityAuditor: + def __init__(self, project_id): + self.client = bigquery.Client(project=project_id) + + def run_audit(self, dataset_id, table_id): + """ + يقوم بفحص سجلات الوكيل بحثاً عن أنماط مشبوهة + """ + query = f""" + SELECT interaction_log, timestamp + FROM `{dataset_id}.{table_id}` + WHERE interaction_log LIKE '%DROP TABLE%' + OR interaction_log LIKE '%UNION SELECT%' + LIMIT 100 + """ + query_job = self.client.query(query) + results = [dict(row) for row in query_job.result()] + + return json.dumps({"status": "AUDIT_COMPLETE", "threats_found": len(results), "data": results}) From 406a6fee500541de0a1ed7388bc9b1bd72e88b2c Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Mon, 29 Jun 2026 01:53:52 +0300 Subject: [PATCH 04/19] Update audit.py --- skills/cloud/agent-security-audit/audit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skills/cloud/agent-security-audit/audit.py b/skills/cloud/agent-security-audit/audit.py index 008944a7d6..b871039510 100644 --- a/skills/cloud/agent-security-audit/audit.py +++ b/skills/cloud/agent-security-audit/audit.py @@ -1,4 +1,4 @@ -from google.cloud import bigquery +bigquery import json class AgentSecurityAuditor: @@ -19,4 +19,4 @@ def run_audit(self, dataset_id, table_id): query_job = self.client.query(query) results = [dict(row) for row in query_job.result()] - return json.dumps({"status": "AUDIT_COMPLETE", "threats_found": len(results), "data": results}) + return json.dumps({"status": "AUDIT_COMPLETE", "threats_found": len(results), "data": results From 8efe60516fcb2606eff822f29fc59c8fcd7f5071 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Mon, 29 Jun 2026 02:00:23 +0300 Subject: [PATCH 05/19] Update SKILL.md From d6a233612a0ea2407a3aa13568e79a5e89531bb2 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Mon, 29 Jun 2026 02:04:08 +0300 Subject: [PATCH 06/19] Update audit.py --- skills/cloud/agent-security-audit/audit.py | 120 ++++++++++++++++++--- 1 file changed, 105 insertions(+), 15 deletions(-) diff --git a/skills/cloud/agent-security-audit/audit.py b/skills/cloud/agent-security-audit/audit.py index b871039510..bf509225f8 100644 --- a/skills/cloud/agent-security-audit/audit.py +++ b/skills/cloud/agent-security-audit/audit.py @@ -1,22 +1,112 @@ -bigquery +from google.cloud import bigquery +from google.api_core import exceptions import json +import re +from datetime import datetime +from typing import List, Dict, Any class AgentSecurityAuditor: - def __init__(self, project_id): + """ + مدقق أمني استباقي لوكلاء الذكاء الاصطناعي. + يفحص سجلات BigQuery بحثاً عن أنماط الهجوم. + """ + + DEFAULT_MAX_ROWS = 500 + SNIPPET_LENGTH = 60 + + THREAT_PATTERNS = { + "PROMPT_INJECTION": r"(?i)(ignore\s+(all\s+)?previous\s+instructions|you\s+are\s+now\s+a\s+|system\s+prompt|reveal\s+your\s+instructions)", + "DATA_EXFILTRATION": r"(?i)(send\s+data\s+to|upload\s+to|https?://|api[_\s]?key|password)", + "SQL_INJECTION": r"(?i)(DROP\s+TABLE|UNION\s+SELECT|--)" + } + + def __init__(self, project_id: str): self.client = bigquery.Client(project=project_id) - - def run_audit(self, dataset_id, table_id): - """ - يقوم بفحص سجلات الوكيل بحثاً عن أنماط مشبوهة + + def _sanitize_identifier(self, name: str) -> str: + """تنظيف اسم المعرف لمنع حقن SQL""" + sanitized = re.sub(r'[^a-zA-Z0-9_]', '', name) + if not sanitized: + raise ValueError(f"Invalid identifier: '{name}'") + return sanitized + + def _build_query(self, dataset: str, table: str, max_rows: int) -> str: + """بناء استعلام BigQuery الآمن""" + return f""" + SELECT interaction_log, timestamp, session_id + FROM `{dataset}.{table}` + WHERE interaction_log IS NOT NULL + LIMIT {max_rows} """ - query = f""" - SELECT interaction_log, timestamp - FROM `{dataset_id}.{table_id}` - WHERE interaction_log LIKE '%DROP TABLE%' - OR interaction_log LIKE '%UNION SELECT%' - LIMIT 100 + + def _analyze_log(self, log: str, timestamp: Any, session_id: Any) -> List[Dict[str, str]]: + """تحليل سجل واحد بحثاً عن جميع التهديدات المطابقة""" + findings = [] + for threat_type, pattern in self.THREAT_PATTERNS.items(): + if re.search(pattern, log): + findings.append({ + "threat_type": threat_type, + "snippet": log[:self.SNIPPET_LENGTH] + "..." if len(log) > self.SNIPPET_LENGTH else log, + "timestamp": str(timestamp), + "session_id": str(session_id) + }) + break + return findings + + def _format_response(self, status: str, **kwargs) -> str: + """تنسيق الرد النهائي بصيغة JSON""" + response = { + "status": status, + "audit_time": datetime.now().isoformat(), + **kwargs + } + return json.dumps(response, indent=2, ensure_ascii=False) + + def run_audit(self, dataset_id: str, table_id: str, max_rows: int = DEFAULT_MAX_ROWS) -> str: """ - query_job = self.client.query(query) - results = [dict(row) for row in query_job.result()] + تشغيل عملية التدقيق الأمني. - return json.dumps({"status": "AUDIT_COMPLETE", "threats_found": len(results), "data": results + Args: + dataset_id: اسم مجموعة البيانات في BigQuery + table_id: اسم الجدول + max_rows: أقصى عدد للصفوف المفحوصة (افتراضي: 500) + + Returns: + JSON string تحتوي على نتائج التدقيق + """ + try: + ds = self._sanitize_identifier(dataset_id) + tb = self._sanitize_identifier(table_id) + + query = self._build_query(ds, tb, max_rows) + query_job = self.client.query(query) + + all_findings = [] + for row in query_job.result(): + log = row.interaction_log + timestamp = row.timestamp + session_id = row.get("session_id", "unknown") + all_findings.extend(self._analyze_log(log, timestamp, session_id)) + + return self._format_response( + "AUDIT_COMPLETE", + threats_found=len(all_findings), + findings=all_findings + ) + + except exceptions.GoogleAPIError as e: + return self._format_response("ERROR", message=str(e)) + except ValueError as e: + return self._format_response("ERROR", message=f"Validation error: {str(e)}") + except Exception as e: + return self._format_response("ERROR", message=f"Unexpected error: {str(e)}") + +if __name__ == "__main__": + auditor = AgentSecurityAuditor(project_id="your-gcp-project-id") + report = json.loads(auditor.run_audit("your_dataset", "your_table")) + + print(f"Audit Status: {report['status']}") + print(f"Time: {report['audit_time']}") + print(f"Threats Found: {report['threats_found']}") + for f in report.get("findings", []): + print(f" - [{f['threat_type']}] {f['snippet']}") From b60b69656677650afbdb9a137493cfe4dd958ff3 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Fri, 7 Aug 2026 22:51:28 +0300 Subject: [PATCH 07/19] Add SQL query for agent security audit patterns --- skills/cloud/agent-security-audit/patterns/jailbreak.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 skills/cloud/agent-security-audit/patterns/jailbreak.sql diff --git a/skills/cloud/agent-security-audit/patterns/jailbreak.sql b/skills/cloud/agent-security-audit/patterns/jailbreak.sql new file mode 100644 index 0000000000..a32993d448 --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/jailbreak.sql @@ -0,0 +1,6 @@ +SELECT + timestamp, + agent_id, + user_input +FROM `{PROJECT_ID}.{DATASET_ID}.{TABLE_ID}` +WHERE REGEXP_CONTAINS(LOWER(user_input), r'ignore\s+(all\s+)?previous\s+instructions|you\s+are\s+now\s+a\s+|jailbreak|system\s+prompt') From c3f3d890fa06583e88fab347232f018661809c4a Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Fri, 7 Aug 2026 22:59:02 +0300 Subject: [PATCH 08/19] Add SQL query for indirect injection security audit Query retrieves timestamps, agent IDs, and non-null retrieved documents, filtering based on specific patterns. --- .../patterns/indirect_injection.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 skills/cloud/agent-security-audit/patterns/indirect_injection.sql diff --git a/skills/cloud/agent-security-audit/patterns/indirect_injection.sql b/skills/cloud/agent-security-audit/patterns/indirect_injection.sql new file mode 100644 index 0000000000..f5e06585da --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/indirect_injection.sql @@ -0,0 +1,11 @@ +SELECT + timestamp, + agent_id, + retrieved_documents +FROM `{PROJECT_ID}.{DATASET_ID}.{TABLE_ID}` +WHERE retrieved_documents IS NOT NULL +AND ( + REGEXP_CONTAINS(LOWER(retrieved_documents), r'ignore\s+above|do\s+not\s+follow|new\s+instruction') + OR + REGEXP_CONTAINS(LOWER(retrieved_documents), r'https?://|curl|wget|exfiltrate') +) From 85395b76af2fbf750be239378f5e8ec20413310f Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Fri, 7 Aug 2026 23:04:34 +0300 Subject: [PATCH 09/19] Load threat patterns from SQL files and update audit results Updated the AgentSecurityAuditor to load threat patterns from SQL files in the 'patterns/' directory, with a fallback to default patterns. Enhanced the run_audit method to include the patterns used in the audit results. --- skills/cloud/agent-security-audit/audit.py | 72 ++++++++++++---------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/skills/cloud/agent-security-audit/audit.py b/skills/cloud/agent-security-audit/audit.py index bf509225f8..8926eae68e 100644 --- a/skills/cloud/agent-security-audit/audit.py +++ b/skills/cloud/agent-security-audit/audit.py @@ -1,37 +1,62 @@ -from google.cloud import bigquery -from google.api_core import exceptions +""" +GCP Agent Security Audit Skill - Core Logic +""" +import os import json import re from datetime import datetime from typing import List, Dict, Any +from google.cloud import bigquery +from google.api_core import exceptions + class AgentSecurityAuditor: """ مدقق أمني استباقي لوكلاء الذكاء الاصطناعي. - يفحص سجلات BigQuery بحثاً عن أنماط الهجوم. + يفحص سجلات BigQuery بحثاً عن أنماط الهجوم باستخدام ملفات patterns/ """ DEFAULT_MAX_ROWS = 500 SNIPPET_LENGTH = 60 - THREAT_PATTERNS = { - "PROMPT_INJECTION": r"(?i)(ignore\s+(all\s+)?previous\s+instructions|you\s+are\s+now\s+a\s+|system\s+prompt|reveal\s+your\s+instructions)", - "DATA_EXFILTRATION": r"(?i)(send\s+data\s+to|upload\s+to|https?://|api[_\s]?key|password)", - "SQL_INJECTION": r"(?i)(DROP\s+TABLE|UNION\s+SELECT|--)" - } - def __init__(self, project_id: str): self.client = bigquery.Client(project=project_id) + self.patterns = self._load_threat_patterns() + def _load_threat_patterns(self) -> Dict[str, str]: + """تحميل أنماط التهديد من ملفات SQL الموجودة في مجلد patterns/""" + patterns_dir = os.path.join(os.path.dirname(__file__), "patterns") + patterns = {} + + if os.path.exists(patterns_dir): + for file_name in os.listdir(patterns_dir): + if file_name.endswith(".sql"): + file_path = os.path.join(patterns_dir, file_name) + try: + with open(file_path, 'r') as f: + content = f.read().strip() + if content: + pattern_name = file_name.replace(".sql", "").upper() + patterns[pattern_name] = content + except Exception: + pass + + # إذا لم يتم تحميل أي شيء، نستخدم أنماطاً افتراضية (Fallback) + if not patterns: + patterns = { + "PROMPT_INJECTION": r"(?i)(ignore\s+(all\s+)?previous\s+instructions|you\s+are\s+now\s+a\s+|system\s+prompt|reveal\s+your\s+instructions)", + "DATA_EXFILTRATION": r"(?i)(send\s+data\s+to|upload\s+to|https?://|api[_\s]?key|password)", + } + + return patterns + def _sanitize_identifier(self, name: str) -> str: - """تنظيف اسم المعرف لمنع حقن SQL""" sanitized = re.sub(r'[^a-zA-Z0-9_]', '', name) if not sanitized: raise ValueError(f"Invalid identifier: '{name}'") return sanitized def _build_query(self, dataset: str, table: str, max_rows: int) -> str: - """بناء استعلام BigQuery الآمن""" return f""" SELECT interaction_log, timestamp, session_id FROM `{dataset}.{table}` @@ -40,10 +65,9 @@ def _build_query(self, dataset: str, table: str, max_rows: int) -> str: """ def _analyze_log(self, log: str, timestamp: Any, session_id: Any) -> List[Dict[str, str]]: - """تحليل سجل واحد بحثاً عن جميع التهديدات المطابقة""" findings = [] - for threat_type, pattern in self.THREAT_PATTERNS.items(): - if re.search(pattern, log): + for threat_type, pattern in self.patterns.items(): + if re.search(pattern, log, re.IGNORECASE): findings.append({ "threat_type": threat_type, "snippet": log[:self.SNIPPET_LENGTH] + "..." if len(log) > self.SNIPPET_LENGTH else log, @@ -54,7 +78,6 @@ def _analyze_log(self, log: str, timestamp: Any, session_id: Any) -> List[Dict[s return findings def _format_response(self, status: str, **kwargs) -> str: - """تنسيق الرد النهائي بصيغة JSON""" response = { "status": status, "audit_time": datetime.now().isoformat(), @@ -63,17 +86,6 @@ def _format_response(self, status: str, **kwargs) -> str: return json.dumps(response, indent=2, ensure_ascii=False) def run_audit(self, dataset_id: str, table_id: str, max_rows: int = DEFAULT_MAX_ROWS) -> str: - """ - تشغيل عملية التدقيق الأمني. - - Args: - dataset_id: اسم مجموعة البيانات في BigQuery - table_id: اسم الجدول - max_rows: أقصى عدد للصفوف المفحوصة (افتراضي: 500) - - Returns: - JSON string تحتوي على نتائج التدقيق - """ try: ds = self._sanitize_identifier(dataset_id) tb = self._sanitize_identifier(table_id) @@ -91,7 +103,8 @@ def run_audit(self, dataset_id: str, table_id: str, max_rows: int = DEFAULT_MAX_ return self._format_response( "AUDIT_COMPLETE", threats_found=len(all_findings), - findings=all_findings + findings=all_findings, + patterns_used=list(self.patterns.keys()) ) except exceptions.GoogleAPIError as e: @@ -104,9 +117,6 @@ def run_audit(self, dataset_id: str, table_id: str, max_rows: int = DEFAULT_MAX_ if __name__ == "__main__": auditor = AgentSecurityAuditor(project_id="your-gcp-project-id") report = json.loads(auditor.run_audit("your_dataset", "your_table")) - print(f"Audit Status: {report['status']}") - print(f"Time: {report['audit_time']}") + print(f"Patterns Used: {report['patterns_used']}") print(f"Threats Found: {report['threats_found']}") - for f in report.get("findings", []): - print(f" - [{f['threat_type']}] {f['snippet']}") From c57ed11b63933cace68314deaf856c88cf090d7f Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Fri, 7 Aug 2026 23:12:40 +0300 Subject: [PATCH 10/19] Enhance SKILL.md for GCP Agent Security Audit Expanded the documentation for the GCP Agent Security Audit Skill, detailing its features, requirements, and usage instructions. --- skills/cloud/agent-security-audit/SKILL.md | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/skills/cloud/agent-security-audit/SKILL.md b/skills/cloud/agent-security-audit/SKILL.md index 23826a64aa..b86bc7912d 100644 --- a/skills/cloud/agent-security-audit/SKILL.md +++ b/skills/cloud/agent-security-audit/SKILL.md @@ -1,7 +1,25 @@ -# Agent Security Audit +# GCP Agent Security Audit Skill -A proactive security tool for analyzing agent interaction logs using BigQuery to detect anomalies and potential prompt injection patterns. +## Overview +This skill provides proactive security auditing for AI Agents on Google Cloud Platform (GCP). It uses BigQuery to analyze agent interaction logs, detecting prompt injection patterns, behavioral anomalies, and potential data exfiltration attempts. + +## Key Features +- **Pattern Detection:** Pre-configured SQL regex patterns to detect jailbreaks, indirect injection, and role overrides. +- **BigQuery Integration:** Uses BigQuery ML for anomaly detection and historical log analysis. +- **Real-Time Alerting:** Integrates with GCP Cloud Monitoring to notify security teams immediately via Pub/Sub. + +## Requirements +- A GCP project with BigQuery enabled. +- Agent logs streamed to a BigQuery table. +- A Service Account with the following IAM roles: + - `roles/bigquery.jobUser` + - `roles/bigquery.dataViewer` + - `roles/monitoring.metricWriter` ## Usage +Run the audit script manually using environment variables: ```bash -agent-cli run agent-security-audit --dataset_id --table_id
+export GCP_PROJECT_ID="your-project-id" +export BIGQUERY_DATASET="your-dataset" +export BIGQUERY_TABLE="agent_logs" +python audit.py From 9330bde86078cf1d4574eff69558389fe8705bf0 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Fri, 7 Aug 2026 23:46:13 +0300 Subject: [PATCH 11/19] Refactor GCP Agent Security Audit Skill Refactor GCP Agent Security Audit Skill to enhance functionality and logging. Introduce new security patterns and improve log fetching and auditing processes. --- skills/cloud/agent-security-audit/audit.py | 480 ++++++++++++++++----- 1 file changed, 372 insertions(+), 108 deletions(-) diff --git a/skills/cloud/agent-security-audit/audit.py b/skills/cloud/agent-security-audit/audit.py index 8926eae68e..d8118fb8de 100644 --- a/skills/cloud/agent-security-audit/audit.py +++ b/skills/cloud/agent-security-audit/audit.py @@ -1,122 +1,386 @@ """ -GCP Agent Security Audit Skill - Core Logic +GCP Agent Security Audit Skill + +Proactive AI Agent security auditing using: +- Google BigQuery +- BigQuery ML anomaly detection +- Cloud Monitoring / PubSub alerts """ -import os + import json import re +import logging from datetime import datetime -from typing import List, Dict, Any +from typing import Dict, List, Any from google.cloud import bigquery -from google.api_core import exceptions +from google.cloud import pubsub_v1 + + +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s %(levelname)s %(message)s" +) + class AgentSecurityAuditor: - """ - مدقق أمني استباقي لوكلاء الذكاء الاصطناعي. - يفحص سجلات BigQuery بحثاً عن أنماط الهجوم باستخدام ملفات patterns/ - """ - - DEFAULT_MAX_ROWS = 500 - SNIPPET_LENGTH = 60 - - def __init__(self, project_id: str): - self.client = bigquery.Client(project=project_id) - self.patterns = self._load_threat_patterns() - - def _load_threat_patterns(self) -> Dict[str, str]: - """تحميل أنماط التهديد من ملفات SQL الموجودة في مجلد patterns/""" - patterns_dir = os.path.join(os.path.dirname(__file__), "patterns") - patterns = {} - - if os.path.exists(patterns_dir): - for file_name in os.listdir(patterns_dir): - if file_name.endswith(".sql"): - file_path = os.path.join(patterns_dir, file_name) - try: - with open(file_path, 'r') as f: - content = f.read().strip() - if content: - pattern_name = file_name.replace(".sql", "").upper() - patterns[pattern_name] = content - except Exception: - pass - - # إذا لم يتم تحميل أي شيء، نستخدم أنماطاً افتراضية (Fallback) - if not patterns: - patterns = { - "PROMPT_INJECTION": r"(?i)(ignore\s+(all\s+)?previous\s+instructions|you\s+are\s+now\s+a\s+|system\s+prompt|reveal\s+your\s+instructions)", - "DATA_EXFILTRATION": r"(?i)(send\s+data\s+to|upload\s+to|https?://|api[_\s]?key|password)", - } - - return patterns - - def _sanitize_identifier(self, name: str) -> str: - sanitized = re.sub(r'[^a-zA-Z0-9_]', '', name) - if not sanitized: - raise ValueError(f"Invalid identifier: '{name}'") - return sanitized - - def _build_query(self, dataset: str, table: str, max_rows: int) -> str: - return f""" - SELECT interaction_log, timestamp, session_id - FROM `{dataset}.{table}` - WHERE interaction_log IS NOT NULL - LIMIT {max_rows} + + + MAX_ROWS = 10000 + + + SECURITY_PATTERNS = { + + "PROMPT_INJECTION": + r"(?i)(ignore previous instructions|ignore all previous|system prompt|developer message|reveal instructions)", + + + "JAILBREAK": + r"(?i)(jailbreak|bypass safety|disable safeguards|ignore policy)", + + + "ROLE_OVERRIDE": + r"(?i)(you are now|act as|pretend to be)", + + + "INDIRECT_PROMPT_INJECTION": + r"(?i)(hidden instruction|embedded command|retrieved document instruction|follow these instructions)", + + + "DATA_EXFILTRATION": + r"(?i)(api[_ -]?key|secret|password|token|private key|credentials)" + + } + + + + def __init__( + self, + project_id: str, + alert_topic: str = None + ): + + self.project_id = project_id + + self.bigquery = bigquery.Client( + project=project_id + ) + + self.publisher = pubsub_v1.PublisherClient() + + self.alert_topic = alert_topic + + + + # ------------------------------- + # BigQuery Logs + # ------------------------------- + + + def fetch_logs( + self, + table_id: str, + limit: int = 500 + ): + + + limit = min( + limit, + self.MAX_ROWS + ) + + + query = f""" + + SELECT * + FROM `{table_id}` + LIMIT {limit} + """ - - def _analyze_log(self, log: str, timestamp: Any, session_id: Any) -> List[Dict[str, str]]: + + + rows = self.bigquery.query( + query + ).result() + + + return [ + dict(row) + for row in rows + ] + + + + # ------------------------------- + # Threat Detection + # ------------------------------- + + + def scan_text( + self, + text: str + ): + + findings = [] - for threat_type, pattern in self.patterns.items(): - if re.search(pattern, log, re.IGNORECASE): - findings.append({ - "threat_type": threat_type, - "snippet": log[:self.SNIPPET_LENGTH] + "..." if len(log) > self.SNIPPET_LENGTH else log, - "timestamp": str(timestamp), - "session_id": str(session_id) - }) - break + + + for name, pattern in self.SECURITY_PATTERNS.items(): + + + if re.search( + pattern, + text + ): + + findings.append( + { + "type": name, + "severity": + self.severity(name) + } + ) + + return findings - - def _format_response(self, status: str, **kwargs) -> str: - response = { - "status": status, - "audit_time": datetime.now().isoformat(), - **kwargs - } - return json.dumps(response, indent=2, ensure_ascii=False) - - def run_audit(self, dataset_id: str, table_id: str, max_rows: int = DEFAULT_MAX_ROWS) -> str: - try: - ds = self._sanitize_identifier(dataset_id) - tb = self._sanitize_identifier(table_id) - - query = self._build_query(ds, tb, max_rows) - query_job = self.client.query(query) - - all_findings = [] - for row in query_job.result(): - log = row.interaction_log - timestamp = row.timestamp - session_id = row.get("session_id", "unknown") - all_findings.extend(self._analyze_log(log, timestamp, session_id)) - - return self._format_response( - "AUDIT_COMPLETE", - threats_found=len(all_findings), - findings=all_findings, - patterns_used=list(self.patterns.keys()) + + + + def audit_logs( + self, + logs + ): + + + results = [] + + + for index, log in enumerate(logs): + + + content = json.dumps( + log, + ensure_ascii=False ) - - except exceptions.GoogleAPIError as e: - return self._format_response("ERROR", message=str(e)) - except ValueError as e: - return self._format_response("ERROR", message=f"Validation error: {str(e)}") + + + issues = self.scan_text( + content + ) + + + if issues: + + results.append( + { + "row": index, + "time": + datetime.utcnow().isoformat(), + "issues": issues + } + ) + + + return results + + + + # ------------------------------- + # BigQuery ML Anomaly + # ------------------------------- + + + def anomaly_detection( + self, + table_id + ): + + + query = f""" + + SELECT * + FROM ML.DETECT_ANOMALIES( + MODEL `{table_id}_model`, + STRUCT(0.95 AS contamination) + ) + + """ + + + try: + + result = self.bigquery.query( + query + ).result() + + + return [ + dict(row) + for row in result + ] + + except Exception as e: - return self._format_response("ERROR", message=f"Unexpected error: {str(e)}") - -if __name__ == "__main__": - auditor = AgentSecurityAuditor(project_id="your-gcp-project-id") - report = json.loads(auditor.run_audit("your_dataset", "your_table")) - print(f"Audit Status: {report['status']}") - print(f"Patterns Used: {report['patterns_used']}") - print(f"Threats Found: {report['threats_found']}") + + + logging.warning( + "BigQuery ML unavailable: %s", + e + ) + + + return { + "status": + "not_configured" + } + + + + # ------------------------------- + # Save Security Report + # ------------------------------- + + + def save_report( + self, + table_id, + report + ): + + + errors = self.bigquery.insert_rows_json( + table_id, + [ + { + "timestamp": + datetime.utcnow().isoformat(), + + "report": + json.dumps(report) + } + ] + ) + + + return errors == [] + + + + # ------------------------------- + # Alerts + # ------------------------------- + + + def send_alert( + self, + message + ): + + + if not self.alert_topic: + + return + + + topic = ( + f"projects/{self.project_id}/topics/" + f"{self.alert_topic}" + ) + + + self.publisher.publish( + topic, + json.dumps(message).encode( + "utf-8" + ) + ) + + + # ------------------------------- + # Final Audit + # ------------------------------- + + + def run_audit( + self, + logs_table, + report_table=None + ): + + + logs = self.fetch_logs( + logs_table + ) + + + findings = self.audit_logs( + logs + ) + + + anomalies = self.anomaly_detection( + logs_table + ) + + + risk = ( + "HIGH" + if findings + else "LOW" + ) + + + report = { + + "generated": + datetime.utcnow().isoformat(), + + "risk": + risk, + + "findings": + findings, + + "anomalies": + anomalies + + } + + + + if report_table: + + self.save_report( + report_table, + report + ) + + + + if risk == "HIGH": + + self.send_alert( + report + ) + + + + return report + + + + @staticmethod + def severity( + name + ): + + + if name in [ + "DATA_EXFILTRATION", + "JAILBREAK" + ]: + + return "HIGH" + + + return "MEDIUM" From 3ce046926ba62874696c4ceadb860976732319d7 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Fri, 7 Aug 2026 23:58:00 +0300 Subject: [PATCH 12/19] Refactor AgentSecurityAuditor to load patterns dynamically --- skills/cloud/agent-security-audit/audit.py | 220 +++++++++++++-------- 1 file changed, 134 insertions(+), 86 deletions(-) diff --git a/skills/cloud/agent-security-audit/audit.py b/skills/cloud/agent-security-audit/audit.py index d8118fb8de..c92e4f79b7 100644 --- a/skills/cloud/agent-security-audit/audit.py +++ b/skills/cloud/agent-security-audit/audit.py @@ -7,6 +7,7 @@ - Cloud Monitoring / PubSub alerts """ +import os import json import re import logging @@ -24,57 +25,84 @@ class AgentSecurityAuditor: + """ + Security auditor for AI Agent logs. + """ MAX_ROWS = 10000 - SECURITY_PATTERNS = { + def __init__( + self, + project_id: str, + alert_topic: str = None + ): - "PROMPT_INJECTION": - r"(?i)(ignore previous instructions|ignore all previous|system prompt|developer message|reveal instructions)", + self.project_id = project_id + self.bigquery = bigquery.Client( + project=project_id + ) - "JAILBREAK": - r"(?i)(jailbreak|bypass safety|disable safeguards|ignore policy)", + self.publisher = pubsub_v1.PublisherClient() + self.alert_topic = alert_topic - "ROLE_OVERRIDE": - r"(?i)(you are now|act as|pretend to be)", + self.patterns = self.load_patterns() - "INDIRECT_PROMPT_INJECTION": - r"(?i)(hidden instruction|embedded command|retrieved document instruction|follow these instructions)", + # -------------------------------- + # Load Security Patterns + # -------------------------------- - "DATA_EXFILTRATION": - r"(?i)(api[_ -]?key|secret|password|token|private key|credentials)" - } + def load_patterns(self): + patterns = {} + path = os.path.join( + os.path.dirname(__file__), + "patterns" + ) - def __init__( - self, - project_id: str, - alert_topic: str = None - ): - self.project_id = project_id + if os.path.exists(path): - self.bigquery = bigquery.Client( - project=project_id - ) + for file in os.listdir(path): - self.publisher = pubsub_v1.PublisherClient() + if file.endswith(".sql"): - self.alert_topic = alert_topic + with open( + os.path.join(path, file), + "r", + encoding="utf-8" + ) as f: + + patterns[ + file.replace( + ".sql", + "" + ).upper() + ] = f.read().strip() + + + + if not patterns: + + logging.warning( + "No patterns found" + ) + + + return patterns - # ------------------------------- + # -------------------------------- # BigQuery Logs - # ------------------------------- + # -------------------------------- def fetch_logs( @@ -99,21 +127,21 @@ def fetch_logs( """ - rows = self.bigquery.query( + result = self.bigquery.query( query ).result() return [ dict(row) - for row in rows + for row in result ] - # ------------------------------- + # -------------------------------- # Threat Detection - # ------------------------------- + # -------------------------------- def scan_text( @@ -125,20 +153,29 @@ def scan_text( findings = [] - for name, pattern in self.SECURITY_PATTERNS.items(): + for name, pattern in self.patterns.items(): + try: - if re.search( - pattern, - text - ): + if re.search( + pattern, + text + ): - findings.append( - { - "type": name, - "severity": + findings.append( + { + "type": name, + "severity": self.severity(name) - } + } + ) + + except re.error as error: + + logging.error( + "Invalid pattern %s: %s", + name, + error ) @@ -148,16 +185,15 @@ def scan_text( def audit_logs( self, - logs + logs: List[Dict[str,Any]] ): - results = [] + findings = [] for index, log in enumerate(logs): - content = json.dumps( log, ensure_ascii=False @@ -171,28 +207,28 @@ def audit_logs( if issues: - results.append( + findings.append( { "row": index, - "time": + "timestamp": datetime.utcnow().isoformat(), "issues": issues } ) - return results + return findings - # ------------------------------- - # BigQuery ML Anomaly - # ------------------------------- + # -------------------------------- + # BigQuery ML + # -------------------------------- def anomaly_detection( self, - table_id + model_id: str ): @@ -200,8 +236,10 @@ def anomaly_detection( SELECT * FROM ML.DETECT_ANOMALIES( - MODEL `{table_id}_model`, - STRUCT(0.95 AS contamination) + MODEL `{model_id}`, + STRUCT( + 0.95 AS contamination + ) ) """ @@ -220,12 +258,11 @@ def anomaly_detection( ] - except Exception as e: - + except Exception as error: logging.warning( - "BigQuery ML unavailable: %s", - e + "BigQuery ML anomaly detection unavailable: %s", + error ) @@ -236,44 +273,49 @@ def anomaly_detection( - # ------------------------------- - # Save Security Report - # ------------------------------- + # -------------------------------- + # Save Report + # -------------------------------- def save_report( self, - table_id, - report + table_id: str, + report: dict ): + rows = [ + + { + "timestamp": + datetime.utcnow().isoformat(), + + "report": + json.dumps(report) + } + + ] + + errors = self.bigquery.insert_rows_json( table_id, - [ - { - "timestamp": - datetime.utcnow().isoformat(), - - "report": - json.dumps(report) - } - ] + rows ) - return errors == [] + return not errors - # ------------------------------- - # Alerts - # ------------------------------- + # -------------------------------- + # Alert System + # -------------------------------- def send_alert( self, - message + report ): @@ -290,21 +332,23 @@ def send_alert( self.publisher.publish( topic, - json.dumps(message).encode( - "utf-8" - ) + json.dumps( + report + ).encode("utf-8") ) - # ------------------------------- - # Final Audit - # ------------------------------- + + # -------------------------------- + # Main Audit + # -------------------------------- def run_audit( self, - logs_table, - report_table=None + logs_table: str, + report_table: str = None, + ml_model: str = None ): @@ -318,9 +362,14 @@ def run_audit( ) - anomalies = self.anomaly_detection( - logs_table - ) + anomalies = {} + + + if ml_model: + + anomalies = self.anomaly_detection( + ml_model + ) risk = ( @@ -364,7 +413,6 @@ def run_audit( ) - return report From 2cc9184e0caeffeb9163b83eea703f2cbd44b628 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:12:39 +0300 Subject: [PATCH 13/19] Enhance GCP Agent Security Audit Skill documentation Expanded the GCP Agent Security Audit Skill documentation with detailed features and examples for prompt injection, jailbreak, role override, indirect prompt injection, and data exfiltration detection. Updated requirements and usage instructions. --- skills/cloud/agent-security-audit/SKILL.md | 107 ++++++++++++++++----- 1 file changed, 85 insertions(+), 22 deletions(-) diff --git a/skills/cloud/agent-security-audit/SKILL.md b/skills/cloud/agent-security-audit/SKILL.md index b86bc7912d..8ade536271 100644 --- a/skills/cloud/agent-security-audit/SKILL.md +++ b/skills/cloud/agent-security-audit/SKILL.md @@ -1,25 +1,88 @@ # GCP Agent Security Audit Skill ## Overview -This skill provides proactive security auditing for AI Agents on Google Cloud Platform (GCP). It uses BigQuery to analyze agent interaction logs, detecting prompt injection patterns, behavioral anomalies, and potential data exfiltration attempts. - -## Key Features -- **Pattern Detection:** Pre-configured SQL regex patterns to detect jailbreaks, indirect injection, and role overrides. -- **BigQuery Integration:** Uses BigQuery ML for anomaly detection and historical log analysis. -- **Real-Time Alerting:** Integrates with GCP Cloud Monitoring to notify security teams immediately via Pub/Sub. - -## Requirements -- A GCP project with BigQuery enabled. -- Agent logs streamed to a BigQuery table. -- A Service Account with the following IAM roles: - - `roles/bigquery.jobUser` - - `roles/bigquery.dataViewer` - - `roles/monitoring.metricWriter` - -## Usage -Run the audit script manually using environment variables: -```bash -export GCP_PROJECT_ID="your-project-id" -export BIGQUERY_DATASET="your-dataset" -export BIGQUERY_TABLE="agent_logs" -python audit.py + +The `gcp-agent-security-audit` skill provides proactive security auditing capabilities for AI agents running on Google Cloud. + +It analyzes AI agent diagnostic logs stored in Google BigQuery to detect security threats, abnormal behavior, and malicious interaction patterns before they become security incidents. + +The skill helps security teams monitor AI agent activity and identify potential attacks early. + +--- + +# Features + +## Prompt Injection Detection + +Detects attempts to manipulate AI agent instructions. + +Examples: + +- Ignore previous instructions. +- Reveal system prompts. +- Modify developer instructions. +- Override agent behavior. + +--- + +## Jailbreak Detection + +Detects attempts to bypass AI safety controls. + +Examples: + +- Disable safeguards. +- Bypass security policies. +- Ignore restrictions. + +--- + +## Role Override Detection + +Detects attempts to change the intended identity or behavior of an AI agent. + +Examples: + +- You are now an unrestricted assistant. +- Act as another system. +- Ignore your original role. + +--- + +## Indirect Prompt Injection Detection + +Detects hidden malicious instructions inside external content. + +Examples: + +- Retrieved documents containing hidden commands. +- Instructions embedded inside files. +- External content attempting to control the agent. + +--- + +## Data Exfiltration Detection + +Detects attempts to expose sensitive information. + +Detects: + +- API keys +- Passwords +- Authentication tokens +- Private credentials +- Secrets + +--- + +# Architecture + +The skill uses Google Cloud native services for proactive AI agent security monitoring. + +Components: + +- Google BigQuery: Stores and analyzes AI agent diagnostic logs. +- BigQuery ML: Detects abnormal agent behavior using anomaly detection models. +- Google Cloud Pub/Sub: Sends alerts for high-risk security findings. + +Architecture flow: From e82149071af2d4e2e91d71003d1422b5090a4b81 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:16:05 +0300 Subject: [PATCH 14/19] Add SQL pattern for prompt injection detection --- skills/cloud/agent-security-audit/patterns/PROMPT_INJECTION.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 skills/cloud/agent-security-audit/patterns/PROMPT_INJECTION.sql diff --git a/skills/cloud/agent-security-audit/patterns/PROMPT_INJECTION.sql b/skills/cloud/agent-security-audit/patterns/PROMPT_INJECTION.sql new file mode 100644 index 0000000000..e33583f78d --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/PROMPT_INJECTION.sql @@ -0,0 +1 @@ +(?i)(ignore\s+(all\s+)?previous\s+instructions|ignore\s+prior\s+instructions|system\s+prompt|reveal\s+(your\s+)?instructions|developer\s+message|modify\s+instructions|override\s+instructions) From 4c8f68a15dbd52b3238d25803d68ef7b7c720e39 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:17:07 +0300 Subject: [PATCH 15/19] Add ROLE_OVERRIDE.sql for role change patterns --- skills/cloud/agent-security-audit/patterns/ROLE_OVERRIDE.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 skills/cloud/agent-security-audit/patterns/ROLE_OVERRIDE.sql diff --git a/skills/cloud/agent-security-audit/patterns/ROLE_OVERRIDE.sql b/skills/cloud/agent-security-audit/patterns/ROLE_OVERRIDE.sql new file mode 100644 index 0000000000..ba74fbc539 --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/ROLE_OVERRIDE.sql @@ -0,0 +1 @@ +(?i)(you\s+are\s+now|act\s+as|pretend\s+to\s+be|change\s+your\s+role|new\s+identity) From 18af06cc1eb75512b943991992b8f8bb6d944897 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:17:50 +0300 Subject: [PATCH 16/19] Add SQL pattern for data exfiltration detection --- skills/cloud/agent-security-audit/patterns/DATA_EXFILTRATION.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 skills/cloud/agent-security-audit/patterns/DATA_EXFILTRATION.sql diff --git a/skills/cloud/agent-security-audit/patterns/DATA_EXFILTRATION.sql b/skills/cloud/agent-security-audit/patterns/DATA_EXFILTRATION.sql new file mode 100644 index 0000000000..4638ba35ef --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/DATA_EXFILTRATION.sql @@ -0,0 +1 @@ +(?i)(api[_\s-]?key|password|secret|token|private\s+key|credentials|access\s+key|send\s+data|upload\s+data) From f9514fc84ccbcbdac8154d3d1f4666d0a37b935e Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:22:52 +0300 Subject: [PATCH 17/19] Rename indirect_injection.sql to INDIRECT_PROMPT_INJECTION.sql --- .../patterns/INDIRECT_PROMPT_INJECTION.sql | 1 + .../patterns/indirect_injection.sql | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) create mode 100644 skills/cloud/agent-security-audit/patterns/INDIRECT_PROMPT_INJECTION.sql delete mode 100644 skills/cloud/agent-security-audit/patterns/indirect_injection.sql diff --git a/skills/cloud/agent-security-audit/patterns/INDIRECT_PROMPT_INJECTION.sql b/skills/cloud/agent-security-audit/patterns/INDIRECT_PROMPT_INJECTION.sql new file mode 100644 index 0000000000..12e2c3ff74 --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/INDIRECT_PROMPT_INJECTION.sql @@ -0,0 +1 @@ +(?i)(ignore\s+above|do\s+not\s+follow|new\s+instruction|https?://|curl|wget|exfiltrate) diff --git a/skills/cloud/agent-security-audit/patterns/indirect_injection.sql b/skills/cloud/agent-security-audit/patterns/indirect_injection.sql deleted file mode 100644 index f5e06585da..0000000000 --- a/skills/cloud/agent-security-audit/patterns/indirect_injection.sql +++ /dev/null @@ -1,11 +0,0 @@ -SELECT - timestamp, - agent_id, - retrieved_documents -FROM `{PROJECT_ID}.{DATASET_ID}.{TABLE_ID}` -WHERE retrieved_documents IS NOT NULL -AND ( - REGEXP_CONTAINS(LOWER(retrieved_documents), r'ignore\s+above|do\s+not\s+follow|new\s+instruction') - OR - REGEXP_CONTAINS(LOWER(retrieved_documents), r'https?://|curl|wget|exfiltrate') -) From a9036ec00cfed9af61786f1791a496ae9115c90a Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:28:30 +0300 Subject: [PATCH 18/19] Update and rename jailbreak.sql to JAILBREAK.sql --- skills/cloud/agent-security-audit/patterns/JAILBREAK.sql | 1 + skills/cloud/agent-security-audit/patterns/jailbreak.sql | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) create mode 100644 skills/cloud/agent-security-audit/patterns/JAILBREAK.sql delete mode 100644 skills/cloud/agent-security-audit/patterns/jailbreak.sql diff --git a/skills/cloud/agent-security-audit/patterns/JAILBREAK.sql b/skills/cloud/agent-security-audit/patterns/JAILBREAK.sql new file mode 100644 index 0000000000..ba74fbc539 --- /dev/null +++ b/skills/cloud/agent-security-audit/patterns/JAILBREAK.sql @@ -0,0 +1 @@ +(?i)(you\s+are\s+now|act\s+as|pretend\s+to\s+be|change\s+your\s+role|new\s+identity) diff --git a/skills/cloud/agent-security-audit/patterns/jailbreak.sql b/skills/cloud/agent-security-audit/patterns/jailbreak.sql deleted file mode 100644 index a32993d448..0000000000 --- a/skills/cloud/agent-security-audit/patterns/jailbreak.sql +++ /dev/null @@ -1,6 +0,0 @@ -SELECT - timestamp, - agent_id, - user_input -FROM `{PROJECT_ID}.{DATASET_ID}.{TABLE_ID}` -WHERE REGEXP_CONTAINS(LOWER(user_input), r'ignore\s+(all\s+)?previous\s+instructions|you\s+are\s+now\s+a\s+|jailbreak|system\s+prompt') From c18191cf8520b5d25a5b2cd9faae17d4f32eaf50 Mon Sep 17 00:00:00 2001 From: Mohammed Ghabban <734402368n@gmail.com> Date: Sat, 8 Aug 2026 00:42:16 +0300 Subject: [PATCH 19/19] Enhance SKILL.md with security examples and architecture Updated SKILL.md to include new examples and detailed architecture flow for AI agent security monitoring. --- skills/cloud/agent-security-audit/SKILL.md | 77 +++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/skills/cloud/agent-security-audit/SKILL.md b/skills/cloud/agent-security-audit/SKILL.md index 8ade536271..8c1f6f05ca 100644 --- a/skills/cloud/agent-security-audit/SKILL.md +++ b/skills/cloud/agent-security-audit/SKILL.md @@ -19,8 +19,11 @@ Detects attempts to manipulate AI agent instructions. Examples: - Ignore previous instructions. + - Reveal system prompts. + - Modify developer instructions. + - Override agent behavior. --- @@ -32,7 +35,9 @@ Detects attempts to bypass AI safety controls. Examples: - Disable safeguards. + - Bypass security policies. + - Ignore restrictions. --- @@ -44,7 +49,9 @@ Detects attempts to change the intended identity or behavior of an AI agent. Examples: - You are now an unrestricted assistant. + - Act as another system. + - Ignore your original role. --- @@ -56,7 +63,9 @@ Detects hidden malicious instructions inside external content. Examples: - Retrieved documents containing hidden commands. + - Instructions embedded inside files. + - External content attempting to control the agent. --- @@ -68,9 +77,13 @@ Detects attempts to expose sensitive information. Detects: - API keys + - Passwords + - Authentication tokens + - Private credentials + - Secrets --- @@ -79,10 +92,70 @@ Detects: The skill uses Google Cloud native services for proactive AI agent security monitoring. -Components: +## Components - Google BigQuery: Stores and analyzes AI agent diagnostic logs. + - BigQuery ML: Detects abnormal agent behavior using anomaly detection models. + - Google Cloud Pub/Sub: Sends alerts for high-risk security findings. -Architecture flow: +## Architecture Flow + +1. The skill reads AI agent interaction logs from BigQuery. + +2. Security patterns analyze logs to detect: + + - Prompt injection. + + - Jailbreak attempts. + + - Role override attacks. + + - Indirect prompt injection. + + - Sensitive data exposure. + +3. BigQuery ML analyzes abnormal agent activity using anomaly detection models. + +4. Security findings are collected into a structured audit report. + +5. High-risk findings can trigger Google Cloud Pub/Sub alerts. + +--- + +# Security Reports + +The skill generates structured security reports containing: + +- Detection timestamp. + +- Risk level. + +- Security findings. + +- Threat categories. + +- Anomaly detection results. + +Example: + +```json + +{ + + "risk": "HIGH", + + "findings": [ + + { + + "type": "PROMPT_INJECTION", + + "severity": "MEDIUM" + + } + + ] + +}