Commit 8f3b811
feat: add QEMU_ADDITIONAL_PACKAGES environment variable (#2266)
* feat: add QEMU_ADDITIONAL_PACKAGES environment variable
Add support for QEMU_ADDITIONAL_PACKAGES environment variable that allows
users to specify additional packages to install in the QEMU microVM during
initialization.
The variable accepts a comma-separated list of package names (e.g.,
"hello-wolfi,nginx-stable,strace") and passes them to microvm-init via
the kernel command line as melange.additional_packages=<list>.
Input validation prevents injection attacks by only allowing alphanumeric
characters, hyphens, underscores, commas, and dots. Invalid input is
rejected with a warning.
Usage:
QEMU_ADDITIONAL_PACKAGES=hello-wolfi,strace melange build mypackage.yaml
Note: This requires a corresponding update to microvm-init package to
read and process the melange.additional_packages kernel parameter.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
* fix: use strings.SplitSeq for modernization linter
Update to use strings.SplitSeq() instead of strings.Split() for better
efficiency with the iterator pattern in Go 1.24+.
Addresses golangci-lint modernize check.
* refactor: extract testable functions and add tests for QEMU_ADDITIONAL_PACKAGES
Addresses PR feedback from @egibs and @89luca89:
- Extract getAdditionalPackages() function for parsing env var
- Extract getPackageCacheSuffix() function for cache key generation
- Use SHA256 hash instead of truncation to avoid collisions
- Add comprehensive test coverage for both functions
- Fix variable shadowing issue
Tests verify:
- Package parsing and validation
- Security (injection prevention)
- Cache suffix generation with SHA256
- Hash determinism and collision prevention
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
* Apply suggestion from @egibs
Co-authored-by: Evan Gibler <[email protected]>
Signed-off-by: antitree <[email protected]>
* Retrieve additional packages from context
Signed-off-by: antitree <[email protected]>
* refactoring egibs changes
* fix: remove duplicate getAdditionalPackages call that shadows parameter
The merge introduced a bug where additionalPkgs parameter was being
shadowed by a local variable that called getAdditionalPackages again.
This defeats the purpose of passing the parameter and causes the
function to be called twice unnecessarily.
Remove the duplicate call to use the passed parameter correctly.
---------
Signed-off-by: antitree <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
Co-authored-by: Evan Gibler <[email protected]>1 parent 3dbccea commit 8f3b811
2 files changed
+246
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
1762 | 1764 | | |
1763 | 1765 | | |
1764 | 1766 | | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
1765 | 1771 | | |
1766 | 1772 | | |
1767 | | - | |
| 1773 | + | |
1768 | 1774 | | |
1769 | 1775 | | |
1770 | 1776 | | |
1771 | 1777 | | |
1772 | 1778 | | |
1773 | 1779 | | |
1774 | | - | |
| 1780 | + | |
1775 | 1781 | | |
1776 | 1782 | | |
1777 | 1783 | | |
| |||
1782 | 1788 | | |
1783 | 1789 | | |
1784 | 1790 | | |
1785 | | - | |
| 1791 | + | |
1786 | 1792 | | |
1787 | 1793 | | |
1788 | 1794 | | |
1789 | 1795 | | |
1790 | 1796 | | |
1791 | 1797 | | |
1792 | 1798 | | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
1793 | 1803 | | |
1794 | 1804 | | |
1795 | 1805 | | |
1796 | 1806 | | |
1797 | 1807 | | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
| 1808 | + | |
1801 | 1809 | | |
1802 | 1810 | | |
1803 | 1811 | | |
| |||
1857 | 1865 | | |
1858 | 1866 | | |
1859 | 1867 | | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
1860 | 1915 | | |
1861 | 1916 | | |
1862 | 1917 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
0 commit comments