@feltdb/core 0.12.2 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/agent-runtime.d.ts +64 -2
  2. package/dist/agent-runtime.d.ts.map +1 -1
  3. package/dist/agent-runtime.js +121 -11
  4. package/dist/agent-state.d.ts +48 -0
  5. package/dist/agent-state.d.ts.map +1 -1
  6. package/dist/agent-state.js +174 -12
  7. package/dist/agent.d.ts +10 -1
  8. package/dist/agent.d.ts.map +1 -1
  9. package/dist/agent.js +10 -1
  10. package/dist/build-identity.json +4 -4
  11. package/dist/cli/commands.js +34 -7
  12. package/dist/cli/workspace-integration.js +8 -0
  13. package/dist/collection.d.ts +3 -1
  14. package/dist/collection.d.ts.map +1 -1
  15. package/dist/collection.js +30 -8
  16. package/dist/create/build-identity.json +4 -4
  17. package/dist/create/cli.js +47 -38
  18. package/dist/create/create.js +21 -8
  19. package/dist/create/package-versions.js +1 -1
  20. package/dist/create/server-source/Cargo.lock +6 -6
  21. package/dist/create/server-source/Cargo.toml +1 -1
  22. package/dist/create/server-source/crates/feltdb/src/lib.rs +126 -35
  23. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +162 -53
  24. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +341 -2
  25. package/dist/create/server-source/crates/feltdb/src/workload.rs +2094 -126
  26. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +18 -12
  27. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +17 -5
  28. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  29. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  30. package/dist/create/server-source/crates/feltdb-server/README.md +6 -1
  31. package/dist/create/server-source/crates/feltdb-server/src/agent_execution.rs +511 -0
  32. package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +9 -1
  33. package/dist/create/server-source/crates/feltdb-server/src/auth.rs +113 -25
  34. package/dist/create/server-source/crates/feltdb-server/src/backup.rs +4 -0
  35. package/dist/create/server-source/crates/feltdb-server/src/console_accounts.rs +1009 -0
  36. package/dist/create/server-source/crates/feltdb-server/src/control_authorization.rs +441 -0
  37. package/dist/create/server-source/crates/feltdb-server/src/identity.rs +68 -6
  38. package/dist/create/server-source/crates/feltdb-server/src/key_management.rs +355 -23
  39. package/dist/create/server-source/crates/feltdb-server/src/lib.rs +4 -0
  40. package/dist/create/server-source/crates/feltdb-server/src/main.rs +1740 -236
  41. package/dist/create/server-source/crates/feltdb-server/src/redaction.rs +208 -0
  42. package/dist/create/server-source/crates/feltdb-server/src/tenancy.rs +198 -19
  43. package/dist/create/server-source/crates/feltdb-server/tests/transaction_precondition_contract.rs +403 -0
  44. package/dist/create/setup-summary.js +40 -0
  45. package/dist/db.d.ts +91 -10
  46. package/dist/db.d.ts.map +1 -1
  47. package/dist/db.js +170 -31
  48. package/dist/deployment.d.ts +19 -0
  49. package/dist/deployment.d.ts.map +1 -1
  50. package/dist/deployment.js +38 -2
  51. package/dist/development-runtime-bridge.d.ts +20 -0
  52. package/dist/development-runtime-bridge.d.ts.map +1 -1
  53. package/dist/development-runtime-bridge.js +61 -12
  54. package/dist/embedded-query.d.ts.map +1 -1
  55. package/dist/embedded-query.js +5 -4
  56. package/dist/embedded-transaction.d.ts +8 -4
  57. package/dist/embedded-transaction.d.ts.map +1 -1
  58. package/dist/embedded-transaction.js +55 -19
  59. package/dist/error-codes.d.ts +31 -2
  60. package/dist/error-codes.d.ts.map +1 -1
  61. package/dist/error-codes.js +41 -2
  62. package/dist/feltdb.d.ts +7 -0
  63. package/dist/feltdb.d.ts.map +1 -1
  64. package/dist/file-db.d.ts +27 -0
  65. package/dist/file-db.d.ts.map +1 -1
  66. package/dist/file-db.js +145 -7
  67. package/dist/http-client.d.ts +11 -3
  68. package/dist/http-client.d.ts.map +1 -1
  69. package/dist/http-client.js +27 -14
  70. package/dist/http-db.d.ts +40 -1
  71. package/dist/http-db.d.ts.map +1 -1
  72. package/dist/http-db.js +285 -58
  73. package/dist/index.js +1 -1
  74. package/dist/local-state-lock.d.ts +34 -0
  75. package/dist/local-state-lock.d.ts.map +1 -0
  76. package/dist/local-state-lock.js +225 -0
  77. package/dist/reactive-graph.d.ts +0 -3
  78. package/dist/reactive-graph.d.ts.map +1 -1
  79. package/dist/reactive-graph.js +11 -1
  80. package/dist/runtime-registry.d.ts +7 -2
  81. package/dist/runtime-registry.d.ts.map +1 -1
  82. package/dist/runtime-registry.js +2 -2
  83. package/dist/studio/{KeyManagementPanel-D5FMvvU9.js → KeyManagementPanel-skUNnKRw.js} +36 -29
  84. package/dist/studio/app.d.ts +8 -1
  85. package/dist/studio/app.d.ts.map +1 -1
  86. package/dist/studio/components/KeyManagementPanel.d.ts.map +1 -1
  87. package/dist/studio/components/KeyManagementPanel.js +1 -1
  88. package/dist/studio/components/index.js +2 -2
  89. package/dist/studio/{components-B4eKIUN5.js → components-CJmzntBi.js} +8 -7
  90. package/dist/studio/control-plane/Data.d.ts.map +1 -1
  91. package/dist/studio/control-plane/Instance.d.ts +4 -1
  92. package/dist/studio/control-plane/Instance.d.ts.map +1 -1
  93. package/dist/studio/control-plane/Operations.d.ts +4 -1
  94. package/dist/studio/control-plane/Operations.d.ts.map +1 -1
  95. package/dist/studio/control-plane/index.js +2 -2
  96. package/dist/studio/control-plane/primitives.d.ts +16 -0
  97. package/dist/studio/control-plane/primitives.d.ts.map +1 -1
  98. package/dist/studio/{control-plane-fxMcJn74.js → control-plane-CaBA7Rgv.js} +448 -424
  99. package/dist/studio/index.d.ts +1 -0
  100. package/dist/studio/index.d.ts.map +1 -1
  101. package/dist/studio/index.js +384 -247
  102. package/dist/studio/navigation.d.ts +57 -0
  103. package/dist/studio/navigation.d.ts.map +1 -0
  104. package/dist/studio/studio.css +1 -1
  105. package/dist/studio/utils/control-plane-api.d.ts +2 -0
  106. package/dist/studio/utils/control-plane-api.d.ts.map +1 -1
  107. package/dist/studio/utils/control-plane-api.js +5 -1
  108. package/dist/studio-app/assets/{feltdb_wasm-BatwwogY.js → feltdb_wasm-BjM1ylL3.js} +1 -1
  109. package/dist/studio-app/assets/feltdb_wasm_bg-TseJn2Ax.wasm +0 -0
  110. package/dist/studio-app/assets/index-1wd0uKua.js +30 -0
  111. package/dist/studio-app/assets/{index-CiC8VY-a.css → index-vi21oEQa.css} +1 -1
  112. package/dist/studio-app/index.html +2 -2
  113. package/dist/transaction.d.ts +27 -11
  114. package/dist/transaction.d.ts.map +1 -1
  115. package/dist/transaction.js +20 -14
  116. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  117. package/dist/wasm/package.json +1 -1
  118. package/dist/workload.d.ts +31 -3
  119. package/dist/workload.d.ts.map +1 -1
  120. package/dist/workload.js +28 -3
  121. package/dist/workspace/local-development-authority.d.ts +19 -0
  122. package/dist/workspace/local-development-authority.d.ts.map +1 -1
  123. package/dist/workspace/local-development-authority.js +335 -15
  124. package/package.json +1 -1
  125. package/dist/studio-app/assets/feltdb_wasm_bg-BX0newOr.wasm +0 -0
  126. package/dist/studio-app/assets/index-DoVvbIay.js +0 -30
@@ -1,14 +1,32 @@
1
+ //! `/api/keys`: list, create, rotate and revoke service keys.
2
+ //!
3
+ //! The request middleware has already required `keys:admin` of a machine
4
+ //! caller and refused application end-user sessions
5
+ //! ([`crate::control_authorization`]). These handlers make the decisions that
6
+ //! need the target: a caller never issues a key with a scope or namespace it
7
+ //! does not hold itself, a key bound to an application only manages keys of
8
+ //! that application, and a console user manages only keys bound to an
9
+ //! application in which it holds `members:write`, with application-level
10
+ //! capabilities its own role grants. Secrets are returned once, at creation
11
+ //! or rotation; listings carry ids, names, scopes and namespaces only.
12
+
1
13
  use axum::{
2
- extract::{Extension, Path, State},
14
+ extract::{Extension, Path, Query, State},
3
15
  http::StatusCode,
16
+ response::{IntoResponse, Response},
4
17
  Json,
5
18
  };
6
19
  use serde::{Deserialize, Serialize};
20
+ use serde_json::json;
7
21
  use std::time::{SystemTime, UNIX_EPOCH};
8
22
 
9
23
  use crate::{
10
24
  app_state::AppState,
11
25
  auth::{ApiKeySummary, Principal},
26
+ control_authorization::{
27
+ console_delegable, namespaces_within, scopes_within, Denial, PrincipalClass,
28
+ APPLICATION_SCOPE_REQUIRED, END_USER_SESSION_FORBIDDEN, PRIVILEGE_ESCALATION_DENIED,
29
+ },
12
30
  };
13
31
 
14
32
  #[derive(Debug, Serialize)]
@@ -24,34 +42,267 @@ pub struct CreateKeyRequest {
24
42
  pub application_id: Option<String>,
25
43
  }
26
44
 
45
+ #[derive(Debug, Default, Deserialize)]
46
+ pub struct KeyListQuery {
47
+ pub application_id: Option<String>,
48
+ }
49
+
27
50
  #[derive(Debug, Serialize)]
28
51
  pub struct CreateKeyResponse {
29
52
  pub secret: String,
30
53
  pub id: String,
54
+ #[serde(skip_serializing_if = "Option::is_none")]
55
+ pub replaces: Option<String>,
56
+ }
57
+
58
+ /// A key-management failure, in the server's canonical error shape.
59
+ #[derive(Debug)]
60
+ pub struct KeyError {
61
+ status: StatusCode,
62
+ message: String,
63
+ reason: Option<&'static str>,
64
+ required_scope: Option<String>,
65
+ }
66
+
67
+ impl KeyError {
68
+ fn status(status: StatusCode, message: impl Into<String>) -> Self {
69
+ Self {
70
+ status,
71
+ message: message.into(),
72
+ reason: None,
73
+ required_scope: None,
74
+ }
75
+ }
76
+ fn forbidden(reason: &'static str, message: impl Into<String>) -> Self {
77
+ Self {
78
+ reason: Some(reason),
79
+ ..Self::status(StatusCode::FORBIDDEN, message)
80
+ }
81
+ }
82
+ fn internal(error: impl ToString) -> Self {
83
+ // Store errors name files, not credentials; the detail stays in logs.
84
+ tracing::error!(error = %error.to_string(), "key store operation failed");
85
+ Self::status(
86
+ StatusCode::INTERNAL_SERVER_ERROR,
87
+ "the key store could not complete the operation",
88
+ )
89
+ }
90
+ }
91
+
92
+ impl From<Denial> for KeyError {
93
+ fn from(denial: Denial) -> Self {
94
+ Self {
95
+ status: StatusCode::FORBIDDEN,
96
+ message: denial.message,
97
+ reason: Some(denial.reason),
98
+ required_scope: denial.required_scope,
99
+ }
100
+ }
101
+ }
102
+
103
+ impl IntoResponse for KeyError {
104
+ fn into_response(self) -> Response {
105
+ let code = match self.status {
106
+ StatusCode::FORBIDDEN => "FORBIDDEN",
107
+ StatusCode::NOT_FOUND => "NOT_FOUND",
108
+ StatusCode::BAD_REQUEST => "VALIDATION_ERROR",
109
+ _ => "EXECUTION_FAILED",
110
+ };
111
+ let mut body = json!({
112
+ "error": code,
113
+ "code": code,
114
+ "message": self.message,
115
+ "request_id": format!("req_{}", uuid::Uuid::new_v4().simple()),
116
+ });
117
+ if let Some(reason) = self.reason {
118
+ body["reason"] = json!(reason);
119
+ }
120
+ if let Some(scope) = self.required_scope {
121
+ body["required_scope"] = json!(scope);
122
+ }
123
+ (self.status, Json(body)).into_response()
124
+ }
125
+ }
126
+
127
+ fn refuse_end_user(class: PrincipalClass) -> Result<(), KeyError> {
128
+ if class == PrincipalClass::EndUser {
129
+ return Err(KeyError::forbidden(
130
+ END_USER_SESSION_FORBIDDEN,
131
+ "end-user sessions cannot manage keys — use an admin key holding keys:admin, or a console session with members:write on the application",
132
+ ));
133
+ }
134
+ Ok(())
135
+ }
136
+
137
+ /// The application a console user may manage keys for, with `capability` in it.
138
+ fn console_application(
139
+ state: &AppState,
140
+ principal: &Principal,
141
+ application_id: Option<&str>,
142
+ capability: &str,
143
+ ) -> Result<crate::tenancy::Application, KeyError> {
144
+ let application_id = application_id.ok_or_else(|| {
145
+ KeyError::forbidden(
146
+ APPLICATION_SCOPE_REQUIRED,
147
+ "console sessions manage keys per application — pass application_id for an application in which you hold members:write",
148
+ )
149
+ })?;
150
+ let denied = || {
151
+ KeyError::forbidden(
152
+ "MEMBERSHIP_REQUIRED",
153
+ format!("managing keys of this application requires {capability} in it"),
154
+ )
155
+ .with_scope(capability)
156
+ };
157
+ let application = state
158
+ .tenancy
159
+ .application_record(application_id)
160
+ .ok_or_else(denied)?;
161
+ if !state.tenancy.authorize_application(
162
+ &principal.key_id,
163
+ &application.tenant_id,
164
+ &application.id,
165
+ capability,
166
+ ) {
167
+ return Err(denied());
168
+ }
169
+ Ok(application)
170
+ }
171
+
172
+ impl KeyError {
173
+ fn with_scope(mut self, scope: &str) -> Self {
174
+ self.required_scope = Some(scope.to_string());
175
+ self
176
+ }
177
+ }
178
+
179
+ /// The namespaces the calling key authenticates for.
180
+ fn caller_namespaces(state: &AppState, principal: &Principal) -> Vec<String> {
181
+ state
182
+ .keys
183
+ .summary(&principal.key_id)
184
+ .map(|summary| summary.namespaces)
185
+ .unwrap_or_else(|| vec![state.namespace.to_string()])
31
186
  }
