Skip to content

Commit cb10f83

Browse files
committed
feat(providers): add AWS STS credential refresh and aws-s3 provider profile
Add server-side AWS STS AssumeRole credential refresh so gateways can mint short-lived AWS credentials for sandboxes. Combined with the SigV4 proxy re-signing from #1638, sandboxes can access S3 (and other AWS services) without ever seeing real credentials. ## STS credential refresh (server) - New `AwsStsAssumeRole` variant in `ProviderCredentialRefreshStrategy`. - `provider_refresh.rs` implements the refresh loop: calls `sts:AssumeRole` using the gateway's ambient AWS credentials (or explicit long-lived keys from material), stores the resulting `AccessKeyId`, `SecretAccessKey`, and `SessionToken` on the provider, and schedules re-rotation before expiry. - `ConfigureProviderRefresh` and `RotateProviderCredential` RPCs gated behind the `providers_v2_enabled` setting. Validates that configuring STS refresh for one provider won't collide with credential keys already held by another provider attached to the same sandbox. - Proto: `AWS_STS_ASSUME_ROLE = 3` on `ProviderCredentialRefreshStrategy`. ## Provider profiles: `aws` and `aws-s3` AWS provider profiles follow the same pattern as the existing `aws-bedrock` profile: a generic base plus service-specific variants. - `providers/aws.yaml`: base AWS profile with STS refresh material (role_arn, session_name, external_id, aws_region, optional long-lived keys) but no endpoints or binaries allowlist. Intended for AWS services that don't yet have a dedicated profile — the user attaches their own policy to supply endpoints. This is the same role `google-cloud` plays relative to `google-vertex-ai`. - `providers/aws-s3.yaml`: S3-specific profile that adds pre-configured endpoints covering regional (`*.s3.*.amazonaws.com`), global (`*.s3.amazonaws.com` with `signing_region: us-east-1`), and dualstack variants. All endpoints use `credential_signing: sigv4` and `signing_service: s3` so the proxy re-signs requests automatically. Includes a binaries allowlist for Python, curl, and the AWS CLI. - End-to-end walkthrough added in `examples/aws-s3-sts.md`. - Provider docs updated in `docs/sandboxes/manage-providers.mdx`. ## Policy: single-label `*` wildcard in middle DNS labels - `validate_host_wildcard` in `openshell-policy` now permits `*` as a complete middle label (e.g. `*.s3.*.amazonaws.com`) in addition to the existing leading-label and intra-label positions. A bare `*` label matches exactly one DNS label via Rego's `glob.match` with `.` separator, consistent with TLS wildcard semantics. - OPA endpoint matching and L7 config lookup updated to handle middle-label wildcards: `host_matches_wildcard_middle` rule and `endpoint_config_for_middle_wildcard` in Rego. - Validation rejects `**` in any position and partial wildcards in middle labels (e.g. `s*.example.com` in a non-leading label). ## SigV4 body validation fix - Allow bodyless requests (GET/HEAD/DELETE) through the SignBody path. boto3 sets `x-amz-content-sha256` to the empty-body hash on all requests, routing them through SignBody via `detect_payload_mode`. Previously `BodyLength::None` was rejected; now it signs with the empty-body hash, matching AWS SDK behavior. ## TUI - Added `AwsStsAssumeRole` match arm to the refresh strategy label in the provider settings view. Validated end-to-end: gateway mints STS credentials, sandbox runs boto3 PutObject/ListObjects/GetObject against real S3 through the SigV4 re-signing proxy. The sandbox sees only placeholder credentials. Signed-off-by: Russell Bryant <[email protected]>
1 parent 0a25fdf commit cb10f83

20 files changed

Lines changed: 1886 additions & 76 deletions

File tree

‎Cargo.lock‎

Lines changed: 382 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ tower-mcp-types = "0.12.0"
7878
# HTTP client
7979
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls-native-roots"] }
8080

