-
-
Notifications
You must be signed in to change notification settings - Fork 167
fix: tenant id validation #1740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,7 @@ use std::{ | |||||||||||||
| num::NonZeroU32, | ||||||||||||||
| path::PathBuf, | ||||||||||||||
| str::FromStr, | ||||||||||||||
| sync::{Arc, RwLock}, | ||||||||||||||
| sync::{Arc, LazyLock, RwLock}, | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| use actix_web::http::{ | ||||||||||||||
|
|
@@ -34,6 +34,7 @@ use bytes::Bytes; | |||||||||||||
| use chrono::Utc; | ||||||||||||||
| use clap::{Parser, error::ErrorKind}; | ||||||||||||||
| use once_cell::sync::{Lazy, OnceCell}; | ||||||||||||||
| use regex::Regex; | ||||||||||||||
| use relative_path::RelativePathBuf; | ||||||||||||||
| pub use staging::StagingError; | ||||||||||||||
| use streams::StreamRef; | ||||||||||||||
|
|
@@ -102,6 +103,23 @@ pub const STREAM_EXISTS: &str = "Stream exists"; | |||||||||||||
| /// OnceCell to return metastore | ||||||||||||||
| pub static METASTORE: OnceCell<Arc<dyn Metastore>> = OnceCell::new(); | ||||||||||||||
|
|
||||||||||||||
| /// LazyLock for tenant id regex | ||||||||||||||
| pub static TENANT_ID_REGEX: LazyLock<Regex> = LazyLock::new(|| { | ||||||||||||||
| regex::RegexBuilder::new(r"^[a-zA-Z0-9][a-zA-Z0-9_-]{0,35}$") | ||||||||||||||
| .build() | ||||||||||||||
| .expect("Unable to create tenant id validation regex") | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| pub fn validate_tenant_id(tenant_id: &str) -> Result<(), String> { | ||||||||||||||
| if !TENANT_ID_REGEX.is_match(&tenant_id) { | ||||||||||||||
| return Err("tenant ID should follow regex- ^[a-zA-Z0-9][a-zA-Z0-9_-]{0,35}$".into()); | ||||||||||||||
| } | ||||||||||||||
| if tenant_id.eq(DEFAULT_TENANT) { | ||||||||||||||
| return Err(format!("tenant ID can't be {DEFAULT_TENANT}")); | ||||||||||||||
| } | ||||||||||||||
| Ok(()) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+113
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Expect every tenant-registration path to validate before registration.
rg -n -C 10 --glob '*.rs' '\b(add_tenant|validate_tenant_id)\s*\(' .Repository: parseablehq/parseable Length of output: 4063 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- add_tenant implementation ---'
sed -n '1178,1225p' src/parseable/mod.rs
printf '%s\n' '--- all add_tenant references ---'
rg -n -C 8 --glob '*.rs' '\.add_tenant\s*\(' .
printf '%s\n' '--- validation references and tenant registry writes ---'
rg -n -C 5 --glob '*.rs' 'validate_tenant_id|insert_tenant|TENANT_METADATA|tenants\.write' srcRepository: parseablehq/parseable Length of output: 1724 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- crate and Parseable API context ---'
rg -n -C 6 --glob '*.rs' 'pub struct Parseable|pub use|mod parseable|add_tenant|tenant_id' src | head -n 500
printf '%s\n' '--- all tenant registry and metadata mutations ---'
rg -n -C 8 --glob '*.rs' 'tenants\.(push|insert|extend)|TENANT_METADATA\.[A-Za-z_]+|insert_tenant\s*\(' src
printf '%s\n' '--- manifest targets ---'
rg -n -C 4 '^\[lib\]|^crate-type|^name\s*=' Cargo.tomlRepository: parseablehq/parseable Length of output: 41774 Validate tenant IDs in
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| /// For OTel log sources the telemetry_type is fully determined by the log_source. | ||||||||||||||
| /// When the user explicitly sets x-p-telemetry-type and it disagrees with the | ||||||||||||||
| /// implied type for an otel-* source, reject the request. When they don't set it, | ||||||||||||||
|
|
@@ -1260,6 +1278,8 @@ impl Parseable { | |||||||||||||
|
|
||||||||||||||
| // validate the possible presence of tenant storage metadata | ||||||||||||||
| for tenant_id in dirs.into_iter() { | ||||||||||||||
| // check if tenantID is valid | ||||||||||||||
| validate_tenant_id(&tenant_id).map_err(|e| anyhow::anyhow!(e))?; | ||||||||||||||
|
Comment on lines
+1281
to
+1282
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Validate directory names only in multi-tenant mode.
Suggested fix for tenant_id in dirs.into_iter() {
- validate_tenant_id(&tenant_id).map_err(|e| anyhow::anyhow!(e))?;
+ if is_multi_tenant {
+ validate_tenant_id(&tenant_id).map_err(|e| anyhow::anyhow!(e))?;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| if let Some(meta) = PARSEABLE | ||||||||||||||
| .metastore | ||||||||||||||
| .get_parseable_metadata(&Some(tenant_id.clone())) | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Make tenant IDs alphanumeric-only.
The pattern accepts
_and-. Values such astenant-prodandtenant_prodtherefore pass validation. This violates the PR objective. Keep the 1–36 character bound, update the error text, and checkDEFAULT_TENANTbefore the regex if its dedicated error must remain reachable.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents