Skip to content

Commit 6b7a00e

Browse files
authored
docs(extensibility): name extension base capabilities (#4405)
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 36c4c03 commit 6b7a00e

6 files changed

Lines changed: 84 additions & 8 deletions

File tree

‎crates/openshell-core/src/extension_protocol.rs‎

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,23 @@ pub struct NegotiatedExtension {
6464
#[derive(Debug, Error, PartialEq, Eq)]
6565
pub enum NegotiationError {
6666
#[error(
67-
"{family} extension '{name}' did not provide protocol metadata; upgrade the extension to a version that supports OpenShell extension negotiation"
67+
"{family} extension '{name}' did not provide protocol metadata; upgrade the extension to a version that supports OpenShell extension negotiation (expected {expected})"
6868
)]
69-
MissingMetadata { family: &'static str, name: String },
69+
MissingMetadata {
70+
family: &'static str,
71+
name: String,
72+
expected: String,
73+
},
7074
#[error(
7175
"gateway did not provide protocol metadata to {family} extension '{name}'; upgrade the gateway and extension together"
7276
)]
7377
MissingGatewayMetadata { family: &'static str, name: String },
74-
#[error("{family} extension '{name}' did not provide a protocol version")]
75-
MissingProtocolVersion { family: &'static str, name: String },
78+
#[error("{family} extension '{name}' did not provide a protocol version (expected {expected})")]
79+
MissingProtocolVersion {
80+
family: &'static str,
81+
name: String,
82+
expected: String,
83+
},
7684
#[error(
7785
"{family} extension '{name}' uses unsupported protocol {remote_major}.{remote_minor}; gateway supports {local_major}.{local_minor}"
7886
)]
@@ -148,6 +156,14 @@ pub fn extension_metadata(
148156
}
149157
}
150158