32
187
 
33
188
  pub async fn list_keys(
34
189
  State(state): State<AppState>,
35
- ) -> Result<Json<KeyListResponse>, (StatusCode, String)> {
36
- let tokens = state
37
- .keys
38
- .list()
39
- .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e))?;
190
+ Extension(principal): Extension<Principal>,
191
+ Extension(class): Extension<PrincipalClass>,
192
+ Query(query): Query<KeyListQuery>,
193
+ ) -> Result<Json<KeyListResponse>, KeyError> {
194
+ refuse_end_user(class)?;
195
+ let all = state.keys.list().map_err(KeyError::internal)?;
196
+ let application = match class {
197
+ PrincipalClass::ConsoleUser => Some(
198
+ console_application(
199
+ &state,
200
+ &principal,
201
+ query.application_id.as_deref(),
202
+ "members:read",
203
+ )?
204
+ .id,
205
+ ),
206
+ _ => match state.tenancy.service_binding(&principal.key_id) {
207
+ // A key bound to an application sees only that application's keys.
208
+ Some(binding) => {
209
+ if query
210
+ .application_id
211
+ .as_deref()
212
+ .is_some_and(|requested| requested != binding.application_id)
213
+ {
214
+ return Err(KeyError::forbidden(
215
+ PRIVILEGE_ESCALATION_DENIED,
216
+ "this key is bound to another application and cannot list its keys",
217
+ ));
218
+ }
219
+ Some(binding.application_id)
220
+ }
221
+ None => query.application_id,
222
+ },
223
+ };
224
+ let tokens = match application {
225
+ Some(application_id) => {
226
+ let bound = state.tenancy.application_service_ids(&application_id);
227
+ all.into_iter()
228
+ .filter(|summary| bound.contains(&summary.id))
229
+ .collect()
230
+ }
231
+ None => all,
232
+ };
40
233
  Ok(Json(KeyListResponse { tokens }))
41
234
  }
