Skip to content

Commit 9029b0e

Browse files
committed
Restrict KGL to IP module and add feature gating helper
1 parent bb0922c commit 9029b0e

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ pub use i18n::{I18n, Locale};
88
pub use build::fingerprint::{BuildFingerprint, BuildHash};
99
pub use model::telemetry::TelemetryMode;
1010
pub use model::capabilities::{CapabilitySnapshot, FeatureFlags};
11+
pub use model::modules::ModuleId;
12+
pub use model::feature_gate::feature_allowed;

src/model/feature_gate.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::config::core::CoreConfig;
2+
use crate::model::capabilities::CapabilitySnapshot;
3+
use crate::model::modules::ModuleId;
4+
5+
/// Returns true if a Korvex extra feature is allowed.
6+
///
7+
/// Enforces:
8+
/// - extras.enabled in core config must be true
9+
/// - local kill switch for "module.feature" must be enabled
10+
/// - capability snapshot must be present and allow the feature
11+
///
12+
/// For now, only ModuleId::Ip is defined.
13+
/// Example feature keys:
14+
/// "ip.whitelist"
15+
/// "ip.geo_identity"
16+
/// "ip.extended_history"
17+
pub fn feature_allowed(
18+
cfg: &CoreConfig,
19+
snapshot: Option<&CapabilitySnapshot>,
20+
module: ModuleId,
21+
feature: &str,
22+
) -> bool {
23+
let key = format!("{}.{}", module.as_str(), feature);
24+
25+
// Global or feature-level disable
26+
if !cfg.is_feature_enabled_locally(&key) {
27+
return false;
28+
}
29+
30+
let snapshot = match snapshot {
31+
Some(s) => s,
32+
None => return false,
33+
};
34+
35+
snapshot.allows(&key)
36+
}

src/model/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
pub mod telemetry;
22
pub mod capabilities;
3+
pub mod modules;
4+
pub mod feature_gate;

src/model/modules.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use serde::{Serialize, Deserialize};
2+
3+
/// Current Guardian module supported by KGL.
4+
///
5+
/// For now only the IP module is defined.
6+
/// New modules (ssh-hardening, port-surface, integrity, ...) will be added later.
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8+
#[serde(rename_all = "kebab-case")]
9+
pub enum ModuleId {
10+
/// IP module (whitelisting, geo, DNS, etc.).
11+
Ip,
12+
}
13+
14+
impl ModuleId {
15+
/// Stable identifier used in configs and capability snapshots.
16+
pub fn as_str(&self) -> &'static str {
17+
match self {
18+
ModuleId::Ip => "ip",
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)