Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions crates/openshell-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ pub struct MtlsAuthConfig {
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct GatewayAuthConfig {
/// Operator-managed JSON discovery certificate grant file, reloaded on requests/watches.
#[serde(default)]
pub discovery_grants_file: Option<PathBuf>,
/// Concurrent discovery-watch admission limits, per gateway process.
#[serde(default)]
pub discovery: DiscoveryLimits,
/// When true, unauthenticated user/CLI calls are accepted as a local
/// developer principal. This is an unsafe local-development escape hatch
/// for trusted, non-shared gateways. Sandbox supervisor calls still use
Expand All @@ -800,6 +806,23 @@ pub struct GatewayAuthConfig {
pub allow_unauthenticated_users: bool,
}

/// `[openshell.gateway.auth.discovery]` watch admission budgets.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct DiscoveryLimits {
pub max_watches: usize,
pub max_watches_per_principal: usize,
}

impl Default for DiscoveryLimits {
fn default() -> Self {
Self {
max_watches: 128,
max_watches_per_principal: 64,
}
}
}

/// One configured gateway interceptor service.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
Expand Down
4 changes: 2 additions & 2 deletions crates/openshell-sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,13 @@ impl OpenShellClient {
workspace: &str,
options: CreateRetryOptions,
) -> Result<SandboxRef> {
self.create_with_retry_using(
Box::pin(self.create_with_retry_using(
request,
workspace,
options,
create_retry_seed(),
tokio::time::sleep,
)
))
.await
}

Expand Down
35 changes: 32 additions & 3 deletions crates/openshell-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ or starting a watch.

`openshell.v1.ServiceDiscovery.GetServiceRouteSnapshot` and `WatchServiceRoutes` expose accepted installations
for one explicit active workspace. They require `sandbox:read` and workspace
user access; omitted/all-workspaces selectors and sandbox principals are rejected.
Dedicated discovery machine grants are separate work.
user access. Omitted selectors and sandbox principals are rejected. Dedicated
reader grants and cross-workspace scopes are described below.

Each successful response replaces the complete view. Consumers preserve the
returned hostname as TLS SNI and HTTP authority when dialing the supervisor
Expand Down Expand Up @@ -468,7 +468,9 @@ failure, configuration changes during collection or timeout return `UNAVAILABLE`
malformed records return `INTERNAL`.
Watches recheck bearer authentication and workspace authorization each second,
use a one-message buffer, and end after one minute or a five-second blocked send.
Each gateway allows 32 watches, at most four per principal and 16 per workspace.
Each gateway allows 32 watches, at most four per principal. The eight-snapshot /
16-watch per-workspace limits apply only to explicit single-workspace requests;
finite and all-workspace consumers use caller/global limits independently.
Cache reuse adds at most one refresh interval to collection freshness; consumers
must independently honor the advertised lease expiry.
Reconnect and relist on stream termination; revisions are opaque
Expand Down Expand Up @@ -532,3 +534,30 @@ URL responses and discovery agree with that installed name. A mode or gateway
name change changes configuration identity, withdrawing old discovery evidence
until the supervisor acknowledges the replacement. Hash inputs and encoding are
shared with gateway-mediated routing in `openshell-core::app_listener`.

Discovery accepts an explicit workspace or the existing all-workspaces selector;
omission fails. Consumers of a finite grant open one watch per granted workspace
and combine the resulting views, replacing only the updated workspace's routes.
Workspace users retain role/scope/membership authorization for every requested
workspace; all-workspaces access requires platform administration or a dedicated
certificate grant. Discovery certificates carry `OU=discovery`, use the configured
TLS client CA, and receive authority only through the operator-managed fingerprint
mapping at `gateway.auth.discovery_grants_file`. They never become user/operator
principals. Certificate expiry and grant removal are rechecked on active watches.

`gateway.auth.discovery.max_watches` (128) and `max_watches_per_principal` (64)
bound concurrent watches per gateway process. Size these for the number of
consumer replicas times their workspace subscriptions. Unary and per-workspace
admission budgets remain independent.

All-workspaces collection includes future active workspaces and omits terminating
ones, without a fixed workspace-count ceiling. Active workspace metadata is
bounded to 4 MiB within the collection deadline. Selected-workspace collection
does not scan unrelated workspaces. Combined snapshots retain the 4,096-route/4-MiB output bound
and ten-second deadline covering setup, collection, and final reauthorization.
Caller/global capacity is reserved before workspace lookups. Watches retain
caller capacity, with tenant-local permits only for single-workspace requests.
Each refresh has the same ten-second deadline. Each workspace scan retains its existing
1,000-record/4-MiB input bounds. Overflow and storage failures are errors, never
partial successful views. A workspace-set change during collection requires a
retry; this is not a cross-resource transactional snapshot.
16 changes: 13 additions & 3 deletions crates/openshell-server/src/auth/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ fn authenticated(principal: &Principal) -> bool {
match principal {
Principal::User(user) => user.identity.provider != IdentityProvider::LocalDev,
Principal::Anonymous => false,
Principal::Operator(_)
Principal::Discovery(_)
| Principal::Operator(_)
| Principal::Sandbox(_)
| Principal::Peer(_)
| Principal::Supervisor(_)
Expand All @@ -230,7 +231,7 @@ fn authenticated(principal: &Principal) -> bool {
/// The mechanism that established `principal`, when it has an audit label.
fn mechanism(principal: &Principal) -> Option<AuthMechanism> {
match principal {
Principal::Operator(_) => Some(AuthMechanism::Mtls),
Principal::Discovery(_) | Principal::Operator(_) => Some(AuthMechanism::Mtls),
Principal::User(user) => match user.identity.provider {
IdentityProvider::Oidc => Some(AuthMechanism::Oidc),
IdentityProvider::Mtls => Some(AuthMechanism::Mtls),
Expand Down Expand Up @@ -258,6 +259,7 @@ fn credential_digest(
peer_certificate_sha256: Option<&str>,
) -> Option<[u8; 32]> {
let credential = match principal {
Principal::Discovery(reader) => reader.certificate_sha256.as_str(),
Principal::Operator(operator) => operator.certificate_sha256.as_str(),
Principal::User(user) if user.identity.provider == IdentityProvider::Mtls => {
peer_certificate_sha256.unwrap_or_default()
Expand Down Expand Up @@ -627,6 +629,10 @@ pub enum AuthzDenial<'a> {
/// The principal type may not call the method, or may not call it with
/// these arguments.
MethodNotPermitted,
/// A discovery-only principal lacks its administrator-managed grant.
DiscoveryGrantRequired,
/// The discovery grant does not authorize the selected workspace.
DiscoveryWorkspaceNotGranted { workspace: &'a str },
/// The method is not one the gateway knows, for example one added by a
/// newer client.
UnknownMethod,
Expand Down Expand Up @@ -655,6 +661,8 @@ impl AuthzDenial<'_> {
fn category(self) -> &'static str {
match self {
Self::MethodNotPermitted => "method_not_permitted",
Self::DiscoveryGrantRequired => "discovery_grant_required",
Self::DiscoveryWorkspaceNotGranted { .. } => "discovery_workspace_not_granted",
Self::UnknownMethod => "unknown_method",
Self::MissingRole => "missing_role",
Self::MissingScope => "missing_scope",
Expand All @@ -675,7 +683,8 @@ impl AuthzDenial<'_> {
Self::CrossSandboxName { name } => {
Some(ResourceDetails::named("sandbox", bounded(name)))
}
Self::NotWorkspaceMember { workspace }
Self::DiscoveryWorkspaceNotGranted { workspace }
| Self::NotWorkspaceMember { workspace }
| Self::InsufficientWorkspaceRole { workspace } => {
Some(ResourceDetails::named("workspace", bounded(workspace)))
}
Expand Down Expand Up @@ -729,6 +738,7 @@ fn principal_user(principal: &Principal) -> User {
Principal::Supervisor(supervisor) => {
User::other(&supervisor.identity.subject, "Supervisor")
}
Principal::Discovery(reader) => User::other(&reader.certificate_sha256, "Discovery Reader"),
Principal::Anonymous => User::unidentified(),
}
}
Expand Down
Loading
Loading