|
| 1 | +--- |
| 2 | +id: h2 |
| 3 | +title: H2 Database - TESTING ONLY, NOT FOR PRODUCTION |
| 4 | +sidebar_label: H2 Database (Testing Only) |
| 5 | +keywords: [open source monitoring tool, H2 database, testing, not for production, security warning] |
| 6 | +--- |
| 7 | + |
| 8 | +> ⚠️ **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. |
| 9 | +
|
| 10 | +## 🔴 Security Risks - READ BEFORE USING |
| 11 | + |
| 12 | +### What is H2 Database? |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +### Why H2 Is Dangerous in Production |
| 17 | + |
| 18 | +H2 has a built-in feature called `CREATE ALIAS` that allows arbitrary Java code execution within database queries. This means: |
| 19 | + |
| 20 | +```sql |
| 21 | +-- Example of EXTREMELY dangerous H2 capability: |
| 22 | +CREATE ALIAS EXEC AS $$ |
| 23 | +String exec(String cmd) throws Exception { |
| 24 | + Runtime.getRuntime().exec(cmd); |
| 25 | + return null; |
| 26 | +} |
| 27 | +$$; |
| 28 | + |
| 29 | +-- This can execute shell commands on the server: |
| 30 | +CALL EXEC('rm -rf /important-data'); |
| 31 | +``` |
| 32 | + |
| 33 | +If your HertzBeat H2 database is accessible to malicious actors (or even unauthorized internal users), they can: |
| 34 | + |
| 35 | +- **Execute arbitrary shell commands** on the HertzBeat server |
| 36 | +- **Read any file** accessible to the HertzBeat process |
| 37 | +- **Compromise the entire server** running HertzBeat |
| 38 | +- **Access all monitoring data** including sensitive credentials |
| 39 | + |
| 40 | +📖 For complete details, read the official [H2 Security Documentation](https://h2database.com/html/security.html). |
| 41 | + |
| 42 | +### Network Exposure Risk |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## ✅ H2 is Appropriate For |
| 49 | + |
| 50 | +- **Local Development**: Quick setup for evaluating HertzBeat features |
| 51 | +- **Automated Testing**: CI/CD pipelines in isolated environments |
| 52 | +- **Demos**: Showcasing HertzBeat to stakeholders |
| 53 | +- **Learning**: Understanding HertzBeat before production deployment |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## 🚫 H2 is NOT Appropriate For |
| 58 | + |
| 59 | +- Production deployments |
| 60 | +- Multi-user environments |
| 61 | +- Systems with sensitive monitoring data |
| 62 | +- Internet-accessible HertzBeat instances |
| 63 | +- Environments requiring data persistence across restarts |
| 64 | +- High-availability setups |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## 🔒 Migrating to a Production Database |
| 69 | + |
| 70 | +For production use, migrate to one of these supported databases: |
| 71 | + |
| 72 | +### MySQL / MariaDB (Recommended for most deployments) |
| 73 | + |
| 74 | +1. Install MySQL 5.7+ or MariaDB 10.5+ |
| 75 | +2. Create a dedicated database and user: |
| 76 | + |
| 77 | +```sql |
| 78 | +CREATE DATABASE hertzbeat; |
| 79 | +CREATE USER 'hertzbeat'@'localhost' IDENTIFIED BY 'strong_password_here'; |
| 80 | +GRANT ALL PRIVILEGES ON hertzbeat.* TO 'hertzbeat'@'localhost'; |
| 81 | +FLUSH PRIVILEGES; |
| 82 | +``` |
| 83 | + |
| 84 | +3. Update `application.yml`: |
| 85 | + |
| 86 | +```yaml |
| 87 | +spring: |
| 88 | + datasource: |
| 89 | + url: jdbc:mysql://localhost:3306/hertzbeat?useUnicode=true&characterEncoding=utf-8 |
| 90 | + username: hertzbeat |
| 91 | + password: strong_password_here |
| 92 | + driver-class-name: com.mysql.cj.jdbc.Driver |
| 93 | +``` |
| 94 | +
|
| 95 | +4. Download MySQL JDBC driver and place in `ext-lib/` |
| 96 | +5. Restart HertzBeat |
| 97 | + |
| 98 | +📖 See the full [MySQL monitoring guide](./mysql.md) for setup details. |
| 99 | + |
| 100 | +### PostgreSQL (Recommended for enterprise deployments) |
| 101 | + |
| 102 | +1. Install PostgreSQL 12+ |
| 103 | +2. Create database and user: |
| 104 | + |
| 105 | +```sql |
| 106 | +CREATE USER hertzbeat WITH PASSWORD 'strong_password_here'; |
| 107 | +CREATE DATABASE hertzbeat OWNER hertzbeat; |
| 108 | +GRANT ALL PRIVILEGES ON DATABASE hertzbeat TO hertzbeat; |
| 109 | +``` |
| 110 | + |
| 111 | +3. Update `application.yml`: |
| 112 | + |
| 113 | +```yaml |
| 114 | +spring: |
| 115 | + datasource: |
| 116 | + url: jdbc:postgresql://localhost:5432/hertzbeat |
| 117 | + username: hertzbeat |
| 118 | + password: strong_password_here |
| 119 | + driver-class-name: org.postgresql.Driver |
| 120 | +``` |
| 121 | + |
| 122 | +4. Download PostgreSQL JDBC driver and place in `ext-lib/` |
| 123 | +5. Restart HertzBeat |
| 124 | + |
| 125 | +📖 See the full [PostgreSQL monitoring guide](./postgresql.md) for setup details. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## ⚙️ H2 Configuration (Testing Only) |
| 130 | + |
| 131 | +If you are using H2 for **testing purposes** in a **sandboxed environment**, the default HertzBeat configuration uses H2 with these settings: |
| 132 | + |
| 133 | +| Configuration | Default Value | Description | |
| 134 | +|--------------|---------------|-------------| |
| 135 | +| Database type | H2 | Embedded Java database | |
| 136 | +| Database file | `./data/hertzbeat` | Local file storage | |
| 137 | +| Web console | Port 8082 | H2 web management UI | |
| 138 | +| Auto-create | Enabled | Creates schema automatically | |
| 139 | + |
| 140 | +### Checking Your Current Configuration |
| 141 | + |
| 142 | +View your current database configuration in `application.yml`: |
| 143 | + |
| 144 | +```yaml |
| 145 | +spring: |
| 146 | + datasource: |
| 147 | + # H2 configuration (testing only) |
| 148 | + url: jdbc:h2:./data/hertzbeat |
| 149 | + driver-class-name: org.h2.Driver |
| 150 | +``` |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## 🛡️ If You Must Use H2 Temporarily |
| 155 | + |
| 156 | +If you absolutely must use H2 while transitioning to a production database, take these precautions: |
| 157 | + |
| 158 | +1. **Restrict Network Access**: Ensure HertzBeat is not accessible from the internet |
| 159 | +2. **Disable H2 Console**: Comment out or remove H2 console configuration |
| 160 | +3. **Firewall Rules**: Block ports 8082 and 9092 externally |
| 161 | +4. **Limit User Access**: Only trusted administrators should access HertzBeat |
| 162 | +5. **Monitor Access Logs**: Watch for unusual SQL queries |
| 163 | +6. **Plan Migration**: Set a deadline to migrate to MySQL or PostgreSQL |
| 164 | + |
| 165 | +```yaml |
| 166 | +# Disable H2 web console in application.yml: |
| 167 | +spring: |
| 168 | + h2: |
| 169 | + console: |
| 170 | + enabled: false # IMPORTANT: Disable in any non-local environment |
| 171 | +``` |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## 📋 Security Checklist Before Going to Production |
| 176 | + |
| 177 | +Before deploying HertzBeat in any non-testing environment, verify: |
| 178 | + |
| 179 | +- [ ] H2 database has been replaced with MySQL or PostgreSQL |
| 180 | +- [ ] H2 web console is disabled |
| 181 | +- [ ] Database credentials are strong and unique |
| 182 | +- [ ] Database is not directly accessible from the internet |
| 183 | +- [ ] HertzBeat is running behind a reverse proxy with SSL |
| 184 | +- [ ] Monitoring credentials are encrypted and access-controlled |
| 185 | +- [ ] Regular database backups are configured |
| 186 | + |
| 187 | +--- |
| 188 | + |
| 189 | +## 🆘 Help and Support |
| 190 | + |
| 191 | +If you need help migrating from H2 to a production database: |
| 192 | + |
| 193 | +- 📖 [HertzBeat Documentation](https://hertzbeat.apache.org/docs/) |
| 194 | +- 💬 [Apache HertzBeat Mailing List](https://lists.apache.org/list.html?dev@hertzbeat.apache.org) |
| 195 | +- 🐛 [GitHub Issues](https://github.com/apache/hertzbeat/issues) |
| 196 | +- 💡 [GitHub Discussions](https://github.com/apache/hertzbeat/discussions) |
| 197 | + |
| 198 | +--- |
| 199 | + |
| 200 | +> **Remember**: The convenience of H2 for testing comes at the cost of security. Always plan to migrate to a production-grade database before deploying HertzBeat in any real environment. |
0 commit comments