1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ImageError {
#[error("invalid image reference format: {0:?}")]
InvalidReferenceFormat(String),
#[error("storage io error: {0}")]
Storage(#[from] std::io::Error),
#[error("json error: {0}")]
JSON(#[from] serde_json::Error),
#[error("asynchronous task failed during image preparation")]
TaskJoin(#[from] tokio::task::JoinError),
#[error("asynchronous image hashing task failed during image preparation")]
ByteChannelError(#[from] std::sync::mpsc::SendError<bytes::Bytes>),
#[error("network request error: {0}")]
NetworkRequest(#[from] reqwest::Error),
#[error("string in image configuration contained internal nul byte")]
NulStringError(#[from] std::ffi::NulError),
#[error("registry server is not allowed by the current configuration: {0}")]
RegistryNotAllowed(crate::image::Registry),
#[error("tar file format error")]
TARFileError,
#[error("virtual filesystem error while preparing image: {0}")]
ImageVFSError(#[from] VFSError),
#[error("data just written to the cache is missing")]
StorageMissingAfterInsert,
#[error("i/o errors occurred, the content digest is not valid")]
ContentDigestIOError,
#[error("we are in offline mode, but a download was requested")]
DownloadInOfflineMode,
#[error("can't determine where to cache image files")]
NoDefaultCacheDir,
#[error("only v2 image manifests are supported")]
UnsupportedManifestType,
#[error("unsupported type for runtime config, {0:?}")]
UnsupportedRuntimeConfigType(String),
#[error("unsupported type for image layer, {0:?}")]
UnsupportedLayerType(String),
#[error("invalid content type string, {0:?}")]
InvalidContentType(String),
#[error("unexpected content size")]
UnexpectedContentSize,
#[error("unable to locate decompressed layers by content hash")]
UnexpectedDecompressedLayerContent,
#[error("unsupported type for rootfs in image config, {0:?}")]
UnsupportedRootFilesystemType(String),
#[error("insecure configuration; refusing to run a manifest downloaded over HTTP with no content digest")]
InsecureManifest,
#[error("registry server requested an unsupported type of authentication: {0:?}")]
UnsupportedAuthentication(String),
#[error("calculated digest of downloaded content is not what we asked for, expected {expected}, found {found}")]
ContentDigestMismatch {
expected: crate::image::ContentDigest,
found: crate::image::ContentDigest,
},
}
#[derive(Error, Debug)]
pub enum RuntimeError {
#[error("io error: {0}")]
IOError(#[from] std::io::Error),
#[error("protocol error: {0}")]
ProtocolError(#[from] crate::sand::protocol::buffer::Error),
#[error("connection lost unexpectedly")]
Disconnected,
#[error("file queue full error")]
FileQueueFullError(#[from] fd_queue::QueueFullError),
#[error("container image error: {0}")]
ImageError(#[from] ImageError),
#[error("task join error: {0}")]
TaskJoinError(#[from] tokio::task::JoinError),
#[error("virtual filesystem error: {0}")]
VFSError(#[from] VFSError),
#[error("container has no configured entry point")]
NoEntryPoint,
#[error("invalid process ID")]
InvalidPid,
#[error("incorrect ipc process state")]
WrongProcessState,
#[error("string decoding error")]
StringDecoding,
#[error("failed to allocate sandbox process: {0}")]
ProgramAllocError(String),
#[error("memory access error")]
MemAccess,
#[error("error in memory-backed file: {0}")]
MemfdError(#[from] memfd::Error),
#[error("argument string contained internal nul byte")]
NulStringError(#[from] std::ffi::NulError),
#[error("unexpected exit from sandbox runtime, {status}\n{stderr}")]
SandUnexpectedStatus {
status: std::process::ExitStatus,
stderr: String,
},
#[error("sandbox runtime reports an unexpected disconnect\n{stderr}")]
SandReportsDisconnect { stderr: String },
#[error("sandbox runtime reports a low-level I/O error\n{stderr}")]
SandIOError { stderr: String },
#[error("panic from sandbox runtime\n{stderr}")]
SandPanic { stderr: String },
}
#[derive(Error, Clone, Debug)]
pub enum VFSError {
#[error("unexpected filesystem image storage error")]
ImageStorageError,
#[error("generic I/O error")]
IO,
#[error("expected a directory, found another node type")]
DirectoryExpected,
#[error("expected a file, found another node type")]
FileExpected,
#[error("unallocated node")]
UnallocNode,
#[error("not found")]
NotFound,
#[error("too many nested path segments")]
PathSegmentLimitExceeded,
#[error("too many nested symbolic links")]
SymbolicLinkLimitExceeded,
#[error("inode reference count error")]
INodeRefCountError,
}
impl VFSError {
pub fn to_errno(&self) -> libc::c_int {
match self {
VFSError::ImageStorageError => libc::EIO,
VFSError::IO => libc::EIO,
VFSError::DirectoryExpected => libc::ENOTDIR,
VFSError::FileExpected => libc::EISDIR,
VFSError::UnallocNode => libc::ENOENT,
VFSError::NotFound => libc::ENOENT,
VFSError::PathSegmentLimitExceeded => libc::ENAMETOOLONG,
VFSError::SymbolicLinkLimitExceeded => libc::ELOOP,
VFSError::INodeRefCountError => libc::ENOMEM,
}
}
}