81+
# AWS SDK
82+
aws-config = { version = "1", default-features = false, features = ["rustls", "rt-tokio", "behavior-version-latest"] }
83+
aws-sdk-sts = { version = "1", default-features = false, features = ["rustls", "rt-tokio", "behavior-version-latest"] }
84+
8185
# WebSocket
8286
tokio-tungstenite = { version = "0.26", features = ["rustls-tls-native-roots"] }
8387

‎architecture/security-policy.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,21 @@ request is denied.
4646
## Host Wildcards
4747

4848
Network endpoint `host` patterns accept a `*` wildcard inside the first DNS
49-
label only. The OPA runtime matches with a `.` label boundary, so a wildcard
50-
never spans dots. The validator enforces the same boundary so that policy load
51-
fails fast instead of silently mismatching at the proxy.
49+
label and as an entire middle DNS label. The OPA runtime matches with a `.`
50+
label boundary, so a wildcard never spans dots. The validator enforces the same
51+
boundary so that policy load fails fast instead of silently mismatching at the
52+
proxy.
5253

5354
| Pattern | Accepted | Example match | Notes |
5455
|---|---|---|---|
5556
| `*.example.com` | Yes | `api.example.com` | Single first label of any value. |
5657
| `**.example.com` | Yes | `a.b.example.com` | Recursive wildcard as the entire first label. |
5758
| `*-aiplatform.googleapis.com` | Yes | `us-central1-aiplatform.googleapis.com` | Intra-label wildcard inside the first DNS label. |
59+
| `*.s3.*.amazonaws.com` | Yes | `bucket.s3.us-east-1.amazonaws.com` | Middle-label `*` matches exactly one DNS label. |
5860
| `*` or `**` | No | — | Matches every host. |
5961
| `*.com`, `**.com` | No | — | TLD wildcards (`labels <= 2`). |
60-
| `foo.*.example.com` | No | — | Wildcard outside the first DNS label. |
62+
| `foo.us-*.example.com` | No | — | Partial middle-label wildcards are not allowed. |
63+
| `foo.**.example.com` | No | — | Recursive wildcard outside the first label is not allowed. |
6164
| `foo**.example.com` | No | — | Recursive `**` mixed inside a label; allowed only as the entire first label. |
6265

6366
Validation rejects the disallowed patterns at policy load time with a message

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ enum CliProviderRefreshStrategy {
692692
Oauth2RefreshToken,
693693
Oauth2ClientCredentials,
694694
GoogleServiceAccountJwt,
695+
AwsStsAssumeRole,
695696
}
696697

697698
impl CliProviderRefreshStrategy {
@@ -700,6 +701,7 @@ impl CliProviderRefreshStrategy {
700701
Self::Oauth2RefreshToken => "oauth2_refresh_token",
701702
Self::Oauth2ClientCredentials => "oauth2_client_credentials",
702703
Self::GoogleServiceAccountJwt => "google_service_account_jwt",
704+
Self::AwsStsAssumeRole => "aws_sts_assume_role",
703705
}
704706
}
705707
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5391,6 +5391,7 @@ fn provider_refresh_strategy(strategy: &str) -> Result<ProviderCredentialRefresh
53915391
"google_service_account_jwt" => {
53925392
Ok(ProviderCredentialRefreshStrategy::GoogleServiceAccountJwt)
53935393
}
5394+
"aws_sts_assume_role" => Ok(ProviderCredentialRefreshStrategy::AwsStsAssumeRole),
53945395
_ => Err(miette!("unsupported provider refresh strategy: {strategy}")),
53955396
}
53965397
}
@@ -5443,6 +5444,7 @@ fn provider_refresh_strategy_name(strategy: ProviderCredentialRefreshStrategy) -
54435444
ProviderCredentialRefreshStrategy::Oauth2RefreshToken => "oauth2_refresh_token",
54445445
ProviderCredentialRefreshStrategy::Oauth2ClientCredentials => "oauth2_client_credentials",
54455446
ProviderCredentialRefreshStrategy::GoogleServiceAccountJwt => "google_service_account_jwt",
5447+
ProviderCredentialRefreshStrategy::AwsStsAssumeRole => "aws_sts_assume_role",
54465448
ProviderCredentialRefreshStrategy::Unspecified => "unspecified",
54475449
}
54485450
}

‎crates/openshell-policy/src/lib.rs‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ pub enum PolicyViolation {
10741074
TooManyPaths { count: usize },
10751075
/// A network endpoint uses a TLD wildcard (e.g. `*.com`).
10761076
TldWildcard { policy_name: String, host: String },
1077+
/// A network endpoint uses a wildcard shape that does not match runtime semantics.
1078+
InvalidHostWildcard { policy_name: String, host: String },
10771079
/// `credential_signing` is set but `signing_service` is missing.
10781080
MissingSigningService { policy_name: String, host: String },
10791081
/// `credential_signing` has an unrecognized value.
@@ -1120,6 +1122,14 @@ impl fmt::Display for PolicyViolation {
11201122
use subdomain wildcards like '*.example.com' instead"
11211123
)
11221124
}
1125+
Self::InvalidHostWildcard { policy_name, host } => {
1126+
write!(
1127+
f,
1128+
"network policy '{policy_name}': invalid host wildcard '{host}'; \
1129+
middle DNS label wildcards must be the entire label '*' and recursive '**' \
1130+
is only allowed as the entire first label"
1131+
)
1132+
}
11231133
Self::MissingSigningService { policy_name, host } => {
11241134
write!(
11251135
f,
@@ -1249,6 +1259,12 @@ pub fn validate_sandbox_policy(
12491259
});
12501260
}
12511261
}
1262+
if host_wildcard_shape_invalid(&ep.host) {
1263+
violations.push(PolicyViolation::InvalidHostWildcard {
1264+
policy_name: name.clone(),
1265+
host: ep.host.clone(),
1266+
});
1267+
}
12521268
if !ep.credential_signing.is_empty()
12531269
&& !matches!(
12541270
ep.credential_signing.as_str(),
@@ -1283,6 +1299,25 @@ pub fn validate_sandbox_policy(
12831299
}
12841300
}
12851301

1302+
fn host_wildcard_shape_invalid(host: &str) -> bool {
1303+
if host == "*" || host == "**" {
1304+
return true;
1305+
}
1306+
if !host.contains('*') {
1307+
return false;
1308+
}
1309+
let labels: Vec<&str> = host.split('.').collect();
1310+
let first_label = labels.first().copied().unwrap_or_default();
1311+
if first_label.contains("**") && first_label != "**" {
1312+
return true;
1313+
}
1314+
labels
1315+
.iter()
1316+
.skip(1)
1317+
.copied()
1318+
.any(|label| label.contains("**") || (label.contains('*') && label != "*"))
1319+
}
1320+
12861321
/// Truncate a string for safe inclusion in error messages.
12871322
fn truncate_for_display(s: &str) -> String {
12881323
if s.len() <= 80 {
@@ -1809,6 +1844,33 @@ network_policies:
18091844
);
18101845
}
18111846

1847+
#[test]
1848+
fn validate_rejects_all_host_star_wildcards() {
1849+
for host in ["*", "**"] {
1850+
let mut policy = restrictive_default_policy();
1851+
policy.network_policies.insert(
1852+
"bad".into(),
1853+
NetworkPolicyRule {
1854+
name: "bad-rule".into(),
1855+
endpoints: vec![NetworkEndpoint {
1856+
host: host.into(),
1857+
port: 443,
1858+
..Default::default()
1859+
}],
1860+
..Default::default()
1861+
},
1862+
);
1863+
1864+
let violations = validate_sandbox_policy(&policy).unwrap_err();
1865+
assert!(
1866+
violations
1867+
.iter()
1868+
.any(|v| matches!(v, PolicyViolation::InvalidHostWildcard { .. })),
1869+
"expected bare host wildcard {host:?} to be rejected, got {violations:?}"
1870+
);
1871+
}
1872+
}
1873+
18121874
#[test]
18131875
fn validate_accepts_subdomain_wildcard() {
18141876
let mut policy = restrictive_default_policy();
@@ -1827,6 +1889,47 @@ network_policies:
18271889
assert!(validate_sandbox_policy(&policy).is_ok());
18281890
}
18291891

1892+
#[test]
1893+
fn validate_accepts_middle_label_star_wildcard() {
1894+
let mut policy = restrictive_default_policy();
1895+
policy.network_policies.insert(
1896+
"ok".into(),
1897+
NetworkPolicyRule {
1898+
name: "ok-rule".into(),
1899+
endpoints: vec![NetworkEndpoint {
1900+
host: "*.s3.*.amazonaws.com".into(),
1901+
port: 443,
1902+
..Default::default()
1903+
}],
1904+
..Default::default()
1905+
},
1906+
);
1907+
assert!(validate_sandbox_policy(&policy).is_ok());
1908+
}
1909+
1910+
#[test]
1911+
fn validate_rejects_partial_middle_label_wildcard() {
1912+
let mut policy = restrictive_default_policy();
1913+
policy.network_policies.insert(
1914+
"bad".into(),
1915+
NetworkPolicyRule {
1916+
name: "bad-rule".into(),
1917+
endpoints: vec![NetworkEndpoint {
1918+
host: "*.s3.us-*.amazonaws.com".into(),
1919+
port: 443,
1920+
..Default::default()
1921+
}],
1922+
..Default::default()
1923+
},
1924+
);
1925+
let violations = validate_sandbox_policy(&policy).unwrap_err();
1926+
assert!(
1927+
violations
1928+
.iter()
1929+
.any(|v| matches!(v, PolicyViolation::InvalidHostWildcard { .. }))
1930+
);
1931+
}
1932+
18301933
#[test]
18311934
fn validate_accepts_explicit_domain() {
18321935
let mut policy = restrictive_default_policy();

‎crates/openshell-providers/src/profiles.rs‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use std::sync::OnceLock;
2121
const PATH_TEMPLATE_CREDENTIAL_PLACEHOLDER: &str = "{credential}";
2222

2323
const BUILT_IN_PROFILE_YAMLS: &[&str] = &[
24+
include_str!("../../../providers/aws.yaml"),
2425
include_str!("../../../providers/aws-bedrock.yaml"),
26+
include_str!("../../../providers/aws-s3.yaml"),
2527
include_str!("../../../providers/claude-code.yaml"),
2628
include_str!("../../../providers/codex.yaml"),
2729
include_str!("../../../providers/copilot.yaml"),
@@ -639,6 +641,7 @@ pub fn provider_refresh_strategy_from_yaml(raw: &str) -> Option<ProviderCredenti
639641
"google_service_account_jwt" => {
640642
Some(ProviderCredentialRefreshStrategy::GoogleServiceAccountJwt)
641643
}
644+
"aws_sts_assume_role" => Some(ProviderCredentialRefreshStrategy::AwsStsAssumeRole),
642645
_ => None,
643646
}
644647
}
@@ -653,6 +656,7 @@ pub fn provider_refresh_strategy_to_yaml(
653656
ProviderCredentialRefreshStrategy::Oauth2RefreshToken => "oauth2_refresh_token",
654657
ProviderCredentialRefreshStrategy::Oauth2ClientCredentials => "oauth2_client_credentials",
655658
ProviderCredentialRefreshStrategy::GoogleServiceAccountJwt => "google_service_account_jwt",
659+
ProviderCredentialRefreshStrategy::AwsStsAssumeRole => "aws_sts_assume_role",
656660
ProviderCredentialRefreshStrategy::Unspecified => "unspecified",
657661
}
658662
}
@@ -2690,4 +2694,92 @@ endpoints:
26902694

26912695
assert!(matches!(err, ProfileError::InvalidEndpoint { id, .. } if id == "bad-endpoint"));
26922696
}
2697+
2698+
#[test]
2699+
fn aws_sts_strategy_serde_roundtrip() {
2700+
use openshell_core::proto::ProviderCredentialRefreshStrategy;
2701+
assert_eq!(
2702+
super::provider_refresh_strategy_from_yaml("aws_sts_assume_role"),
2703+
Some(ProviderCredentialRefreshStrategy::AwsStsAssumeRole)
2704+
);
2705+
assert_eq!(
2706+
super::provider_refresh_strategy_to_yaml(
2707+
ProviderCredentialRefreshStrategy::AwsStsAssumeRole
2708+
),
2709+
"aws_sts_assume_role"
2710+
);
2711+
}
2712+
2713+
#[test]
2714+
fn aws_profile_parses_correctly() {
2715+
let aws = get_default_profile("aws").expect("aws profile should exist");
2716+
assert_eq!(aws.display_name, "AWS");
2717+
assert_eq!(aws.credentials.len(), 3);
2718+
let access_key = aws
2719+
.credentials
2720+
.iter()
2721+
.find(|c| c.name == "access_key_id")
2722+
.unwrap();
2723+
assert!(access_key.refresh.is_some());
2724+
let refresh = access_key.refresh.as_ref().unwrap();
2725+
assert_eq!(
2726+
refresh.strategy,
2727+
openshell_core::proto::ProviderCredentialRefreshStrategy::AwsStsAssumeRole
2728+
);
2729+
assert!(
2730+
refresh
2731+
.material
2732+
.iter()
2733+
.any(|m| m.name == "role_arn" && m.required)
2734+
);
2735+
}
2736+
2737+
#[test]
2738+
fn aws_s3_profile_parses_with_endpoints() {
2739+
let aws_s3 = get_default_profile("aws-s3").expect("aws-s3 profile should exist");
2740+
assert_eq!(aws_s3.display_name, "AWS S3");
2741+
assert!(!aws_s3.endpoints.is_empty());
2742+
assert!(
2743+
!aws_s3
2744+
.endpoints
2745+
.iter()
2746+
.any(|e| e.host == "**.amazonaws.com")
2747+
);
2748+
assert!(
2749+
aws_s3
2750+
.endpoints
2751+
.iter()
2752+
.any(|e| e.host == "*.s3.amazonaws.com")
2753+
);
2754+
assert!(
2755+
aws_s3
2756+
.endpoints
2757+
.iter()
2758+
.any(|e| e.host == "s3.amazonaws.com")
2759+
);
2760+
assert!(
2761+
aws_s3
2762+
.endpoints
2763+
.iter()
2764+
.any(|e| e.host == "*.s3.*.amazonaws.com")
2765+
);
2766+
assert!(
2767+
aws_s3
2768+
.endpoints
2769+
.iter()
2770+
.any(|e| e.host == "s3.*.amazonaws.com")
2771+
);
2772+
assert!(
2773+
aws_s3
2774+
.endpoints
2775+
.iter()
2776+
.any(|e| e.host == "*.s3.dualstack.*.amazonaws.com")
2777+
);
2778+
assert!(
2779+
aws_s3
2780+
.endpoints
2781+
.iter()
2782+
.any(|e| e.host == "s3.dualstack.*.amazonaws.com")
2783+
);
2784+
}
26932785
}

‎crates/openshell-server/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ toml = { workspace = true }
8080
tokio-stream = { workspace = true }
8181
sqlx = { workspace = true }
8282
reqwest = { workspace = true }
83+
aws-config = { workspace = true }
84+
aws-sdk-sts = { workspace = true }
8385
uuid = { workspace = true }
8486
hmac = "0.12"
8587
sha2 = { workspace = true }

‎crates/openshell-server/src/grpc/policy.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ async fn profile_provider_policy_layers(
13671367
Ok(layers)
13681368
}
13691369

1370-
fn bool_setting_enabled(settings: &StoredSettings, key: &str) -> Result<bool, Status> {
1370+
pub(super) fn bool_setting_enabled(settings: &StoredSettings, key: &str) -> Result<bool, Status> {
13711371
match settings.settings.get(key) {
13721372
None => Ok(false),
13731373
Some(StoredSettingValue::Bool(value)) => Ok(*value),

0 commit comments

Comments
 (0)