@@ -13,6 +13,8 @@ use cap_std_ext::cap_std;
13
13
use cap_std_ext:: cap_std:: fs:: MetadataExt ;
14
14
use cap_std_ext:: dirext:: CapStdExtDirExt as _;
15
15
use fn_error_context:: context;
16
+ use indoc:: indoc;
17
+ use serde:: Serialize ;
16
18
17
19
/// Reference to embedded default baseimage content that should exist.
18
20
const BASEIMAGE_REF : & str = "usr/share/doc/bootc/baseimage/base" ;
@@ -51,7 +53,8 @@ impl LintError {
51
53
type LintFn = fn ( & Dir ) -> LintResult ;
52
54
53
55
/// The classification of a lint type.
54
- #[ derive( Debug ) ]
56
+ #[ derive( Debug , Serialize ) ]
57
+ #[ serde( rename_all = "kebab-case" ) ]
55
58
enum LintType {
56
59
/// If this fails, it is known to be fatal - the system will not install or
57
60
/// is effectively guaranteed to fail at runtime.
@@ -60,51 +63,89 @@ enum LintType {
60
63
Warning ,
61
64
}
62
65
66
+ #[ derive( Debug , Serialize ) ]
67
+ #[ serde( rename_all = "kebab-case" ) ]
63
68
struct Lint {
64
69
name : & ' static str ,
70
+ #[ serde( rename = "type" ) ]
65
71
ty : LintType ,
72
+ #[ serde( skip) ]
66
73
f : LintFn ,
74
+ description : & ' static str ,
67
75
}
68
76
69
77
const LINTS : & [ Lint ] = & [
70
78
Lint {
71
79
name : "var-run" ,
72
80
ty : LintType :: Fatal ,
73
81
f : check_var_run,
82
+ description : "Check for /var/run being a physical directory; this is always a bug." ,
74
83
} ,
75
84
Lint {
76
85
name : "kernel" ,
77
86
ty : LintType :: Fatal ,
78
87
f : check_kernel,
88
+ description : indoc ! { r#"
89
+ Check for multiple kernels, i.e. multiple directories of the form /usr/lib/modules/$kver.
90
+ Only one kernel is supported in an image.
91
+ "# } ,
79
92
} ,
80
93
Lint {
81
94
name : "bootc-kargs" ,
82
95
ty : LintType :: Fatal ,
83
96
f : check_parse_kargs,
97
+ description : "Verify syntax of /usr/lib/bootc/kargs.d." ,
84
98
} ,
85
99
Lint {
86
100
name : "etc-usretc" ,
87
101
ty : LintType :: Fatal ,
88
102
f : check_usretc,
103
+ description : indoc ! { r#"
104
+ Verify that only one of /etc or /usr/etc exist. You should only have /etc
105
+ in a container image. It will cause undefined behavior to have both /etc
106
+ and /usr/etc.
107
+ "# } ,
89
108
} ,
90
109
Lint {
91
110
// This one can be lifted in the future, see https://github.com/containers/bootc/issues/975
92
111
name : "utf8" ,
93
112
ty : LintType :: Fatal ,
94
113
f : check_utf8,
114
+ description : indoc ! { r#"
115
+ Check for non-UTF8 filenames. Currently, the ostree backend of bootc only supports
116
+ UTF-8 filenames. Non-UTF8 filenames will cause a fatal error.
117
+ "# } ,
95
118
} ,
96
119
Lint {
97
120
name : "baseimage-root" ,
98
121
ty : LintType :: Fatal ,
99
122
f : check_baseimage_root,
123
+ description : indoc ! { r#"
124
+ Check that expected files are present in the root of the filesystem; such
125
+ as /sysroot and a composefs configuration for ostree. More in
126
+ <https://containers.github.io/bootc/bootc-images.html#standard-image-content>.
127
+ "# } ,
100
128
} ,
101
129
Lint {
102
130
name : "var-log" ,
103
131
ty : LintType :: Warning ,
104
132
f : check_varlog,
133
+ description : indoc ! { r#"
134
+ Check for non-empty regular files in `/var/log`. It is often undesired
135
+ to ship log files in container images. Log files in general are usually
136
+ per-machine state in `/var`. Additionally, log files often include
137
+ timestamps, causing unreproducible container images, and may contain
138
+ sensitive build system information.
139
+ "# } ,
105
140
} ,
106
141
] ;
107
142
143
+ pub ( crate ) fn lint_list ( output : impl std:: io:: Write ) -> Result < ( ) > {
144
+ // Dump in yaml format by default, it's readable enough
145
+ serde_yaml:: to_writer ( output, LINTS ) ?;
146
+ Ok ( ( ) )
147
+ }
148
+
108
149
/// check for the existence of the /var/run directory
109
150
/// if it exists we need to check that it links to /run if not error
110
151
/// if it does not exist error.
@@ -522,4 +563,12 @@ mod tests {
522
563
check_baseimage_root ( & td) . unwrap ( ) . unwrap ( ) ;
523
564
Ok ( ( ) )
524
565
}
566
+
567
+ #[ test]
568
+ fn test_list ( ) {
569
+ let mut r = Vec :: new ( ) ;
570
+ lint_list ( & mut r) . unwrap ( ) ;
571
+ let lints: Vec < serde_yaml:: Value > = serde_yaml:: from_slice ( & r) . unwrap ( ) ;
572
+ assert_eq ! ( lints. len( ) , LINTS . len( ) ) ;
573
+ }
525
574
}
0 commit comments