1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodSecurityContext {
6 pub app_armor_profile: Option<crate::api::core::v1::AppArmorProfile>,
8
9 pub fs_group: Option<i64>,
15
16 pub fs_group_change_policy: Option<std::string::String>,
18
19 pub run_as_group: Option<i64>,
21
22 pub run_as_non_root: Option<bool>,
24
25 pub run_as_user: Option<i64>,
27
28 pub se_linux_change_policy: Option<std::string::String>,
40
41 pub se_linux_options: Option<crate::api::core::v1::SELinuxOptions>,
43
44 pub seccomp_profile: Option<crate::api::core::v1::SeccompProfile>,
46
47 pub supplemental_groups: Option<std::vec::Vec<i64>>,
49
50 pub supplemental_groups_policy: Option<std::string::String>,
52
53 pub sysctls: Option<std::vec::Vec<crate::api::core::v1::Sysctl>>,
55
56 pub windows_options: Option<crate::api::core::v1::WindowsSecurityContextOptions>,
58}
59
60impl crate::DeepMerge for PodSecurityContext {
61 fn merge_from(&mut self, other: Self) {
62 crate::DeepMerge::merge_from(&mut self.app_armor_profile, other.app_armor_profile);
63 crate::DeepMerge::merge_from(&mut self.fs_group, other.fs_group);
64 crate::DeepMerge::merge_from(&mut self.fs_group_change_policy, other.fs_group_change_policy);
65 crate::DeepMerge::merge_from(&mut self.run_as_group, other.run_as_group);
66 crate::DeepMerge::merge_from(&mut self.run_as_non_root, other.run_as_non_root);
67 crate::DeepMerge::merge_from(&mut self.run_as_user, other.run_as_user);
68 crate::DeepMerge::merge_from(&mut self.se_linux_change_policy, other.se_linux_change_policy);
69 crate::DeepMerge::merge_from(&mut self.se_linux_options, other.se_linux_options);
70 crate::DeepMerge::merge_from(&mut self.seccomp_profile, other.seccomp_profile);
71 crate::merge_strategies::list::atomic(&mut self.supplemental_groups, other.supplemental_groups);
72 crate::DeepMerge::merge_from(&mut self.supplemental_groups_policy, other.supplemental_groups_policy);
73 crate::merge_strategies::list::atomic(&mut self.sysctls, other.sysctls);
74 crate::DeepMerge::merge_from(&mut self.windows_options, other.windows_options);
75 }
76}
77
78impl<'de> crate::serde::Deserialize<'de> for PodSecurityContext {
79 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
80 #[allow(non_camel_case_types)]
81 enum Field {
82 Key_app_armor_profile,
83 Key_fs_group,
84 Key_fs_group_change_policy,
85 Key_run_as_group,
86 Key_run_as_non_root,
87 Key_run_as_user,
88 Key_se_linux_change_policy,
89 Key_se_linux_options,
90 Key_seccomp_profile,
91 Key_supplemental_groups,
92 Key_supplemental_groups_policy,
93 Key_sysctls,
94 Key_windows_options,
95 Other,
96 }
97
98 impl<'de> crate::serde::Deserialize<'de> for Field {
99 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
100 struct Visitor;
101
102 impl crate::serde::de::Visitor<'_> for Visitor {
103 type Value = Field;
104
105 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
106 f.write_str("field identifier")
107 }
108
109 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
110 Ok(match v {
111 "appArmorProfile" => Field::Key_app_armor_profile,
112 "fsGroup" => Field::Key_fs_group,
113 "fsGroupChangePolicy" => Field::Key_fs_group_change_policy,
114 "runAsGroup" => Field::Key_run_as_group,
115 "runAsNonRoot" => Field::Key_run_as_non_root,
116 "runAsUser" => Field::Key_run_as_user,
117 "seLinuxChangePolicy" => Field::Key_se_linux_change_policy,
118 "seLinuxOptions" => Field::Key_se_linux_options,
119 "seccompProfile" => Field::Key_seccomp_profile,
120 "supplementalGroups" => Field::Key_supplemental_groups,
121 "supplementalGroupsPolicy" => Field::Key_supplemental_groups_policy,
122 "sysctls" => Field::Key_sysctls,
123 "windowsOptions" => Field::Key_windows_options,
124 _ => Field::Other,
125 })
126 }
127 }
128
129 deserializer.deserialize_identifier(Visitor)
130 }
131 }
132
133 struct Visitor;
134
135 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
136 type Value = PodSecurityContext;
137
138 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
139 f.write_str("PodSecurityContext")
140 }
141
142 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
143 let mut value_app_armor_profile: Option<crate::api::core::v1::AppArmorProfile> = None;
144 let mut value_fs_group: Option<i64> = None;
145 let mut value_fs_group_change_policy: Option<std::string::String> = None;
146 let mut value_run_as_group: Option<i64> = None;
147 let mut value_run_as_non_root: Option<bool> = None;
148 let mut value_run_as_user: Option<i64> = None;
149 let mut value_se_linux_change_policy: Option<std::string::String> = None;
150 let mut value_se_linux_options: Option<crate::api::core::v1::SELinuxOptions> = None;
151 let mut value_seccomp_profile: Option<crate::api::core::v1::SeccompProfile> = None;
152 let mut value_supplemental_groups: Option<std::vec::Vec<i64>> = None;
153 let mut value_supplemental_groups_policy: Option<std::string::String> = None;
154 let mut value_sysctls: Option<std::vec::Vec<crate::api::core::v1::Sysctl>> = None;
155 let mut value_windows_options: Option<crate::api::core::v1::WindowsSecurityContextOptions> = None;
156
157 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
158 match key {
159 Field::Key_app_armor_profile => value_app_armor_profile = crate::serde::de::MapAccess::next_value(&mut map)?,
160 Field::Key_fs_group => value_fs_group = crate::serde::de::MapAccess::next_value(&mut map)?,
161 Field::Key_fs_group_change_policy => value_fs_group_change_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
162 Field::Key_run_as_group => value_run_as_group = crate::serde::de::MapAccess::next_value(&mut map)?,
163 Field::Key_run_as_non_root => value_run_as_non_root = crate::serde::de::MapAccess::next_value(&mut map)?,
164 Field::Key_run_as_user => value_run_as_user = crate::serde::de::MapAccess::next_value(&mut map)?,
165 Field::Key_se_linux_change_policy => value_se_linux_change_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
166 Field::Key_se_linux_options => value_se_linux_options = crate::serde::de::MapAccess::next_value(&mut map)?,
167 Field::Key_seccomp_profile => value_seccomp_profile = crate::serde::de::MapAccess::next_value(&mut map)?,
168 Field::Key_supplemental_groups => value_supplemental_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
169 Field::Key_supplemental_groups_policy => value_supplemental_groups_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
170 Field::Key_sysctls => value_sysctls = crate::serde::de::MapAccess::next_value(&mut map)?,
171 Field::Key_windows_options => value_windows_options = crate::serde::de::MapAccess::next_value(&mut map)?,
172 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
173 }
174 }
175
176 Ok(PodSecurityContext {
177 app_armor_profile: value_app_armor_profile,
178 fs_group: value_fs_group,
179 fs_group_change_policy: value_fs_group_change_policy,
180 run_as_group: value_run_as_group,
181 run_as_non_root: value_run_as_non_root,
182 run_as_user: value_run_as_user,
183 se_linux_change_policy: value_se_linux_change_policy,
184 se_linux_options: value_se_linux_options,
185 seccomp_profile: value_seccomp_profile,
186 supplemental_groups: value_supplemental_groups,
187 supplemental_groups_policy: value_supplemental_groups_policy,
188 sysctls: value_sysctls,
189 windows_options: value_windows_options,
190 })
191 }
192 }
193
194 deserializer.deserialize_struct(
195 "PodSecurityContext",
196 &[
197 "appArmorProfile",
198 "fsGroup",
199 "fsGroupChangePolicy",
200 "runAsGroup",
201 "runAsNonRoot",
202 "runAsUser",
203 "seLinuxChangePolicy",
204 "seLinuxOptions",
205 "seccompProfile",
206 "supplementalGroups",
207 "supplementalGroupsPolicy",
208 "sysctls",
209 "windowsOptions",
210 ],
211 Visitor,
212 )
213 }
214}
215
216impl crate::serde::Serialize for PodSecurityContext {
217 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
218 let mut state = serializer.serialize_struct(
219 "PodSecurityContext",
220 self.app_armor_profile.as_ref().map_or(0, |_| 1) +
221 self.fs_group.as_ref().map_or(0, |_| 1) +
222 self.fs_group_change_policy.as_ref().map_or(0, |_| 1) +
223 self.run_as_group.as_ref().map_or(0, |_| 1) +
224 self.run_as_non_root.as_ref().map_or(0, |_| 1) +
225 self.run_as_user.as_ref().map_or(0, |_| 1) +
226 self.se_linux_change_policy.as_ref().map_or(0, |_| 1) +
227 self.se_linux_options.as_ref().map_or(0, |_| 1) +
228 self.seccomp_profile.as_ref().map_or(0, |_| 1) +
229 self.supplemental_groups.as_ref().map_or(0, |_| 1) +
230 self.supplemental_groups_policy.as_ref().map_or(0, |_| 1) +
231 self.sysctls.as_ref().map_or(0, |_| 1) +
232 self.windows_options.as_ref().map_or(0, |_| 1),
233 )?;
234 if let Some(value) = &self.app_armor_profile {
235 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "appArmorProfile", value)?;
236 }
237 if let Some(value) = &self.fs_group {
238 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fsGroup", value)?;
239 }
240 if let Some(value) = &self.fs_group_change_policy {
241 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fsGroupChangePolicy", value)?;
242 }
243 if let Some(value) = &self.run_as_group {
244 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "runAsGroup", value)?;
245 }
246 if let Some(value) = &self.run_as_non_root {
247 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "runAsNonRoot", value)?;
248 }
249 if let Some(value) = &self.run_as_user {
250 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "runAsUser", value)?;
251 }
252 if let Some(value) = &self.se_linux_change_policy {
253 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "seLinuxChangePolicy", value)?;
254 }
255 if let Some(value) = &self.se_linux_options {
256 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "seLinuxOptions", value)?;
257 }
258 if let Some(value) = &self.seccomp_profile {
259 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "seccompProfile", value)?;
260 }
261 if let Some(value) = &self.supplemental_groups {
262 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "supplementalGroups", value)?;
263 }
264 if let Some(value) = &self.supplemental_groups_policy {
265 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "supplementalGroupsPolicy", value)?;
266 }
267 if let Some(value) = &self.sysctls {
268 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sysctls", value)?;
269 }
270 if let Some(value) = &self.windows_options {
271 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "windowsOptions", value)?;
272 }
273 crate::serde::ser::SerializeStruct::end(state)
274 }
275}
276
277#[cfg(feature = "schemars")]
278impl crate::schemars::JsonSchema for PodSecurityContext {
279 fn schema_name() -> std::borrow::Cow<'static, str> {
280 "io.k8s.api.core.v1.PodSecurityContext".into()
281 }
282
283 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
284 crate::schemars::json_schema!({
285 "description": "PodSecurityContext holds pod-level security attributes and common container settings. Some fields are also present in container.securityContext. Field values of container.securityContext take precedence over field values of PodSecurityContext.",
286 "type": "object",
287 "properties": {
288 "appArmorProfile": ({
289 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::AppArmorProfile>();
290 schema_obj.ensure_object().insert("description".into(), "appArmorProfile is the AppArmor options to use by the containers in this pod. Note that this field cannot be set when spec.os.name is windows.".into());
291 schema_obj
292 }),
293 "fsGroup": {
294 "description": "A special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod:\n\n1. The owning GID will be the FSGroup 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) 3. The permission bits are OR'd with rw-rw----\n\nIf unset, the Kubelet will not modify the ownership and permissions of any volume. Note that this field cannot be set when spec.os.name is windows.",
295 "type": "integer",
296 "format": "int64",
297 },
298 "fsGroupChangePolicy": {
299 "description": "fsGroupChangePolicy defines behavior of changing ownership and permission of the volume before being exposed inside Pod. This field will only apply to volume types which support fsGroup based ownership(and permissions). It will have no effect on ephemeral volume types such as: secret, configmaps and emptydir. Valid values are \"OnRootMismatch\" and \"Always\". If not specified, \"Always\" is used. Note that this field cannot be set when spec.os.name is windows.",
300 "type": "string",
301 },
302 "runAsGroup": {
303 "description": "The GID to run the entrypoint of the container process. Uses runtime default if unset. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. Note that this field cannot be set when spec.os.name is windows.",
304 "type": "integer",
305 "format": "int64",
306 },
307 "runAsNonRoot": {
308 "description": "Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.",
309 "type": "boolean",
310 },
311 "runAsUser": {
312 "description": "The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. Note that this field cannot be set when spec.os.name is windows.",
313 "type": "integer",
314 "format": "int64",
315 },
316 "seLinuxChangePolicy": {
317 "description": "seLinuxChangePolicy defines how the container's SELinux label is applied to all volumes used by the Pod. It has no effect on nodes that do not support SELinux or to volumes does not support SELinux. Valid values are \"MountOption\" and \"Recursive\".\n\n\"Recursive\" means relabeling of all files on all Pod volumes by the container runtime. This may be slow for large volumes, but allows mixing privileged and unprivileged Pods sharing the same volume on the same node.\n\n\"MountOption\" mounts all eligible Pod volumes with `-o context` mount option. This requires all Pods that share the same volume to use the same SELinux label. It is not possible to share the same volume among privileged and unprivileged Pods. Eligible volumes are in-tree FibreChannel and iSCSI volumes, and all CSI volumes whose CSI driver announces SELinux support by setting spec.seLinuxMount: true in their CSIDriver instance. Other volumes are always re-labelled recursively. \"MountOption\" value is allowed only when SELinuxMount feature gate is enabled.\n\nIf not specified and SELinuxMount feature gate is enabled, \"MountOption\" is used. If not specified and SELinuxMount feature gate is disabled, \"MountOption\" is used for ReadWriteOncePod volumes and \"Recursive\" for all other volumes.\n\nThis field affects only Pods that have SELinux label set, either in PodSecurityContext or in SecurityContext of all containers.\n\nAll Pods that use the same volume should use the same seLinuxChangePolicy, otherwise some pods can get stuck in ContainerCreating state. Note that this field cannot be set when spec.os.name is windows.",
318 "type": "string",
319 },
320 "seLinuxOptions": ({
321 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::SELinuxOptions>();
322 schema_obj.ensure_object().insert("description".into(), "The SELinux context to be applied to all containers. If unspecified, the container runtime will allocate a random SELinux context for each container. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. Note that this field cannot be set when spec.os.name is windows.".into());
323 schema_obj
324 }),
325 "seccompProfile": ({
326 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::SeccompProfile>();
327 schema_obj.ensure_object().insert("description".into(), "The seccomp options to use by the containers in this pod. Note that this field cannot be set when spec.os.name is windows.".into());
328 schema_obj
329 }),
330 "supplementalGroups": {
331 "description": "A list of groups applied to the first process run in each container, in addition to the container's primary GID and fsGroup (if specified). If the SupplementalGroupsPolicy feature is enabled, the supplementalGroupsPolicy field determines whether these are in addition to or instead of any group memberships defined in the container image. If unspecified, no additional groups are added, though group memberships defined in the container image may still be used, depending on the supplementalGroupsPolicy field. Note that this field cannot be set when spec.os.name is windows.",
332 "type": "array",
333 "items": {
334 "type": "integer",
335 "format": "int64",
336 },
337 },
338 "supplementalGroupsPolicy": {
339 "description": "Defines how supplemental groups of the first container processes are calculated. Valid values are \"Merge\" and \"Strict\". If not specified, \"Merge\" is used. (Alpha) Using the field requires the SupplementalGroupsPolicy feature gate to be enabled and the container runtime must implement support for this feature. Note that this field cannot be set when spec.os.name is windows.",
340 "type": "string",
341 },
342 "sysctls": {
343 "description": "Sysctls hold a list of namespaced sysctls used for the pod. Pods with unsupported sysctls (by the container runtime) might fail to launch. Note that this field cannot be set when spec.os.name is windows.",
344 "type": "array",
345 "items": (__gen.subschema_for::<crate::api::core::v1::Sysctl>()),
346 },
347 "windowsOptions": ({
348 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::WindowsSecurityContextOptions>();
349 schema_obj.ensure_object().insert("description".into(), "The Windows specific settings applied to all containers. If unspecified, the options within a container's SecurityContext will be used. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. Note that this field cannot be set when spec.os.name is linux.".into());
350 schema_obj
351 }),
352 },
353 })
354 }
355}