42
235
 
43
236
  pub async fn create_key(
44
237
  State(state): State<AppState>,
45
238
  Extension(principal): Extension<Principal>,
239
+ Extension(class): Extension<PrincipalClass>,
46
240
  Json(req): Json<CreateKeyRequest>,
47
- ) -> Result<(StatusCode, Json<CreateKeyResponse>), (StatusCode, String)> {
241
+ ) -> Result<(StatusCode, Json<CreateKeyResponse>), KeyError> {
242
+ refuse_end_user(class)?;
243
+ let scopes = req.scopes;
244
+ if scopes.is_empty() || scopes.iter().any(|scope| scope.trim().is_empty()) {
245
+ return Err(KeyError::status(
246
+ StatusCode::BAD_REQUEST,
247
+ "scopes must name at least one capability, e.g. [\"state:read\"]",
248
+ ));
249
+ }
250
+ match class {
251
+ PrincipalClass::ConsoleUser => {
252
+ let application = console_application(
253
+ &state,
254
+ &principal,
255
+ req.application_id.as_deref(),
256
+ "members:write",
257
+ )?;
258
+ if let Some(scope) = scopes.iter().find(|scope| {
259
+ !console_delegable(scope)
260
+ || !state.tenancy.authorize_application(
261
+ &principal.key_id,
262
+ &application.tenant_id,
263
+ &application.id,
264
+ scope,
265
+ )
266
+ }) {
267
+ return Err(KeyError::forbidden(
268
+ PRIVILEGE_ESCALATION_DENIED,
269
+ format!("cannot delegate scope {scope}: console sessions delegate only application capabilities their own role grants; operator scopes need an admin key"),
270
+ ));
271
+ }
272
+ if req.namespace != state.namespace.as_ref() && req.namespace != application.namespace
273
+ {
274
+ return Err(KeyError::forbidden(
275
+ PRIVILEGE_ESCALATION_DENIED,
276
+ format!(
277
+ "cannot issue a key for namespace {}: use this authority's or the application's namespace",
278
+ req.namespace
279
+ ),
280
+ ));
281
+ }
282
+ }
283
+ PrincipalClass::Machine => {
284
+ scopes_within(&scopes, &principal.scopes)?;
285
+ namespaces_within(&req.namespace, &caller_namespaces(&state, &principal))?;
286
+ if let Some(binding) = state.tenancy.service_binding(&principal.key_id) {
287
+ if req.application_id.as_deref() != Some(binding.application_id.as_str()) {
288
+ return Err(KeyError::forbidden(
289
+ APPLICATION_SCOPE_REQUIRED,
290
+ format!(
291
+ "this key is bound to application {}; keys it issues must name that application_id",
292
+ binding.application_id
293
+ ),
294
+ ));
295
+ }
296
+ }
297
+ }
298
+ PrincipalClass::Development | PrincipalClass::EndUser => {}
299
+ }
300
+
48
301
  let timestamp = SystemTime::now()
49
302
  .duration_since(UNIX_EPOCH)
50
303
  .unwrap_or_default()
51
304
  .as_secs();
52
-
53
305
  let name = req.id.unwrap_or_else(|| format!("key-{}", timestamp));
54
- let scopes = req.scopes;
55
306
  let mut authentication_namespaces = vec![req.namespace];
56
307
  if !authentication_namespaces
57
308
  .iter()
@@ -64,10 +315,12 @@ pub async fn create_key(
64
315
  // unavailable while qualification creates several scoped keys.
65
316
  let keys = state.keys.clone();
66
317
  let key_scopes = scopes.clone();
67
- let key = tokio::task::spawn_blocking(move || keys.create(name, key_scopes, authentication_namespaces))
68
- .await
69
- .map_err(|error| (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()))?
70
- .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e))?;
318
+ let key = tokio::task::spawn_blocking(move || {
319
+ keys.create(name, key_scopes, authentication_namespaces)
320
+ })
321
+ .await
322
+ .map_err(KeyError::internal)?
323
+ .map_err(KeyError::internal)?;
71
324
 
72
325
  if let Some(application_id) = req.application_id {
73
326
  if let Err(error) = state.tenancy.register_application_service(
@@ -77,7 +330,10 @@ pub async fn create_key(
77
330
  scopes,
78
331
  ) {
79
332
  let _ = state.keys.revoke(&key.id);
80
- return Err((StatusCode::FORBIDDEN, error));
333
+ return Err(KeyError::forbidden(
334
+ "MEMBERSHIP_REQUIRED",
335
+ format!("the key could not be bound to application {application_id}: {error}; binding requires members:write in that application"),
336
+ ));
81
337
  }
82
338
  }
83
339
 
@@ -86,22 +342,98 @@ pub async fn create_key(
86
342
  Json(CreateKeyResponse {
87
343
  secret: key.secret,
88
344
  id: key.id,
345
+ replaces: None,
89
346
  }),
90
347
  ))
91
348
  }
92
349
 
350
+ /// May this caller revoke or rotate `id`? Returns the key's listing entry.
351
+ fn authorize_target(
352
+ state: &AppState,
353
+ principal: &Principal,
354
+ class: PrincipalClass,
355
+ id: &str,
356
+ ) -> Result<ApiKeySummary, KeyError> {
357
+ refuse_end_user(class)?;
358
+ let target = state.keys.summary(id);
359
+ let binding = state.tenancy.service_binding(id);
360
+ match class {
361
+ PrincipalClass::ConsoleUser => {
362
+ let application = binding.as_ref().map(|binding| binding.application_id.as_str());
363
+ console_application(state, principal, application, "members:write")?;
364
+ }
365
+ PrincipalClass::Machine => {
366
+ if let Some(own) = state.tenancy.service_binding(&principal.key_id) {
367
+ if binding.as_ref().map(|binding| &binding.application_id)
368
+ != Some(&own.application_id)
369
+ {
370
+ return Err(KeyError::forbidden(
371
+ PRIVILEGE_ESCALATION_DENIED,
372
+ "this key is bound to an application and manages only that application's keys",
373
+ ));
374
+ }
375
+ }
376
+ if let Some(target) = &target {
377
+ // Revoking or re-issuing a broader key is not a narrower act.
378
+ scopes_within(&target.scopes, &principal.scopes)?;
379
+ for namespace in &target.namespaces {
380
+ namespaces_within(namespace, &caller_namespaces(state, principal))?;
381
+ }
382
+ }
383
+ }
384
+ PrincipalClass::Development | PrincipalClass::EndUser => {}
385
+ }
386
+ target.ok_or_else(|| KeyError::status(StatusCode::NOT_FOUND, "key not found"))
387
+ }
388
+
93
389
  pub async fn revoke_key(
94
390
  State(state): State<AppState>,
391
+ Extension(principal): Extension<Principal>,
392
+ Extension(class): Extension<PrincipalClass>,
95
393
  Path(id): Path<String>,
96
- ) -> Result<StatusCode, (StatusCode, String)> {
97
- let found = state
98
- .keys
99
- .revoke(&id)
100
- .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e))?;
394
+ ) -> Result<StatusCode, KeyError> {
395
+ authorize_target(&state, &principal, class, &id)?;
396
+ if !state.keys.revoke(&id).map_err(KeyError::internal)? {
397
+ return Err(KeyError::status(StatusCode::NOT_FOUND, "key not found"));
398
+ }
399
+ state
400
+ .tenancy
401
+ .transfer_application_service(&principal.key_id, &id, None)
402
+ .map_err(KeyError::internal)?;
403
+ Ok(StatusCode::NO_CONTENT)
404
+ }
101
405
 
