Skip to main content

alien_signing/
error.rs

1use alien_error::AlienErrorData;
2use serde::{Deserialize, Serialize};
3
4/// Why a statement, signer list, setting, ledger or workload was refused.
5///
6/// Every variant is a refusal an enforcer reports back to whoever sent the
7/// input, so none of them is internal.
8#[derive(Debug, Clone, AlienErrorData, Serialize, Deserialize, PartialEq, Eq)]
9#[serde(rename_all = "camelCase")]
10pub enum ErrorData {
11    /// A key is not a valid ECDSA P-256 key in the expected encoding.
12    #[error(
13        code = "SIGNING_KEY_INVALID",
14        message = "Invalid signing key: {reason}",
15        retryable = "false",
16        internal = "false",
17        http_status_code = 400
18    )]
19    KeyInvalid {
20        /// What is wrong with the key.
21        reason: String,
22    },
23
24    /// The bytes are not a well-formed signed statement.
25    #[error(
26        code = "SIGNING_STATEMENT_MALFORMED",
27        message = "Malformed statement: {reason}",
28        retryable = "false",
29        internal = "false",
30        http_status_code = 400
31    )]
32    StatementMalformed {
33        /// What is wrong with the statement.
34        reason: String,
35    },
36
37    /// The statement is of another kind than the one expected.
38    #[error(
39        code = "SIGNING_WRONG_KIND",
40        message = "Expected a '{expected}' statement, got '{actual}'",
41        retryable = "false",
42        internal = "false",
43        http_status_code = 403
44    )]
45    WrongKind {
46        /// Kind the caller asked for.
47        expected: String,
48        /// Kind the statement declares.
49        actual: String,
50    },
51
52    /// The statement names another project.
53    #[error(
54        code = "SIGNING_WRONG_PROJECT",
55        message = "The statement is for project '{actual}', not '{expected}'",
56        retryable = "false",
57        internal = "false",
58        http_status_code = 403
59    )]
60    WrongProject {
61        /// Project of the pinned signer list.
62        expected: String,
63        /// Project the statement names.
64        actual: String,
65    },
66
67    /// The statement names another install, or none where one is required.
68    #[error(
69        code = "SIGNING_WRONG_INSTALL",
70        message = "The statement is for install '{actual}', not '{expected}'",
71        retryable = "false",
72        internal = "false",
73        http_status_code = 403
74    )]
75    WrongInstall {
76        /// This install, or `none` for project-wide kinds.
77        expected: String,
78        /// Install the statement names, or `none`.
79        actual: String,
80    },
81
82    /// A release is for another channel than the one setup pinned.
83    #[error(
84        code = "SIGNING_WRONG_CHANNEL",
85        message = "The release is for channel '{actual}', but this install follows '{expected}'",
86        retryable = "false",
87        internal = "false",
88        http_status_code = 403
89    )]
90    WrongChannel {
91        /// Channel setup pinned.
92        expected: String,
93        /// Channel the release names.
94        actual: String,
95    },
96
97    /// A signature does not verify, or names a signer that may not sign.
98    #[error(
99        code = "SIGNING_SIGNATURE_REFUSED",
100        message = "Signature by '{signer}' refused: {reason}",
101        retryable = "false",
102        internal = "false",
103        http_status_code = 403
104    )]
105    SignatureRefused {
106        /// Signer id the signature names.
107        signer: String,
108        /// Why it was refused.
109        reason: String,
110    },
111
112    /// The statement carries no signature that counts.
113    #[error(
114        code = "SIGNING_UNSIGNED",
115        message = "The statement is not signed by a key holding the '{role}' role",
116        retryable = "false",
117        internal = "false",
118        http_status_code = 403
119    )]
120    Unsigned {
121        /// Role the statement's kind requires.
122        role: String,
123    },
124
125    /// The statement's `notAfter` has passed.
126    #[error(
127        code = "SIGNING_EXPIRED",
128        message = "The statement expired at {not_after}",
129        retryable = "false",
130        internal = "false",
131        http_status_code = 403
132    )]
133    Expired {
134        /// When it stopped being valid, RFC 3339.
135        not_after: String,
136    },
137
138    /// The statement's digest is on the signer list's deny-list.
139    #[error(
140        code = "SIGNING_DENIED",
141        message = "The statement {digest} is on the signer list's deny-list",
142        retryable = "false",
143        internal = "false",
144        http_status_code = 403
145    )]
146    Denied {
147        /// Digest of the statement payload.
148        digest: String,
149    },
150
151    /// A signer list does not extend the trusted chain.
152    #[error(
153        code = "SIGNING_SIGNER_LIST_REFUSED",
154        message = "Signer list version {version} refused: {reason}",
155        retryable = "false",
156        internal = "false",
157        http_status_code = 403
158    )]
159    SignerListRefused {
160        /// Version the refused list claims.
161        version: u64,
162        /// Why it was refused.
163        reason: String,
164    },
165
166    /// The statement was signed against a signer list version the enforcer
167    /// has not been given.
168    #[error(
169        code = "SIGNING_SIGNER_LIST_MISSING",
170        message = "The statement needs signer list version {needed}, but only version {current} is trusted",
171        retryable = "true",
172        internal = "false",
173        http_status_code = 409
174    )]
175    SignerListMissing {
176        /// Version the statement names.
177        needed: u64,
178        /// Highest version the enforcer trusts.
179        current: u64,
180    },
181
182    /// The signing settings setup wrote are malformed or contradict where
183    /// they were found.
184    #[error(
185        code = "SIGNING_SETTINGS_INVALID",
186        message = "Invalid signing settings: {reason}",
187        retryable = "false",
188        internal = "false",
189        http_status_code = 400
190    )]
191    SettingsInvalid {
192        /// What is wrong with the settings.
193        reason: String,
194    },
195
196    /// Whether this install is protected can't be decided from what the
197    /// enforcer could read, so it runs nothing new.
198    #[error(
199        code = "SIGNING_SETTINGS_UNDECIDED",
200        message = "Can't tell whether this install is protected: {reason}",
201        retryable = "true",
202        internal = "false",
203        http_status_code = 503
204    )]
205    SettingsUndecided {
206        /// What the enforcer saw.
207        reason: String,
208    },
209
210    /// The install accepted signed state under one trust root and now finds
211    /// another, or none. Only a local operator command resets it.
212    #[error(
213        code = "SIGNING_TRUST_ROOT_CHANGED",
214        message = "This install accepted state under {accepted} and now finds {found}; it runs nothing new until an operator resets it",
215        retryable = "false",
216        internal = "false",
217        http_status_code = 409
218    )]
219    TrustRootChanged {
220        /// The fingerprint or install id the install accepted state under.
221        accepted: String,
222        /// What it finds now, or `none`.
223        found: String,
224    },
225
226    /// The install's ledger is missing, malformed or forks from what this
227    /// enforcer holds.
228    #[error(
229        code = "SIGNING_LEDGER_REFUSED",
230        message = "The install's ledger was refused: {reason}",
231        retryable = "false",
232        internal = "false",
233        http_status_code = 409
234    )]
235    LedgerRefused {
236        /// Why.
237        reason: String,
238    },
239
240    /// A workload asked for something its signed release does not allow.
241    #[error(
242        code = "SIGNING_WORKLOAD_REFUSED",
243        message = "Workload '{workload}' refused: {reason}",
244        retryable = "false",
245        internal = "false",
246        http_status_code = 403
247    )]
248    WorkloadRefused {
249        /// Workload name.
250        workload: String,
251        /// Why it was refused.
252        reason: String,
253    },
254
255    /// A statement body breaks a rule of its kind.
256    #[error(
257        code = "SIGNING_BODY_REFUSED",
258        message = "The '{kind}' statement was refused: {reason}",
259        retryable = "false",
260        internal = "false",
261        http_status_code = 403
262    )]
263    BodyRefused {
264        /// Statement kind.
265        kind: String,
266        /// Why it was refused.
267        reason: String,
268    },
269}
270
271/// Result type of this crate.
272pub type Result<T> = alien_error::Result<T, ErrorData>;