Skip to content

Commit 5e20ee4

Browse files
added configuring of device mount permissions in udev discovery handler #726 (#737)
* added configuring of device mount permissions in udev discovery handler #726 Signed-off-by: Marcel Bindseil <[email protected]> * incremented version Signed-off-by: Marcel Bindseil <[email protected]> * formatting Signed-off-by: Marcel Bindseil <[email protected]> * fixed version Signed-off-by: Marcel Bindseil <[email protected]> * updated helm chart version Signed-off-by: Marcel Bindseil <[email protected]> * updated rust version Signed-off-by: Marcel Bindseil <[email protected]> * updated rust version to 1.84 Signed-off-by: Marcel Bindseil <[email protected]> * fixed default for permissions Signed-off-by: Marcel Bindseil <[email protected]> * added default func for permissions Signed-off-by: Marcel Bindseil <[email protected]> * updated rust version to 1.81 Signed-off-by: Marcel Bindseil <[email protected]> * Update discovery-handlers/udev/src/discovery_handler.rs Co-authored-by: Kate Goldenring <[email protected]> Signed-off-by: Marcel Bindseil <[email protected]> * added unit test and added dependencies Signed-off-by: Marcel Bindseil <[email protected]> * test for permissions Signed-off-by: Marcel Bindseil <[email protected]> * removed unused var Signed-off-by: Marcel Bindseil <[email protected]> * restructured test Signed-off-by: Marcel Bindseil <[email protected]> * fixed test Signed-off-by: Marcel Bindseil <[email protected]> * added default permissions for lint files Signed-off-by: Marcel Bindseil <[email protected]> * signoff Signed-off-by: Marcel Bindseil <[email protected]> Signed-off-by: Marcel Bindseil <[email protected]> * removed panic Signed-off-by: Marcel Bindseil <[email protected]> --------- Signed-off-by: Marcel Bindseil <[email protected]> Co-authored-by: Kate Goldenring <[email protected]>
1 parent 8e5b3ab commit 5e20ee4

15 files changed

+79
-27
lines changed

.github/workflows/check-rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Rust install
3434
uses: dtolnay/rust-toolchain@master
3535
with:
36-
toolchain: 1.79.0
36+
toolchain: 1.81.0
3737
components: clippy, rustfmt
3838
- name: Install Linux requirements
3939
# TODO: When ubuntu-latest gets updated to >= 23.04 replace the wget+unzip with just protobuf-compiler in apt

.github/workflows/run-tarpaulin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616

1717
env:
1818
CARGO_TERM_COLOR: always
19-
CARGO_VERSION: 1.79.0
19+
CARGO_VERSION: 1.81.0
2020

