H2 Database - TESTING ONLY, NOT FOR PRODUCTION
⚠️ CRITICAL SECURITY WARNING: H2 Database is NOT suitable for production environments. It is provided for local testing and development purposes only. Using H2 in production exposes your server to serious security vulnerabilities. Please read this page carefully before using H2 with HertzBeat.
🔴 Security Risks - READ BEFORE USING
What is H2 Database?
H2 is an open-source Java SQL database. HertzBeat ships with H2 as its default embedded database to enable quick testing and evaluation without requiring a separate database installation.
Why H2 Is Dangerous in Production
H2 has a built-in feature called CREATE ALIAS that allows arbitrary Java code execution within database queries. This means:
-- Example of EXTREMELY dangerous H2 capability:
CREATE ALIAS EXEC AS $$
String exec(String cmd) throws Exception {
Runtime.getRuntime().exec(cmd);
return null;
}
$$;
-- This can execute shell commands on the server:
CALL EXEC('rm -rf /important-data');
If your HertzBeat H2 database is accessible to malicious actors (or even unauthorized internal users), they can:
- Execute arbitrary shell commands on the HertzBeat server
- Read any file accessible to the HertzBeat process
- Compromise the entire server running HertzBeat
- Access all monitoring data including sensitive credentials
📖 For complete details, read the official H2 Security Documentation.
Network Exposure Risk
H2 can run in server mode, potentially exposing a database management interface on the network. By default, H2 uses ports 8082 (web console) and 9092 (TCP server). If these are accessible externally, any user can connect directly to your database.
✅ H2 is Appropriate For
- Local Development: Quick setup for evaluating HertzBeat features
- Automated Testing: CI/CD pipelines in isolated environments
- Demos: Showcasing HertzBeat to stakeholders
- Learning: Understanding HertzBeat before production deployment
🚫 H2 is NOT Appropriate For
- Production deployments
- Multi-user environments
- Systems with sensitive monitoring data
- Internet-accessible HertzBeat instances
- Environments requiring data persistence across restarts
- High-availability setups
🔒 Migrating to a Production Database
For production use, migrate to one of these supported databases:
MySQL / MariaDB (Recommended for most deployments)
-
Install MySQL 5.7+ or MariaDB 10.5+
-
Create a dedicated database and user:
CREATE DATABASE hertzbeat;
CREATE USER 'hertzbeat'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON hertzbeat.* TO 'hertzbeat'@'localhost';
FLUSH PRIVILEGES; -
Update
application.yml:spring:
datasource:
url: jdbc:mysql://localhost:3306/hertzbeat?useUnicode=true&characterEncoding=utf-8
username: hertzbeat
password: strong_password_here
driver-class-name: com.mysql.cj.jdbc.Driver -
Download MySQL JDBC driver and place in
ext-lib/ -
Restart HertzBeat