-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kata.genpolicy: never log already existing policy annotation
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...ages/by-name/kata/kata-runtime/0018-genpolicy-do-not-log-policy-annotation-in-debug.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: jmxnzo <[email protected]> | ||
Date: Mon, 9 Dec 2024 15:26:56 +0100 | ||
Subject: [PATCH] genpolicy: do not log policy annotation in debug | ||
|
||
--- | ||
src/tools/genpolicy/src/obj_meta.rs | 39 ++++++++++++++++++++++++++++- | ||
1 file changed, 38 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/src/tools/genpolicy/src/obj_meta.rs b/src/tools/genpolicy/src/obj_meta.rs | ||
index 3da75fc0ff67068af04ea98a6dfdc6989961e17c..d56545f8dc538b3660b0d75086aeb0ca802dd638 100644 | ||
--- a/src/tools/genpolicy/src/obj_meta.rs | ||
+++ b/src/tools/genpolicy/src/obj_meta.rs | ||
@@ -8,9 +8,10 @@ | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use std::collections::BTreeMap; | ||
+use std::fmt; | ||
|
||
/// See ObjectMeta in the Kubernetes API reference. | ||
-#[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||
+#[derive(Clone, Default, Serialize, Deserialize)] | ||
pub struct ObjectMeta { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub name: Option<String>, | ||
@@ -43,3 +44,39 @@ impl ObjectMeta { | ||
self.namespace.as_ref().cloned() | ||
} | ||
} | ||
+ | ||
+ | ||
+impl fmt::Debug for ObjectMeta { | ||
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
+ let mut debug_struct = f.debug_struct("ObjectMeta"); | ||
+ | ||
+ if let Some(ref name) = self.name { | ||
+ debug_struct.field("name", name); | ||
+ } | ||
+ if let Some(ref generate_name) = self.generateName { | ||
+ debug_struct.field("generateName", generate_name); | ||
+ } | ||
+ if let Some(ref labels) = self.labels { | ||
+ debug_struct.field("labels", labels); | ||
+ } | ||
+ if let Some(ref annotations) = self.annotations { | ||
+ // Process annotations: redact values longer than 100 characters | ||
+ let redacted_annotations: BTreeMap<_, _> = annotations | ||
+ .iter() | ||
+ .map(|(key, value)| { | ||
+ if value.len() > 100 { | ||
+ (key.clone(), "<redacted annotation>".to_string()) | ||
+ } else { | ||
+ (key.clone(), value.clone()) | ||
+ } | ||
+ }) | ||
+ .collect(); | ||
+ debug_struct.field("annotations", &redacted_annotations); | ||
+ } | ||
+ if let Some(ref namespace) = self.namespace { | ||
+ debug_struct.field("namespace", namespace); | ||
+ } | ||
+ | ||
+ debug_struct.finish() | ||
+ } | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters