Skip to content

Commit 8ed02ac

Browse files
feat(auth): implement RFC 0011 Phase 2 workspace authorization
Signed-off-by: Derek Carr <decarr@redhat.com>
1 parent b78c861 commit 8ed02ac

61 files changed

Lines changed: 6864 additions & 1278 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/openshell-cli/SKILL.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ Use an `http://` endpoint only for trusted local port-forwarding or a protected
5252

5353
```bash
5454
openshell status
55+
openshell whoami
5556
```
5657

5758
Confirm the gateway is reachable, authentication is valid or not required, and
5859
the output shows a version. `Status: Connected` only proves the public health
5960
endpoint is reachable; inspect the separate `Authentication` line before
60-
running protected commands.
61+
running protected commands. `openshell whoami` reports the identity validated
62+
by the gateway, including the subject an administrator uses for workspace
63+
membership. Add `--output json` for automation.
6164

6265
### Step 3: Create a sandbox
6366

@@ -619,6 +622,7 @@ $ openshell sandbox upload --help
619622
|------|---------|
620623
| Register local port-forwarded gateway | `openshell gateway add http://127.0.0.1:8080 --local --name local` |
621624
| Check gateway health and authentication | `openshell status` |
625+
| Show authenticated identity and subject | `openshell whoami` |
622626
| List/switch gateways | `openshell gateway select [name]` |
623627
| Connect directly to a gateway | `openshell --gateway-endpoint <url> status` |
624628
| Create sandbox (interactive) | `openshell sandbox create` |

‎.github/workflows/e2e-test.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ jobs:
5050
- suite: python
5151
cmd: "mise run --no-deps --skip-deps e2e:python"
5252
apt_packages: ""
53+
- suite: oidc-python
54+
cmd: "mise run --no-deps --skip-deps e2e:oidc-python:docker"
55+
apt_packages: ""
56+
- suite: oidc-pkce-docker
57+
cmd: "mise run --no-deps --skip-deps e2e:oidc-pkce:docker"
58+
apt_packages: "openssh-client"
5359
- suite: rust-docker
5460
cmd: "mise run --no-deps --skip-deps e2e:rust"
5561
apt_packages: "openssh-client"
@@ -111,7 +117,7 @@ jobs:
111117
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
112118

113119
- name: Install Python dependencies and generate protobuf stubs
114-
if: matrix.suite == 'python'
120+
if: matrix.suite == 'python' || matrix.suite == 'oidc-python'
115121
run: uv sync --frozen && mise run --no-deps python:proto
116122

117123
- name: Run tests

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎architecture/gateway.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,15 @@ does not grant sandbox identity. Kubernetes deployments use the
157157
gateway-minted JWT bootstrap path: the supervisor starts with a projected
158158
ServiceAccount token, exchanges it for a gateway-minted sandbox JWT, and uses
159159
that JWT on subsequent gateway RPCs.
160-
User-facing mutations are authorized by role policy when OIDC or edge identity
161-
is enabled.
160+
User-facing RPCs are authorized by descriptor-declared role and scope policy
161+
when OIDC or edge identity is enabled. The OIDC admin role grants platform-wide
162+
access and bypasses workspace membership checks. Workspace Admin and Workspace
163+
User roles are durable membership records keyed by workspace and authenticated
164+
subject. Handlers resolve the resource workspace and require sufficient
165+
membership after the middleware validates the global role and optional scope.
166+
The authenticated `GetCurrentUser` endpoint exposes the gateway's validated
167+
user subject, display name, roles, scopes, and identity provider for CLI
168+
identity inspection without client-side token decoding.
162169

163170
Sandbox secrets are gateway-signed JWTs bound to a single sandbox ID. Docker,
164171
Podman, and VM drivers deliver the initial token through supervisor-only

‎crates/openshell-cli/src/main.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ const HELP_TEMPLATE: &str = "\
263263
\x1b[1mGATEWAY COMMANDS\x1b[0m
264264
gateway: Manage gateways
265265
status: Show gateway status and information
266+
whoami: Show the authenticated user identity
266267
inference: Manage inference configuration
267268
doctor: Diagnose gateway issues
268269
@@ -588,6 +589,14 @@ enum Commands {
588589
output: OutputFormat,
589590
},
590591

592+
/// Show the identity validated by the gateway.
593+
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
594+
Whoami {
595+
/// Output format.
596+
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
597+
output: OutputFormat,
598+
},
599+
591600
/// Manage inference configuration.
592601
#[command(after_help = INFERENCE_EXAMPLES, help_template = SUBCOMMAND_HELP_TEMPLATE)]
593602
Inference {
@@ -2312,6 +2321,16 @@ async fn main() -> Result<()> {
23122321
}
23132322
}
23142323

2324+
// -----------------------------------------------------------
2325+
// Top-level current identity
2326+
// -----------------------------------------------------------
2327+
Some(Commands::Whoami { output }) => {
2328+
let ctx = resolve_gateway(&cli.gateway, &cli.gateway_endpoint)?;
2329+
let mut tls = tls.with_gateway_name(&ctx.name);
2330+
apply_auth(&mut tls, &ctx.name);
2331+
run::whoami(&ctx.endpoint, &tls, output.as_str()).await?;
2332+
}
2333+
23152334
// -----------------------------------------------------------
23162335
// Top-level forward (was `sandbox forward`)
23172336
// -----------------------------------------------------------
@@ -3924,6 +3943,19 @@ mod tests {
39243943
assert!(matches!(cli.command, Some(Commands::Status { .. })));
39253944
}
39263945

3946+
#[test]
3947+
fn whoami_accepts_output_json() {
3948+
let cli = Cli::try_parse_from(["openshell", "whoami", "--output", "json"])
3949+
.expect("whoami --output json should parse");
3950+
3951+
assert!(matches!(
3952+
cli.command,
3953+
Some(Commands::Whoami {
3954+
output: OutputFormat::Json
3955+
})
3956+
));
3957+
}
3958+
39273959
#[test]
39283960
fn gateway_info_accepts_output_json() {
39293961
let cli = Cli::try_parse_from(["openshell", "gateway", "info", "-o", "json"])

‎crates/openshell-cli/src/run.rs‎

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,21 @@ use openshell_core::proto::{
3838
CreateSandboxRequest, CreateSshSessionRequest, DeleteInferenceRouteRequest,
3939
DeleteProviderProfileRequest, DeleteProviderRefreshRequest, DeleteProviderRequest,
4040
DeleteSandboxRequest, DeleteServiceRequest, DetachSandboxProviderRequest, ExecSandboxRequest,
41-
ExposeServiceRequest, GetDraftHistoryRequest, GetDraftPolicyRequest, GetGatewayConfigRequest,
42-
GetInferenceRouteRequest, GetProviderProfileRequest, GetProviderRefreshStatusRequest,
43-
GetProviderRequest, GetSandboxConfigRequest, GetSandboxConfigResponse, GetSandboxLogsRequest,
44-
GetSandboxPolicyStatusRequest, GetSandboxRequest, GetServiceRequest, GpuResourceRequirements,
45-
ImportProviderProfilesRequest, LintProviderProfilesRequest, ListProviderProfilesRequest,
46-
ListProvidersRequest, ListSandboxPoliciesRequest, ListSandboxProvidersRequest,
47-
ListSandboxesRequest, ListServicesRequest, PolicySource, PolicyStatus, Provider,
48-
ProviderCredentialRefreshStatus, ProviderCredentialRefreshStrategy, ProviderProfile,
49-
ProviderProfileDiagnostic, ProviderProfileImportItem, RejectDraftChunkRequest,
50-
ResourceRequirements, RevokeSshSessionRequest, RotateProviderCredentialRequest, Sandbox,
51-
SandboxPhase, SandboxPolicy, SandboxSpec, SandboxTemplate, ServiceEndpointResponse,
52-
SetInferenceRouteRequest, SettingScope, TcpForwardFrame, TcpForwardInit, TcpRelayTarget,
53-
UpdateConfigRequest, UpdateProviderProfilesRequest, UpdateProviderRequest, WatchSandboxRequest,
54-
exec_sandbox_event, setting_value, tcp_forward_init,
41+
ExposeServiceRequest, GetCurrentUserRequest, GetDraftHistoryRequest, GetDraftPolicyRequest,
42+
GetGatewayConfigRequest, GetInferenceRouteRequest, GetProviderProfileRequest,
43+
GetProviderRefreshStatusRequest, GetProviderRequest, GetSandboxConfigRequest,
44+
GetSandboxConfigResponse, GetSandboxLogsRequest, GetSandboxPolicyStatusRequest,
45+
GetSandboxRequest, GetServiceRequest, GpuResourceRequirements, ImportProviderProfilesRequest,
46+
LintProviderProfilesRequest, ListProviderProfilesRequest, ListProvidersRequest,
47+
ListSandboxPoliciesRequest, ListSandboxProvidersRequest, ListSandboxesRequest,
48+
ListServicesRequest, PolicySource, PolicyStatus, Provider, ProviderCredentialRefreshStatus,
49+
ProviderCredentialRefreshStrategy, ProviderProfile, ProviderProfileDiagnostic,
50+
ProviderProfileImportItem, RejectDraftChunkRequest, ResourceRequirements,
51+
RevokeSshSessionRequest, RotateProviderCredentialRequest, Sandbox, SandboxPhase, SandboxPolicy,
52+
SandboxSpec, SandboxTemplate, ServiceEndpointResponse, SetInferenceRouteRequest, SettingScope,
53+
TcpForwardFrame, TcpForwardInit, TcpRelayTarget, UpdateConfigRequest,
54+
UpdateProviderProfilesRequest, UpdateProviderRequest, WatchSandboxRequest, exec_sandbox_event,
55+
setting_value, tcp_forward_init,
5556
};
5657
use openshell_core::settings;
5758
use openshell_core::{ObjectId, ObjectName, ObjectWorkspace};
@@ -115,6 +116,65 @@ impl ProgressOutput {
115116
}
116117
}
117118

119+
#[derive(Debug, Clone)]
120+
struct CurrentUserView {
121+
subject: String,
122+
display_name: Option<String>,
123+
roles: Vec<String>,
124+
scopes: Vec<String>,
125+
identity_provider: String,
126+
}
127+
128+
/// Show the identity validated by the selected gateway.
129+
pub async fn whoami(server: &str, tls: &TlsOptions, output: &str) -> Result<()> {
130+
let mut client = grpc_client(server, tls).await?;
131+
let identity = client
132+
.get_current_user(GetCurrentUserRequest {})
133+
.await
134+
.map_err(|err| match err.code() {
135+
Code::Unimplemented => miette!("whoami is not supported by this gateway version"),
136+
Code::Unauthenticated => miette!("whoami requires authentication: {err}"),
137+
_ => miette!("get_current_user failed: {err}"),
138+
})?
139+
.into_inner();
140+
141+
let view = CurrentUserView {
142+
subject: identity.subject,
143+
display_name: (!identity.display_name.is_empty()).then_some(identity.display_name),
144+
roles: identity.roles,
145+
scopes: identity.scopes,
146+
identity_provider: identity.identity_provider,
147+
};
148+
print_current_user(&view, output)
149+
}
150+
151+
fn print_current_user(view: &CurrentUserView, output: &str) -> Result<()> {
152+
if crate::output::print_output_single(output, view, current_user_to_json)? {
153+
return Ok(());
154+
}
155+
156+
println!("{}", "Current User".cyan().bold());
157+
println!();
158+
println!(" {} {}", "Subject:".dimmed(), view.subject);
159+
if let Some(display_name) = &view.display_name {
160+
println!(" {} {}", "Name:".dimmed(), display_name);
161+
}
162+
println!(" {} {}", "Provider:".dimmed(), view.identity_provider);
163+
println!(" {} {}", "Roles:".dimmed(), view.roles.join(", "));
164+
println!(" {} {}", "Scopes:".dimmed(), view.scopes.join(", "));
165+
Ok(())
166+
}
167+
168+
fn current_user_to_json(view: &CurrentUserView) -> serde_json::Value {
169+
serde_json::json!({
170+
"subject": &view.subject,
171+
"display_name": &view.display_name,
172+
"roles": &view.roles,
173+
"scopes": &view.scopes,
174+
"identity_provider": &view.identity_provider,
175+
})
176+
}
177+
118178
/// Validate system prerequisites for running a gateway.
119179
///
120180
/// Checks Docker connectivity and reports the result. Returns exit code 0
@@ -420,11 +480,17 @@ pub async fn sandbox_create(
420480
}
421481
None => None,
422482
};
423-
let providers_v2_enabled = gateway_providers_v2_enabled(&mut client).await?;
483+
let inferred_provider = inferred_provider_type(command);
484+
let providers_v2_enabled =
485+
if inferred_provider.is_some() && auto_providers_override != Some(false) {
486+
gateway_providers_v2_enabled(&mut client).await?
487+
} else {
488+
false
489+
};
424490
let inferred_types: Vec<String> = if providers_v2_enabled {
425491
Vec::new()
426492
} else {
427-
inferred_provider_type(command).into_iter().collect()
493+
inferred_provider.into_iter().collect()
428494
};
429495
let configured_providers = ensure_required_providers(
430496
&mut client,

‎crates/openshell-cli/tests/ensure_providers_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ impl TestOpenShell {
7979

8080
#[tonic::async_trait]
8181
impl OpenShell for TestOpenShell {
82+
async fn get_current_user(
83+
&self,
84+
_request: tonic::Request<openshell_core::proto::GetCurrentUserRequest>,
85+
) -> Result<Response<openshell_core::proto::GetCurrentUserResponse>, Status> {
86+
Err(Status::unimplemented("not used by this test server"))
87+
}
88+
8289
async fn health(
8390
&self,
8491
_request: tonic::Request<HealthRequest>,

‎crates/openshell-cli/tests/mtls_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ struct TestOpenShell;
3333

3434
#[tonic::async_trait]
3535
impl OpenShell for TestOpenShell {
36+
async fn get_current_user(
37+
&self,
38+
_request: tonic::Request<openshell_core::proto::GetCurrentUserRequest>,
39+
) -> Result<Response<openshell_core::proto::GetCurrentUserResponse>, Status> {
40+
Err(Status::unimplemented("not used by this test server"))
41+
}
42+
3643
async fn health(
3744
&self,
3845
_request: tonic::Request<HealthRequest>,

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ struct TestOpenShell {
9898

9999
#[tonic::async_trait]
100100
impl OpenShell for TestOpenShell {
101+
async fn get_current_user(
102+
&self,
103+
_request: tonic::Request<openshell_core::proto::GetCurrentUserRequest>,
104+
) -> Result<Response<openshell_core::proto::GetCurrentUserResponse>, Status> {
105+
Err(Status::unimplemented("not used by this test server"))
106+
}
107+
101108
async fn health(
102109
&self,
103110
_request: tonic::Request<HealthRequest>,

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::collections::HashMap;
3131
use std::fs;
3232
use std::os::unix::fs::PermissionsExt;
3333
use std::sync::Arc;
34-
use std::sync::atomic::{AtomicBool, Ordering};
34+
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
3535
use std::time::{Duration, Instant};
3636
use tempfile::TempDir;
3737
use tokio::net::TcpListener;
@@ -48,6 +48,7 @@ struct SandboxState {
4848
vm_slow_progress_before_ready: Arc<AtomicBool>,
4949
vm_log_churn_before_ready: Arc<AtomicBool>,
5050
global_settings: Arc<Mutex<HashMap<String, SettingValue>>>,
51+
gateway_config_requests: Arc<AtomicUsize>,
5152
}
5253

5354
#[derive(Clone, Default)]
@@ -57,6 +58,13 @@ struct TestOpenShell {
5758

5859
#[tonic::async_trait]
5960
impl OpenShell for TestOpenShell {
61+
async fn get_current_user(
62+
&self,
63+
_request: tonic::Request<openshell_core::proto::GetCurrentUserRequest>,
64+
) -> Result<Response<openshell_core::proto::GetCurrentUserResponse>, Status> {
65+
Err(Status::unimplemented("not used by this test server"))
66+
}
67+
6068
async fn health(
6169
&self,
6270
_request: tonic::Request<HealthRequest>,
@@ -182,6 +190,9 @@ impl OpenShell for TestOpenShell {
182190
&self,
183191
_request: tonic::Request<GetGatewayConfigRequest>,
184192
) -> Result<Response<GetGatewayConfigResponse>, Status> {
193+
self.state
194+
.gateway_config_requests
195+
.fetch_add(1, Ordering::SeqCst);
185196
Ok(Response::new(GetGatewayConfigResponse {
186197
settings: self.state.global_settings.lock().await.clone(),
187198
settings_revision: 1,
@@ -1208,6 +1219,40 @@ async fn sandbox_create_keeps_command_sessions_by_default() {
12081219
);
12091220
}
12101221

1222+
#[tokio::test]
1223+
async fn sandbox_create_without_inferred_provider_skips_gateway_config() {
1224+
let server = run_server().await;
1225+
let fake_ssh_dir = tempfile::tempdir().unwrap();
1226+
let xdg_dir = tempfile::tempdir().unwrap();
1227+
let _env = test_env(&fake_ssh_dir, &xdg_dir);
1228+
let tls = test_tls(&server);
1229+
install_fake_ssh(&fake_ssh_dir);
1230+
1231+
run::sandbox_create(
1232+
&server.endpoint,
1233+
"openshell",
1234+
run::SandboxCreateConfig {
1235+
name: Some("no-provider-config"),
1236+
command: &["echo".into(), "OK".into()],
1237+
..test_config()
1238+
},
1239+
"default",
1240+
&tls,
1241+
)
1242+
.await
1243+
.expect("sandbox create should succeed without reading gateway config");
1244+
1245+
assert_eq!(
1246+
server
1247+
.openshell
1248+
.state
1249+
.gateway_config_requests
1250+
.load(Ordering::SeqCst),
1251+
0,
1252+
"commands without an inferred provider must not require global gateway settings"
1253+
);
1254+
}
1255+
12111256
#[tokio::test]
12121257
async fn sandbox_create_sends_cpu_and_memory_limits_only() {
12131258
let server = run_server().await;

0 commit comments

Comments
 (0)