@@ -1041,110 +1041,6 @@ def _gather_security_config(conn, manager):
10411041 return security_info
10421042
10431043
1044- def _generate_security_report_llm (client , security_info ):
1045- """
1046- Use the LLM to analyze the security configuration and generate a report.
1047- """
1048- from pgadmin .llm .models import Message
1049-
1050- # Build the system prompt
1051- system_prompt = (
1052- "You are a PostgreSQL security expert. Your task is to analyze "
1053- "the security configuration of a PostgreSQL database server and "
1054- "generate a comprehensive security report in Markdown format.\n \n "
1055- "Focus ONLY on server-level security configuration, not database "
1056- "objects or data.\n \n "
1057- "IMPORTANT: Do NOT include a report title, header block, or "
1058- "generation date at the top of your response. The title and "
1059- "metadata are added separately by the application. Start "
1060- "directly with the Executive Summary section.\n \n "
1061- "The report should include:\n "
1062- "1. **Executive Summary** - Brief overview of the security posture\n "
1063- "2. **Critical Issues** - Vulnerabilities needing "
1064- "immediate attention\n "
1065- "3. **Warnings** - Important security concerns to be addressed\n "
1066- "4. **Recommendations** - Best practices to improve security\n "
1067- "5. **Configuration Review** - Analysis of key security settings\n \n "
1068- "Use severity indicators:\n "
1069- "- 🔴 Critical - Immediate action required\n "
1070- "- 🟠 Warning - Should be addressed soon\n "
1071- "- 🟡 Advisory - Recommended improvement\n "
1072- "- 🟢 Good - Configuration is secure\n \n "
1073- "Be specific and actionable in your recommendations. Include the "
1074- "current setting values when discussing issues. Format the output "
1075- "as well-structured Markdown."
1076- )
1077-
1078- # Build the user message with the security configuration
1079- settings_json = json .dumps (
1080- security_info .get ('settings' , []), indent = 2 , default = str
1081- )
1082- hba_json = json .dumps (
1083- security_info .get ('hba_rules' , []), indent = 2 , default = str
1084- )
1085- superusers_json = json .dumps (
1086- security_info .get ('superusers' , []), indent = 2 , default = str
1087- )
1088- privileged_json = json .dumps (
1089- security_info .get ('privileged_roles' , []), indent = 2 , default = str
1090- )
1091- no_expiry_json = json .dumps (
1092- security_info .get ('roles_no_expiry' , []), indent = 2 , default = str
1093- )
1094- extensions_json = json .dumps (
1095- security_info .get ('extensions' , []), indent = 2 , default = str
1096- )
1097-
1098- user_message = f"""Please analyze this PostgreSQL server security config.
1099-
1100- ## Server Information
1101- - Server Version: { security_info .get ('server_version' , 'Unknown' )}
1102-
1103- ## Security Settings
1104- ```json
1105- { settings_json }
1106- ```
1107-
1108- ## pg_hba.conf Rules
1109- { security_info .get ('hba_note' , '' )}
1110- ```json
1111- { hba_json }
1112- ```
1113-
1114- ## Superuser Roles
1115- ```json
1116- { superusers_json }
1117- ```
1118-
1119- ## Roles with Special Privileges
1120- ```json
1121- { privileged_json }
1122- ```
1123-
1124- ## Login Roles Without Password Expiry
1125- ```json
1126- { no_expiry_json }
1127- ```
1128-
1129- ## Installed Extensions
1130- ```json
1131- { extensions_json }
1132- ```
1133-
1134- Generate a comprehensive security report analyzing this configuration."""
1135-
1136- # Call the LLM
1137- messages = [Message .user (user_message )]
1138- response = client .chat (
1139- messages = messages ,
1140- system_prompt = system_prompt ,
1141- max_tokens = 4096 ,
1142- temperature = 0.3 # Lower temperature for more consistent analysis
1143- )
1144-
1145- return response .content
1146-
1147-
11481044# =============================================================================
11491045# Database Security Report
11501046# =============================================================================
0 commit comments