mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-17 15:38:00 +00:00
genpolicy: support readonly hostpath
Set hostpath access based on volume mount readOnly value Signed-off-by: Saul Paredes <saulparedes@microsoft.com>
This commit is contained in:
parent
c2774b09dd
commit
36a4104753
@ -209,6 +209,13 @@ fn get_host_path_mount(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let access = match yaml_mount.readOnly {
|
||||||
|
Some(true) => {
|
||||||
|
debug!("setting read only access for host path mount");
|
||||||
|
"ro"
|
||||||
|
}
|
||||||
|
_ => "rw",
|
||||||
|
};
|
||||||
// TODO:
|
// TODO:
|
||||||
//
|
//
|
||||||
// - When volume.hostPath.path: /dev/ttyS0
|
// - When volume.hostPath.path: /dev/ttyS0
|
||||||
@ -220,7 +227,7 @@ fn get_host_path_mount(
|
|||||||
if !path.starts_with("/dev/") && !path.starts_with("/sys/") {
|
if !path.starts_with("/dev/") && !path.starts_with("/sys/") {
|
||||||
debug!("get_host_path_mount: calling get_shared_bind_mount");
|
debug!("get_host_path_mount: calling get_shared_bind_mount");
|
||||||
let propagation = if biderectional { "rshared" } else { "rprivate" };
|
let propagation = if biderectional { "rshared" } else { "rprivate" };
|
||||||
get_shared_bind_mount(yaml_mount, p_mounts, propagation, "rw");
|
get_shared_bind_mount(yaml_mount, p_mounts, propagation, access);
|
||||||
} else {
|
} else {
|
||||||
let dest = yaml_mount.mountPath.clone();
|
let dest = yaml_mount.mountPath.clone();
|
||||||
let type_ = "bind".to_string();
|
let type_ = "bind".to_string();
|
||||||
@ -228,7 +235,7 @@ fn get_host_path_mount(
|
|||||||
let options = vec![
|
let options = vec![
|
||||||
"rbind".to_string(),
|
"rbind".to_string(),
|
||||||
mount_option.to_string(),
|
mount_option.to_string(),
|
||||||
"rw".to_string(),
|
access.to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if let Some(policy_mount) = p_mounts.iter_mut().find(|m| m.destination.eq(&dest)) {
|
if let Some(policy_mount) = p_mounts.iter_mut().find(|m| m.destination.eq(&dest)) {
|
||||||
|
@ -27,6 +27,17 @@ spec:
|
|||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: host-empty-vol
|
- name: host-empty-vol
|
||||||
mountPath: "/host/cache"
|
mountPath: "/host/cache"
|
||||||
|
- mountPath: /tmp/results
|
||||||
|
name: hostpath-vol
|
||||||
|
- mountPath: /tmp/results-read-only
|
||||||
|
name: hostpath-vol-read-only
|
||||||
|
readOnly: true
|
||||||
volumes:
|
volumes:
|
||||||
- name: host-empty-vol
|
- name: host-empty-vol
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
|
- name: hostpath-vol
|
||||||
|
hostPath:
|
||||||
|
path: /tmp/results
|
||||||
|
- name: hostpath-vol-read-only
|
||||||
|
hostPath:
|
||||||
|
path: /tmp/results-read-only
|
Loading…
Reference in New Issue
Block a user