2121
jobs:
2222
build:

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ members = [
2323
resolver = "2"
2424

2525
[workspace.package]
26-
version = "0.13.9"
26+
version = "0.13.10"
2727
edition = "2021"
2828
license = "Apache-2.0"
2929
homepage = "https://docs.akri.sh/"
3030
repository = "https://github.com/project-akri/akri"
31-
rust-version = "1.79"
31+
rust-version = "1.81"
3232
authors = ["The Akri Team"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p align="center"><img src="https://github.com/project-akri/akri-docs/blob/main/art/logo-horizontal/akri-logo-horizontal-light.svg" alt="Akri Logo" width="300"></p>
22

33
[![Slack channel #akri](https://img.shields.io/badge/slack-akri-blueviolet.svg?logo=slack)](https://kubernetes.slack.com/messages/akri)
4-
[![Rust Version](https://img.shields.io/badge/rustc-1.79.0-blue.svg)](https://blog.rust-lang.org/2023/03/31/Rust-1.79.0.html)
4+
[![Rust Version](https://img.shields.io/badge/rustc-1.81.0-blue.svg)](https://blog.rust-lang.org/2025/01/09/Rust-1.81.0.html)
55
[![Kubernetes Version](https://img.shields.io/badge/kubernetes-≥%201.16-blue.svg)](https://kubernetes.io/)
66
[![codecov](https://codecov.io/gh/project-akri/akri/branch/main/graph/badge.svg?token=V468HO7CDE)](https://codecov.io/gh/project-akri/akri)
77
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5339/badge)](https://bestpractices.coreinfrastructure.org/projects/5339)

build/containers/Dockerfile.rust

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx
22

3-
FROM --platform=$BUILDPLATFORM rust:1.79-slim-bookworm AS build
3+
FROM --platform=$BUILDPLATFORM rust:1.81-slim-bookworm AS build
44
RUN rustup component add rustfmt
55
RUN apt-get update && apt-get install -y clang lld protobuf-compiler pkg-config mmdebstrap wget
66
COPY --from=xx / /

build/setup.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ then
2323
if [ -x "$(command -v sudo)" ];
2424
then
2525
echo "Install rustup"
26-
sudo curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.79.0
26+
sudo curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.81.0
2727
else
2828
echo "Install rustup"
29-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.79.0
29+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.81.0
3030
fi
3131
else
3232
echo "Found rustup"

deployment/helm/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 0.13.9
19+
version: 0.13.10
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to
2323
# follow Semantic Versioning. They should reflect the version the application is using.
24-
appVersion: 0.13.9
24+
appVersion: 0.13.10

deployment/helm/templates/udev-configuration.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ spec:
1010
groupRecursive: {{ .Values.udev.configuration.discoveryDetails.groupRecursive }}
1111
udevRules:
1212
{{- required "Please set at least one udev rule with `--set udev.configuration.discoveryDetails.udevRules[0]==\"<udev rule>\"' to specify what you want discovered. See the udev Configuration document at https://docs.akri.sh/discovery-handlers/udev for more information." .Values.udev.configuration.discoveryDetails.udevRules | toYaml | nindent 6 }}
13+
permissions: {{ .Values.udev.configuration.discoveryDetails.permissions }}
1314
{{- if or .Values.udev.configuration.brokerPod.image.repository .Values.udev.configuration.brokerJob.image.repository }}
1415
{{- /* Only add brokerSpec if a broker image is provided */}}
1516
brokerSpec:

deployment/helm/values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,9 @@ udev:
714714
# udevRules is the list of udev rules used to find instances created as a result of
715715
# applying this udev configuration
716716
udevRules:
717+
# permissions is the list of Cgroups permissions of the device
718+
# combination of r (read), w (write), m (modify)
719+
permissions: rwm
717720
# capacity is the capacity for any instances created as a result of
718721
# applying this udev configuration
719722
capacity: 1

discovery-handlers/udev/src/discovery_handler.rs

+47-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use akri_discovery_utils::discovery::{
1212
};
1313
use async_trait::async_trait;
1414
use log::{error, info, trace};
15+
use serde::{de, Deserialize, Deserializer};
1516
use std::collections::{HashMap, HashSet};
1617
use std::time::Duration;
1718
use tokio::sync::mpsc;
@@ -30,6 +31,34 @@ pub struct UdevDiscoveryDetails {
3031

3132
#[serde(default)]
3233
pub group_recursive: bool,
34+
35+
#[serde(default = "default_permissions")]
36+
#[serde(deserialize_with = "validate_permissions")]
37+
pub permissions: String,
38+
}
39+
40+
// Validate the permissible set of cgroups `permissions`
41+
fn validate_permissions<'de, D>(deserializer: D) -> Result<String, D::Error>
42+
where
43+
D: Deserializer<'de>,
44+
{
45+
let value: String = Deserialize::deserialize(deserializer)?;
46+
47+
// Validating that the string only contains allowed combinations of 'r', 'w', 'm'
48+
let valid_permissions = ["r", "w", "m", "rw", "rm", "rwm", "wm"];
49+
if valid_permissions.contains(&value.as_str()) {
50+
Ok(value)
51+
} else {
52+
Err(de::Error::invalid_value(
53+
de::Unexpected::Str(&value),
54+
&"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')",
55+
))
56+
}
57+
}
58+
59+
/// Default permissions for devices
60+
fn default_permissions() -> String {
61+
"rwm".to_string()
3362
}
3463

3564
/// `DiscoveryHandlerImpl` discovers udev instances by parsing the udev rules in `discovery_handler_config.udev_rules`.
@@ -105,7 +134,7 @@ impl DiscoveryHandler for DiscoveryHandlerImpl {
105134
device_specs.push(DeviceSpec {
106135
container_path: devnode.clone(),
107136
host_path: devnode,
108-
permissions: "rwm".to_string(),
137+
permissions: discovery_handler_config.permissions.clone(),
109138
})
110139
}
111140
}
@@ -178,7 +207,8 @@ mod tests {
178207
let udev_dh_config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap();
179208
assert!(udev_dh_config.udev_rules.is_empty());
180209
let serialized = serde_json::to_string(&udev_dh_config).unwrap();
181-
let expected_deserialized = r#"{"udevRules":[],"groupRecursive":false}"#;
210+
let expected_deserialized =
211+
r#"{"udevRules":[],"groupRecursive":false,"permissions":"rwm"}"#;
182212
assert_eq!(expected_deserialized, serialized);
183213
}
184214

@@ -187,9 +217,24 @@ mod tests {
187217
let yaml = r#"
188218
udevRules:
189219
- 'KERNEL=="video[0-9]*"'
220+
permissions: rwm
190221
"#;
191222
let udev_dh_config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap();
192223
assert_eq!(udev_dh_config.udev_rules.len(), 1);
193224
assert_eq!(&udev_dh_config.udev_rules[0], "KERNEL==\"video[0-9]*\"");
225+
assert_eq!(&udev_dh_config.permissions, "rwm");
226+
}
227+
228+
#[test]
229+
fn test_deserialize_discovery_details_permissions_invalid() {
230+
let yaml = r#"
231+
udevRules:
232+
- 'KERNEL=="video[0-9]*"'
233+
permissions: xyz
234+
"#;
235+
match deserialize_discovery_details::<UdevDiscoveryDetails>(yaml) {
236+
Ok(_) => panic!("Expected error parsing invalid permissions"),
237+
Err(e) => assert!(e.to_string().contains("a valid permission combination")),
238+
}
194239
}
195240
}

test/helm-lint-values-jobs.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ udev:
2222
discoveryDetails:
2323
udevRules:
2424
- 'KERNEL=="video[0-9]*"'
25+
permissions: "rwm"
2526
brokerJob:
2627
image:
2728
repository: "busybox"

test/helm-lint-values.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ udev:
2222
groupRecursive: true
2323
udevRules:
2424
- 'KERNEL=="video[0-9]*"'
25+
permissions: "rwm"
2526
brokerPod:
2627
image:
2728
repository: "nginx"

test/yaml/akri-udev-video-configuration.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
discoveryDetails: |+
99
udevRules:
1010
- 'KERNEL=="video[0-9]*"'
11+
permissions: "rwm"
1112
brokerSpec:
1213
brokerPodSpec:
1314
containers:

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.13.9
1+
0.13.10

0 commit comments

Comments
 (0)