Security Features Quick Start
Security Features Quick Start
Overview
HeliosDB provides comprehensive security features including row-level security, column-level encryption, ABAC, and audit logging to protect sensitive data.
Key Concepts
Security Layers
- Authentication: Who are you? (User identity)
- Authorization: What can you do? (Permissions)
- Encryption: How is data protected? (Data at rest/in transit)
- Audit: Who did what? (Compliance tracking)
Quick Start
1. Enable Security Features
-- Check security statusSELECT setting, unit FROM pg_settingsWHERE name LIKE 'security%';
-- Enable column encryptionSET column_encryption_enabled = true;
-- Enable audit loggingSET audit_logging_enabled = true;2. Row-Level Security (RLS)
RLS automatically filters rows based on user context.
-- Create a sales tableCREATE TABLE sales ( id SERIAL PRIMARY KEY, salesperson VARCHAR(100), amount DECIMAL(10,2), customer VARCHAR(100));
-- Enable RLSALTER TABLE sales ENABLE ROW SECURITY;
-- Create policy: salespeople see only their own salesCREATE POLICY sales_filter ON sales FOR SELECT USING (salesperson = current_user);
-- Insert test dataINSERT INTO sales (salesperson, amount, customer) VALUES ('alice', 1000, 'Company A'), ('bob', 2000, 'Company B');
-- As 'alice', only sees alice's rowsSELECT * FROM sales; -- Returns 1 row3. Column-Level Encryption
Encrypt sensitive columns transparently.
-- Create table with encrypted columnsCREATE TABLE customers ( id SERIAL PRIMARY KEY, name VARCHAR(100), email ENCRYPTED VARCHAR(256), -- Encrypted ssn ENCRYPTED VARCHAR(11), -- Encrypted phone VARCHAR(20));
-- Insert data (encryption automatic)INSERT INTO customers (name, email, ssn, phone) VALUES ('Alice', 'alice@example.com', '123-45-6789', '555-0100');
-- Queries work transparentlySELECT * FROM customers WHERE email = 'alice@example.com';
-- Check encryption statusSELECT column_name, is_encryptedFROM information_schema.columnsWHERE table_name = 'customers';4. Attribute-Based Access Control (ABAC)
Fine-grained access based on attributes.
-- Define attributesCREATE ATTRIBUTE department VALUES ('Sales', 'Engineering', 'Finance');CREATE ATTRIBUTE region VALUES ('EMEA', 'APAC', 'Americas');
-- Create policyCREATE POLICY employee_access ON employees FOR SELECT USING ( current_attribute('department') = employees.department OR current_attribute('region') = employees.region );
-- Assign attributes to usersGRANT ATTRIBUTE department:Sales TO alice;GRANT ATTRIBUTE region:Americas TO alice;5. Audit Logging
Track all database access for compliance.
-- Enable audit for sensitive tableAUDIT SELECT, INSERT, UPDATE, DELETE ON customers;
-- View audit logsSELECT timestamp, user_name, operation, object_name, resultFROM pg_audit_logWHERE object_name = 'customers'ORDER BY timestamp DESCLIMIT 10;
-- Archive logs for complianceSELECT * FROM pg_audit_logWHERE timestamp < CURRENT_TIMESTAMP - INTERVAL '90 days'ORDER BY timestamp DESC;Common Scenarios
Scenario 1: Protect PII
-- Create table with encrypted PIICREATE TABLE users ( id SERIAL PRIMARY KEY, username VARCHAR(100), email ENCRYPTED VARCHAR(256), phone ENCRYPTED VARCHAR(20), ssn ENCRYPTED VARCHAR(11));
-- Only data owners can see full SSNGRANT SELECT ON users TO data_owner;Scenario 2: Department-Level Access
-- Each user sees only their department's dataCREATE POLICY department_isolation ON orders USING (department_id = current_department());
-- Engineering sees engineering orders-- Sales sees sales orders-- No cross-department visibilityScenario 3: Compliance Audit Trail
-- All changes logged automaticallyAUDIT ALL ON customers, orders, payments;
-- Generate compliance reportSELECT DATE(timestamp) as audit_date, COUNT(*) as total_operations, COUNT(DISTINCT user_name) as unique_usersFROM pg_audit_logGROUP BY DATE(timestamp)ORDER BY audit_date DESC;Performance Considerations
- Encryption Overhead: ~5-10% depending on algorithm
- RLS Overhead: Minimal if policies are simple
- Audit Logging: Adds I/O but can be batched
-- Monitor performance impactSELECT query, mean_time, callsFROM pg_stat_statementsWHERE query LIKE '%encrypted%'ORDER BY mean_time DESC;Security Best Practices
-
Encryption Keys Management
-- Store keys securely (use external KMS)SET encryption_key = 'aws:kms:arn:...'; -
Least Privilege Access
-- Grant minimal required permissionsGRANT SELECT (customer_id, order_date) ON orders TO analyst; -
Regular Audits
-- Schedule audit reviewSELECT COUNT(*) FROM pg_audit_logWHERE timestamp > NOW() - INTERVAL '1 day'; -
Strong Authentication
-- Require strong passwordsALTER SYSTEM SET password_min_length = 12;ALTER SYSTEM SET password_complexity = 'strong';
Compliance Frameworks
- GDPR: Column encryption + RLS + Audit
- HIPAA: Full encryption + RLS + Audit logging
- PCI DSS: Column encryption for cards
- SOC 2: Comprehensive audit trail
- ISO 27001: Access control policies
Troubleshooting
Q: RLS not working?
A: Ensure table security is enabled and policies are defined.
Q: Performance degradation after encryption?
A: Monitor with pg_stat_statements and optimize key management.
Q: Audit logs growing too fast?
A: Archive old logs and adjust audit scope.
Next Steps
- Read
/docs/features/packages/30-security-readme.mdfor full feature list - Review
/docs/features/packages/31-security-column-encryption.mdfor encryption details - Check encryption quick start:
/docs/features/encryption/COLUMN_ENCRYPTION_QUICK_START.md
Related Features
- Backup & Encryption:
/docs/guides/user/BACKUP_ENCRYPTION_CONSUMER_PROTECTION_GUIDE.md - Compliance Guide:
/docs/guides/user/BACKUP_ENCRYPTION_REGULATORY_COMPLIANCE_MATRIX.md - Security Hardening:
/docs/guides/user/SECURITY_HARDENING_V7.md
Document Version: 1.0 Last Updated: December 30, 2025 Audience: Database administrators, security engineers Reading Time: 10 minutes