|
| 1 | +--- |
| 2 | +seo: |
| 3 | + title: Architecture - ClickVault Documentation |
| 4 | + canonical: https://clickvault.emiliano-go.com/architecture |
| 5 | + robots: index,follow |
| 6 | + og: |
| 7 | + type: website |
| 8 | + title: Architecture - ClickVault Documentation |
| 9 | + description: Plugin structure |
| 10 | + url: https://clickvault.emiliano-go.com/architecture |
| 11 | + image: https://clickvault.emiliano-go.com/assets/images/og-image.png |
| 12 | + image:width: 1376 |
| 13 | + image:height: 768 |
| 14 | + image:alt: ClickVault documentation |
| 15 | + site_name: ClickVault Documentation |
| 16 | + locale: en_US |
| 17 | + twitter: |
| 18 | + card: summary_large_image |
| 19 | + title: Architecture - ClickVault Documentation |
| 20 | + description: Plugin structure |
| 21 | + image: https://clickvault.emiliano-go.com/assets/images/og-image.png |
| 22 | + image:alt: ClickVault documentation |
| 23 | + site: '@emiliano_go_' |
| 24 | + description: Plugin structure |
| 25 | + schema_jsonld: |
| 26 | + - '@context': https://schema.org |
| 27 | + '@type': WebPage |
| 28 | + name: Architecture - ClickVault Documentation |
| 29 | + url: https://clickvault.emiliano-go.com/architecture |
| 30 | + description: Plugin structure |
| 31 | + image: https://clickvault.emiliano-go.com/assets/images/og-image.png |
| 32 | + publisher: |
| 33 | + '@type': Organization |
| 34 | + name: Emiliano Gandini Outeda |
| 35 | + logo: https://clickvault.emiliano-go.com/assets/images/og-image.png |
| 36 | + - '@context': https://schema.org |
| 37 | + '@type': BreadcrumbList |
| 38 | + itemListElement: |
| 39 | + - '@type': ListItem |
| 40 | + position: 1 |
| 41 | + name: Architecture |
| 42 | + item: https://clickvault.emiliano-go.com/architecture |
| 43 | +seo_html: "<title>Architecture - ClickVault Documentation</title>\n<meta name=\"description\"\ |
| 44 | + \ content=\"Plugin structure\">\n<link rel=\"canonical\" href=\"https://clickvault.emiliano-go.com/architecture\"\ |
| 45 | + >\n<meta name=\"robots\" content=\"index,follow\">\n<meta property=\"og:type\" content=\"\ |
| 46 | + website\">\n<meta property=\"og:title\" content=\"Architecture - ClickVault Documentation\"\ |
| 47 | + >\n<meta property=\"og:description\" content=\"Plugin structure\">\n<meta property=\"\ |
| 48 | + og:url\" content=\"https://clickvault.emiliano-go.com/architecture\">\n<meta property=\"\ |
| 49 | + og:image\" content=\"https://clickvault.emiliano-go.com/assets/images/og-image.png\"\ |
| 50 | + >\n<meta property=\"og:image:width\" content=\"1376\">\n<meta property=\"og:image:height\"\ |
| 51 | + \ content=\"768\">\n<meta property=\"og:image:alt\" content=\"ClickVault documentation\"\ |
| 52 | + >\n<meta property=\"og:site_name\" content=\"ClickVault Documentation\">\n<meta\ |
| 53 | + \ property=\"og:locale\" content=\"en_US\">\n<meta name=\"twitter:card\" content=\"\ |
| 54 | + summary_large_image\">\n<meta name=\"twitter:title\" content=\"Architecture - ClickVault\ |
| 55 | + \ Documentation\">\n<meta name=\"twitter:description\" content=\"Plugin structure\"\ |
| 56 | + >\n<meta name=\"twitter:image\" content=\"https://clickvault.emiliano-go.com/assets/images/og-image.png\"\ |
| 57 | + >\n<meta name=\"twitter:image:alt\" content=\"ClickVault documentation\">\n<meta\ |
| 58 | + \ name=\"twitter:site\" content=\"@emiliano_go_\">\n<script type=\"application/ld+json\"\ |
| 59 | + >\n[\n {\n \"@context\": \"https://schema.org\",\n \"@type\": \"WebPage\"\ |
| 60 | + ,\n \"name\": \"Architecture - ClickVault Documentation\",\n \"url\": \"https://clickvault.emiliano-go.com/architecture\"\ |
| 61 | + ,\n \"description\": \"Plugin structure\",\n \"image\": \"https://clickvault.emiliano-go.com/assets/images/og-image.png\"\ |
| 62 | + ,\n \"publisher\": {\n \"@type\": \"Organization\",\n \"name\": \"\ |
| 63 | + Emiliano Gandini Outeda\",\n \"logo\": \"https://clickvault.emiliano-go.com/assets/images/og-image.png\"\ |
| 64 | + \n }\n },\n {\n \"@context\": \"https://schema.org\",\n \"@type\": \"\ |
| 65 | + BreadcrumbList\",\n \"itemListElement\": [\n {\n \"@type\": \"ListItem\"\ |
| 66 | + ,\n \"position\": 1,\n \"name\": \"Architecture\",\n \"item\"\ |
| 67 | + : \"https://clickvault.emiliano-go.com/architecture\"\n }\n ]\n }\n]\n\ |
| 68 | + </script>\n" |
| 69 | +--- |
| 70 | + |
| 71 | +# Architecture |
| 72 | + |
| 73 | +## Plugin structure |
| 74 | + |
| 75 | +ClickVault implements the Vault database plugin SDK interface |
| 76 | +(`sdk/database/dbplugin/v5`). It registers itself with Vault as plugin |
| 77 | +type `clickvault` and communicates over the plugin RPC boundary. |
| 78 | + |
| 79 | +``` |
| 80 | +┌─────────────┐ RPC ┌─────────────────────────────┐ |
| 81 | +│ Vault │ ◄─────────► │ clickvault plugin │ |
| 82 | +│ (database │ │ │ |
| 83 | +│ secrets │ │ ┌───────────────────────┐ │ |
| 84 | +│ engine) │ │ │ clickvault.go │ │ |
| 85 | +└─────────────┘ │ │ (6 interface methods)│ │ |
| 86 | + │ └───────┬───────────────┘ │ |
| 87 | + │ │ calls │ |
| 88 | + │ ┌───────▼───────────────┐ │ |
| 89 | + │ │ ddl.go │ │ |
| 90 | + │ │ (SQL construction, │ │ |
| 91 | + │ │ cluster branching) │ │ |
| 92 | + │ └───────┬───────────────┘ │ |
| 93 | + │ │ executes │ |
| 94 | + │ ┌───────▼───────────────┐ │ |
| 95 | + │ │ ClickHouse server │ │ |
| 96 | + │ └───────────────────────┘ │ |
| 97 | + └─────────────────────────────┘ |
| 98 | +``` |
| 99 | + |
| 100 | +## DDL construction |
| 101 | + |
| 102 | +All SQL is built in one place, `internal/clickvault/ddl.go`. The rest of the |
| 103 | +plugin never constructs SQL strings itself — it only calls into `ddl.go` and |
| 104 | +executes whatever statements come back. |
| 105 | + |
| 106 | +Key design decisions: |
| 107 | + |
| 108 | +- **Cluster handling is centralized.** If the connection is configured with a |
| 109 | + `cluster`, every generated statement gets `ON CLUSTER '<cluster>'` appended |
| 110 | + automatically (unless the statement already has one). Callers do not branch |
| 111 | + on cluster themselves. |
| 112 | + |
| 113 | +- **ON CLUSTER placement follows ClickHouse grammar.** It goes immediately |
| 114 | + after the entity name for `CREATE`/`ALTER`/`DROP USER`, and immediately |
| 115 | + after the verb for `GRANT`/`REVOKE`. |
| 116 | + |
| 117 | +- **SQL injection prevention.** Generated values are checked for dangerous |
| 118 | + characters (quotes, backticks, backslash, control characters) before |
| 119 | + substitution. |
| 120 | + |
| 121 | +## Concurrency |
| 122 | + |
| 123 | +`ClickvaultPlugin` holds its ClickHouse connection and config behind a single |
| 124 | +`sync.RWMutex`, so one plugin instance is safe for the concurrent calls |
| 125 | +Vault's plugin framework makes. |
| 126 | + |
| 127 | +## Error handling |
| 128 | + |
| 129 | +Every error returned from the six interface methods is wrapped with |
| 130 | +`fmt.Errorf("clickvault <Method>: %w", err)` so failures are traceable back |
| 131 | +to which call produced them. |
0 commit comments