102
- if found {
103
- Ok(StatusCode::NO_CONTENT)
104
- } else {
105
- Err((StatusCode::NOT_FOUND, "Key not found".to_string()))
406
+ /// Rotate = issue a replacement with the same scopes, namespaces and binding,
407
+ /// and revoke the old key in the same store write. The new secret is shown
408
+ /// once, here.
409
+ pub async fn rotate_key(
410
+ State(state): State<AppState>,
411
+ Extension(principal): Extension<Principal>,
412
+ Extension(class): Extension<PrincipalClass>,
413
+ Path(id): Path<String>,
414
+ ) -> Result<(StatusCode, Json<CreateKeyResponse>), KeyError> {
415
+ let target = authorize_target(&state, &principal, class, &id)?;
416
+ if target.revoked {
417
+ return Err(KeyError::status(
418
+ StatusCode::NOT_FOUND,
419
+ "key is revoked; create a new key instead",
420
+ ));
106
421
  }
422
+ let created = state
423
+ .keys
424
+ .rotate(&id)
425
+ .map_err(KeyError::internal)?
426
+ .ok_or_else(|| KeyError::status(StatusCode::NOT_FOUND, "key not found"))?;
427
+ state
428
+ .tenancy
429
+ .transfer_application_service(&principal.key_id, &id, Some(&created.id))
430
+ .map_err(KeyError::internal)?;
431
+ Ok((
432
+ StatusCode::CREATED,
433
+ Json(CreateKeyResponse {
434
+ secret: created.secret,
435
+ id: created.id,
436
+ replaces: Some(id),
437
+ }),
438
+ ))
107
439
  }
@@ -18,6 +18,7 @@
18
18
 
19
19
  pub use feltdb;
20
20
 
21
+ pub mod agent_execution;
21
22
  pub mod app_state;
22
23
  pub mod application_contract;
23
24
  pub mod artifacts;
@@ -33,7 +34,9 @@ pub mod certification_harness;
33
34
  pub mod clock;
34
35
  pub mod cluster;
35
36
  pub mod connections;
37
+ pub mod console_accounts;
36
38
  pub mod content;
39
+ pub mod control_authorization;
37
40
  pub mod control_plane;
38
41
  pub mod delegation_token;
39
42
  pub mod durable_operations;
@@ -48,6 +51,7 @@ pub mod portable_bundle;
48
51
  pub mod principals;
49
52
  pub mod providers;
50
53
  pub mod query_shape;
54
+ pub mod redaction;
51
55
  pub mod releases;
52
56
  pub mod request_telemetry;
53
57
  pub mod sessions;