159+
/// Protocol version and base capability an extension of `family` must declare.
160+
fn expected_contract(family: ExtensionFamily) -> String {
161+
format!(
162+
"protocol {PROTOCOL_MAJOR}.{PROTOCOL_MINOR} and capability {}",
163+
family.contract_capability()
164+
)
165+
}
166+
151167
pub fn negotiate(
152168
family: ExtensionFamily,
153169
configured_name: impl Into<String>,
@@ -156,20 +172,24 @@ pub fn negotiate(
156172
) -> Result<NegotiatedExtension, NegotiationError> {
157173
let configured_name = configured_name.into();
158174
let family_name = family.as_str();
175+
let expected = expected_contract(family);
159176
let extension = extension.ok_or_else(|| NegotiationError::MissingMetadata {
160177
family: family_name,
161178
name: configured_name.clone(),
179+
expected: expected.clone(),
162180
})?;
163181
let version = extension.protocol_version.as_ref().ok_or_else(|| {
164182
NegotiationError::MissingProtocolVersion {
165183
family: family_name,
166184
name: configured_name.clone(),
185+
expected: expected.clone(),
167186
}
168187
})?;
169188
let gateway_version = gateway.protocol_version.as_ref().ok_or_else(|| {
170189
NegotiationError::MissingProtocolVersion {
171190
family: family_name,
172191
name: "gateway".to_string(),
192+
expected,
173193
}
174194
})?;
175195
if version.major != gateway_version.major {
@@ -401,10 +421,13 @@ mod tests {
401421
#[test]
402422
fn missing_metadata_and_major_skew_are_actionable() {
403423
let (gateway, mut extension) = compatible();
404-
assert!(matches!(
405-
negotiate(ExtensionFamily::Compute, "example", &gateway, None),
406-
Err(NegotiationError::MissingMetadata { .. })
407-
));
424+
let missing = negotiate(ExtensionFamily::Compute, "example", &gateway, None).unwrap_err();
425+
assert!(matches!(missing, NegotiationError::MissingMetadata { .. }));
426+
assert!(
427+
missing
428+
.to_string()
429+
.contains("protocol 1.0 and capability openshell.compute.contract")
430+
);
408431
extension.protocol_version.as_mut().unwrap().major = 2;
409432
assert!(matches!(
410433
negotiate(
@@ -417,6 +440,28 @@ mod tests {
417440
));
418441
}
419442

443+
#[test]
444+
fn missing_protocol_version_names_the_expected_contract() {
445+
let (gateway, mut extension) = compatible();
446+
extension.protocol_version = None;
447+
let error = negotiate(
448+
ExtensionFamily::Compute,
449+
"example",
450+
&gateway,
451+
Some(extension),
452+
)
453+
.unwrap_err();
454+
assert!(matches!(
455+
error,
456+
NegotiationError::MissingProtocolVersion { .. }
457+
));
458+
assert!(
459+
error
460+
.to_string()
461+
.contains("protocol 1.0 and capability openshell.compute.contract")
462+
);
463+
}
464+
420465
#[test]
421466
fn both_peers_require_capabilities_from_the_other() {
422467
let (mut gateway, mut extension) = compatible();

‎docs/extensibility/overview.mdx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ are satisfied. It rejects different major versions, missing metadata, or an
102102
unmet required capability during startup. Built-in and external service
103103
extensions follow the same compatibility checks.
104104

105+
Every extension returns protocol `1.0` and lists its family's base capability in
106+
`supported_capabilities`:
107+
108+
| Family | Base capability | Returned in |
109+
|---|---|---|
110+
| Compute driver | `openshell.compute.contract` | `GetCapabilitiesResponse.extension` |
111+
| Credential driver | `openshell.credentials.contract` | `GetCredentialDriverCapabilitiesResponse.extension` |
112+
| Gateway interceptor | `openshell.gateway-interceptor.contract` | `InterceptorManifest.extension` |
113+
| Supervisor middleware | `openshell.supervisor-middleware.contract` | `MiddlewareManifest.extension` |
114+
115+
For example, a supervisor middleware `Describe` response includes:
116+
117+
```json
118+
{
119+
"extension": {
120+
"protocol_version": { "major": 1, "minor": 0 },
121+
"implementation_name": "example/content-guard",
122+
"implementation_version": "0.1.0",
123+
"supported_capabilities": ["openshell.supervisor-middleware.contract"]
124+
}
125+
}
126+
```
127+
105128
Use `openshell gateway info` to inspect the negotiated extension families,
106129
implementation versions, protocol versions, and capabilities active on a
107130
gateway.

‎proto/compute_driver.proto‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ message GetCapabilitiesResponse {
101101
// the driver does not support rootfs tar sources.
102102
uint64 rootfs_tar_max_bytes = 11;
103103
// Compute extension protocol metadata. Required for protocol negotiation.
104+
// Declare protocol 1.0 and list "openshell.compute.contract" in
105+
// supported_capabilities.
104106
openshell.extension.v1.PeerMetadata extension = 12;
105107
// Versioned effective operator admission policy (v1: followed by JSON).
106108
// Gateways require an exact policy match before activating the driver.

‎proto/credential_driver.proto‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ message GetCredentialDriverCapabilitiesResponse {
5151
// True when ResolveCredentials may return expiration_time values.
5252
bool supports_expires_at = 5;
5353
// Credential-driver protocol metadata. Required for protocol negotiation.
54+
// Declare protocol 1.0 and list "openshell.credentials.contract" in
55+
// supported_capabilities.
5456
openshell.extension.v1.PeerMetadata extension = 6;
5557
}
5658

‎proto/gateway_interceptor.proto‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ message InterceptorManifest {
111111
// post-authentication consistency check.
112112
string expected_audience = 5;
113113
// Gateway-interceptor protocol metadata. Required for negotiation.
114+
// Declare protocol 1.0 and list "openshell.gateway-interceptor.contract" in
115+
// supported_capabilities.
114116
openshell.extension.v1.PeerMetadata extension = 6;
115117
}
116118

‎proto/supervisor_middleware.proto‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ message MiddlewareManifest {
6767
// this post-authentication consistency check.
6868
string expected_audience = 4;
6969
// Supervisor-middleware protocol metadata. Required for negotiation.
70+
// Declare protocol 1.0 and list "openshell.supervisor-middleware.contract"
71+
// in supported_capabilities.
7072
openshell.extension.v1.PeerMetadata extension = 5;
7173
}
7274

0 commit comments

Comments
 (0)