Class: AiRootShield::EnterprisePolicyManager
- Inherits:
-
Object
- Object
- AiRootShield::EnterprisePolicyManager
- Defined in:
- lib/ai_root_shield/enterprise_policy_manager.rb
Overview
Enterprise policy management for customizable security rules and compliance
Constant Summary collapse
- DEFAULT_POLICY =
Default enterprise policy template
{ "version" => "1.0", "name" => "Default Enterprise Policy", "description" => "Standard enterprise security policy", "minimum_security_level" => 70, "compliance_rules" => { "device_requirements" => { "allow_rooted_devices" => false, "allow_jailbroken_devices" => false, "allow_emulators" => false, "require_screen_lock" => true, "minimum_os_version" => { "android" => "8.0", "ios" => "12.0" } }, "network_security" => { "allow_vpn" => true, "allow_proxy" => false, "allow_tor" => false, "require_certificate_pinning" => true, "allowed_dns_servers" => [], "blocked_dns_servers" => [] }, "application_integrity" => { "allow_debug_builds" => false, "allow_repackaged_apps" => false, "require_code_signing" => true, "allowed_certificate_issuers" => [] }, "runtime_protection" => { "enable_rasp" => true, "allow_debugging" => false, "allow_hooking_frameworks" => false, "enable_tamper_detection" => true } }, "risk_thresholds" => { "low" => 20, "medium" => 50, "high" => 70, "critical" => 90 }, "actions" => { "on_policy_violation" => "block", "on_high_risk" => "alert", "on_critical_risk" => "block", "custom_actions" => {} }, "reporting" => { "enable_audit_logs" => true, "log_level" => "info", "retention_days" => 90 } }.freeze
- VIOLATION_LEVELS =
Policy violation severity levels
%w[info warning critical].freeze
Instance Method Summary collapse
-
#audit_logs ⇒ Array<Hash>
Get audit logs.
-
#clear_compliance_cache ⇒ Object
Clear compliance cache.
-
#compliance_violations ⇒ Array<Hash>
Get compliance violations.
-
#export_policy ⇒ String
Export policy to JSON.
-
#import_policy(json_policy) ⇒ Object
Import policy from JSON.
-
#initialize(policy_config = nil) ⇒ EnterprisePolicyManager
constructor
A new instance of EnterprisePolicyManager.
-
#load_policy(policy_source = nil) ⇒ Hash
Load policy from file or use provided configuration.
-
#meets_minimum_security_level?(risk_score) ⇒ Boolean
Check if minimum security level is met.
-
#policy_configuration ⇒ Hash
Get policy configuration.
-
#policy_statistics ⇒ Hash
Get policy statistics.
-
#update_policy(new_policy) ⇒ Object
Update policy configuration.
-
#validate_compliance(scan_result) ⇒ Hash
Validate device compliance against enterprise policy.
Constructor Details
#initialize(policy_config = nil) ⇒ EnterprisePolicyManager
Returns a new instance of EnterprisePolicyManager.
68 69 70 71 72 73 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 68 def initialize(policy_config = nil) @policy = load_policy(policy_config) @violations = [] @compliance_cache = {} @audit_logs = [] end |
Instance Method Details
#audit_logs ⇒ Array<Hash>
Get audit logs
158 159 160 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 158 def audit_logs @audit_logs.dup end |
#clear_compliance_cache ⇒ Object
Clear compliance cache
163 164 165 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 163 def clear_compliance_cache @compliance_cache.clear end |
#compliance_violations ⇒ Array<Hash>
Get compliance violations
152 153 154 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 152 def compliance_violations @violations.dup end |
#export_policy ⇒ String
Export policy to JSON
169 170 171 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 169 def export_policy JSON.pretty_generate(@policy) end |
#import_policy(json_policy) ⇒ Object
Import policy from JSON
175 176 177 178 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 175 def import_policy(json_policy) policy_hash = JSON.parse(json_policy) update_policy(policy_hash) end |
#load_policy(policy_source = nil) ⇒ Hash
Load policy from file or use provided configuration
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 78 def load_policy(policy_source = nil) case policy_source when String load_policy_from_file(policy_source) when Hash merge_with_default_policy(policy_source) when nil DEFAULT_POLICY.dup else raise ArgumentError, "Invalid policy source type: #{policy_source.class}" end end |
#meets_minimum_security_level?(risk_score) ⇒ Boolean
Check if minimum security level is met
131 132 133 134 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 131 def meets_minimum_security_level?(risk_score) minimum_level = @policy["minimum_security_level"] (100 - risk_score) >= minimum_level end |
#policy_configuration ⇒ Hash
Get policy configuration
138 139 140 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 138 def policy_configuration @policy.dup end |
#policy_statistics ⇒ Hash
Get policy statistics
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 182 def policy_statistics { policy_version: @policy["version"], total_violations: @violations.size, violation_types: @violations.group_by { |v| v[:type] }.transform_values(&:size), compliance_checks: @compliance_cache.size, audit_log_entries: @audit_logs.size, last_policy_update: @audit_logs.reverse.find { |log| log[:event] == "policy_updated" }&.dig(:timestamp) } end |
#update_policy(new_policy) ⇒ Object
Update policy configuration
144 145 146 147 148 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 144 def update_policy(new_policy) @policy = merge_with_default_policy(new_policy) clear_compliance_cache log_audit_event("policy_updated", "Enterprise policy configuration updated") end |
#validate_compliance(scan_result) ⇒ Hash
Validate device compliance against enterprise policy
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ai_root_shield/enterprise_policy_manager.rb', line 94 def validate_compliance(scan_result) compliance_result = { compliant: true, violations: [], risk_assessment: {}, recommended_actions: [], policy_version: @policy["version"], validation_timestamp: Time.now.to_f } # Check device requirements compliance_result = validate_device_requirements(scan_result, compliance_result) # Check network security compliance_result = validate_network_security(scan_result, compliance_result) # Check application integrity compliance_result = validate_application_integrity(scan_result, compliance_result) # Check runtime protection compliance_result = validate_runtime_protection(scan_result, compliance_result) # Assess overall risk against thresholds compliance_result = assess_risk_thresholds(scan_result, compliance_result) # Determine final compliance status compliance_result[:compliant] = compliance_result[:violations].empty? # Log compliance check log_compliance_check(scan_result, compliance_result) compliance_result end |