Skip to content

Commit e3ad817

Browse files
committed
feat(providers): AWS STS AssumeRole refresh strategy and aws-s3 profile
Add gateway-managed AWS STS credential refresh (provider-v2, NVIDIA#1576). The gateway calls sts:AssumeRole and writes three short-lived credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) to the provider record; the proxy re-signs requests with SigV4. Adds the aws and aws-s3 provider profiles and a declarative multi-output refresh model (additional_outputs) so one AssumeRole co-mints all three credentials. Hardening (from review): - Reject caller-supplied STS endpoint overrides; the endpoint is always region-resolved in production, test-only otherwise (CWE-918). - Validate a single canonical STS profile binding at configure (matching strategy, canonical AWS_ACCESS_KEY_ID primary, both declared outputs); remove the mint-path fallback to hardcoded sibling keys. - Require aws_access_key_id/aws_secret_access_key as a complete pair, with optional aws_session_token for temporary source credentials. - Enforce the providers_v2 gate on every mint (worker and manual rotate), not just at configure time. - Clear refresh-owned expiries for the primary and every pinned additional output inside the provider CAS closure, preserving independent changes. - Gate the provider credential write on refresh-generation ownership so a rotation cannot resurrect a deleted refresh or write stale-generation credentials (CWE-362). - Serialize refresh configuration against sandbox mutations to reserve credential keys atomically within a gateway process. - Return a typed Conflict for absent-row conditional writes instead of a backend-dependent error string. - Mirror runtime whole-middle-label host wildcard semantics in the prover. Signed-off-by: Russell Bryant <[email protected]>
1 parent 8029321 commit e3ad817

27 files changed

Lines changed: 4496 additions & 199 deletions

File tree

‎Cargo.lock‎

Lines changed: 385 additions & 56 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
@@ -79,6 +79,10 @@ tower-mcp-types = "0.12.0"
7979
# HTTP client
8080
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls-native-roots"] }
8181

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

‎architecture/gateway.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ state, SSH sessions, policy revisions, settings, inference configuration, and
259259
deployment records. Provider refresh material is stored as a separate object
260260
scoped to the provider instance through `objects.scope`; the provider record
261261
keeps only the current injectable credential values and optional per-credential
262-
expiry timestamps.
262+
expiry timestamps. A refresh normally mints one credential, but a strategy may
263+
co-mint several (AWS STS mints the access key, secret key, and session token in
264+
one call); the refresh state pins the resolved set of env keys it owns so
265+
collision checks reserve all of them before the first mint.
263266

264267
### Optimistic Concurrency (CAS)
265268

‎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
@@ -5464,6 +5464,7 @@ fn provider_refresh_strategy(strategy: &str) -> Result<ProviderCredentialRefresh
54645464
"google_service_account_jwt" => {
54655465
Ok(ProviderCredentialRefreshStrategy::GoogleServiceAccountJwt)
54665466
}
5467+
"aws_sts_assume_role" => Ok(ProviderCredentialRefreshStrategy::AwsStsAssumeRole),
54675468
_ => Err(miette!("unsupported provider refresh strategy: {strategy}")),
54685469
}
54695470
}
@@ -5516,6 +5517,7 @@ fn provider_refresh_strategy_name(strategy: ProviderCredentialRefreshStrategy) -
55165517
ProviderCredentialRefreshStrategy::Oauth2RefreshToken => "oauth2_refresh_token",
55175518
ProviderCredentialRefreshStrategy::Oauth2ClientCredentials => "oauth2_client_credentials",
55185519
ProviderCredentialRefreshStrategy::GoogleServiceAccountJwt => "google_service_account_jwt",
5520+
ProviderCredentialRefreshStrategy::AwsStsAssumeRole => "aws_sts_assume_role",
55195521
ProviderCredentialRefreshStrategy::Unspecified => "unspecified",
55205522
}
55215523
}

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,8 @@ pub enum PolicyViolation {
11091109
TooManyPaths { count: usize },
11101110
/// A network endpoint uses a TLD wildcard (e.g. `*.com`).
11111111
TldWildcard { policy_name: String, host: String },
1112+
/// A network endpoint uses a wildcard shape that does not match runtime semantics.
1113+
InvalidHostWildcard { policy_name: String, host: String },
11121114
/// `credential_signing` is set but `signing_service` is missing.
11131115
MissingSigningService { policy_name: String, host: String },
11141116
/// `credential_signing` has an unrecognized value.
@@ -1158,6 +1160,14 @@ impl fmt::Display for PolicyViolation {
11581160
use subdomain wildcards like '*.example.com' instead"
11591161
)
11601162
}
1163+
Self::InvalidHostWildcard { policy_name, host } => {
1164+
write!(
1165+
f,
1166+
"network policy '{policy_name}': invalid host wildcard '{host}'; \
1167+
middle DNS label wildcards must be the entire label '*' and recursive '**' \
1168+
is only allowed as the entire first label"
1169+
)
1170+
}
11611171
Self::MissingSigningService { policy_name, host } => {
11621172
write!(
11631173
f,
@@ -1288,6 +1298,12 @@ pub fn validate_sandbox_policy(
12881298
});
12891299
}
12901300
}
1301+
if host_wildcard_shape_invalid(&ep.host) {
1302+
violations.push(PolicyViolation::InvalidHostWildcard {
1303+
policy_name: name.clone(),
1304+
host: ep.host.clone(),
1305+
});
1306+
}
12911307
if !ep.credential_signing.is_empty()
12921308
&& !matches!(
12931309
ep.credential_signing.as_str(),
@@ -1322,6 +1338,25 @@ pub fn validate_sandbox_policy(
13221338
}
13231339
}
13241340

1341+
fn host_wildcard_shape_invalid(host: &str) -> bool {
1342+
if host == "*" || host == "**" {
1343+
return true;
1344+
}
1345+
if !host.contains('*') {
1346+
return false;
1347+
}
1348+
let labels: Vec<&str> = host.split('.').collect();
1349+
let first_label = labels.first().copied().unwrap_or_default();
1350+
if first_label.contains("**") && first_label != "**" {
1351+
return true;
1352+
}
1353+
labels
1354+
.iter()
1355+
.skip(1)
1356+
.copied()
1357+
.any(|label| label.contains("**") || (label.contains('*') && label != "*"))
1358+
}
1359+
13251360
/// Truncate a string for safe inclusion in error messages.
13261361
fn truncate_for_display(s: &str) -> String {
13271362
if s.len() <= 80 {
@@ -1848,6 +1883,33 @@ network_policies:
18481883
);
18491884
}
18501885

1886+
#[test]
1887+
fn validate_rejects_all_host_star_wildcards() {
1888+
for host in ["*", "**"] {
1889+
let mut policy = restrictive_default_policy();
1890+
policy.network_policies.insert(
1891+
"bad".into(),
1892+
NetworkPolicyRule {
1893+
name: "bad-rule".into(),
1894+
endpoints: vec![NetworkEndpoint {
1895+
host: host.into(),
1896+
port: 443,
1897+
..Default::default()
1898+
}],
1899+
..Default::default()
1900+
},
1901+
);
1902+
1903+
let violations = validate_sandbox_policy(&policy).unwrap_err();
1904+
assert!(
1905+
violations
1906+
.iter()
1907+
.any(|v| matches!(v, PolicyViolation::InvalidHostWildcard { .. })),
1908+
"expected bare host wildcard {host:?} to be rejected, got {violations:?}"
1909+
);
1910+
}
1911+
}
1912+
18511913
#[test]
18521914
fn validate_accepts_subdomain_wildcard() {
18531915
let mut policy = restrictive_default_policy();
@@ -1866,6 +1928,47 @@ network_policies:
18661928
assert!(validate_sandbox_policy(&policy).is_ok());
18671929
}
18681930

1931+
#[test]
1932+
fn validate_accepts_middle_label_star_wildcard() {
1933+
let mut policy = restrictive_default_policy();
1934+
policy.network_policies.insert(
1935+
"ok".into(),
1936+
NetworkPolicyRule {
1937+
name: "ok-rule".into(),
1938+
endpoints: vec![NetworkEndpoint {
1939+
host: "*.s3.*.amazonaws.com".into(),
1940+
port: 443,
1941+
..Default::default()
1942+
}],
1943+
..Default::default()
1944+
},
1945+
);
1946+
assert!(validate_sandbox_policy(&policy).is_ok());
1947+
}
1948+
1949+
#[test]
1950+
fn validate_rejects_partial_middle_label_wildcard() {
1951+
let mut policy = restrictive_default_policy();
1952+
policy.network_policies.insert(
1953+
"bad".into(),
1954+
NetworkPolicyRule {
1955+
name: "bad-rule".into(),
1956+
endpoints: vec![NetworkEndpoint {
1957+
host: "*.s3.us-*.amazonaws.com".into(),
1958+
port: 443,
1959+
..Default::default()
1960+
}],
1961+
..Default::default()
1962+
},
1963+
);
1964+
let violations = validate_sandbox_policy(&policy).unwrap_err();
1965+
assert!(
1966+
violations
1967+
.iter()
1968+
.any(|v| matches!(v, PolicyViolation::InvalidHostWildcard { .. }))
1969+
);
1970+
}
1971+
18691972
#[test]
18701973
fn validate_accepts_explicit_domain() {
18711974
let mut policy = restrictive_default_policy();

‎crates/openshell-prover/src/credentials.rs‎

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,39 @@ fn host_pattern_covers(pattern: &str, host: &str) -> bool {
186186
return false;
187187
};
188188

189+
// A leading `**` matches one or more leading labels; the remaining labels
190+
// match the tail of the host label-for-label, mirroring the runtime.
189191
if first_pattern_label == "**" {
190192
let suffix = &pattern_labels[1..];
191-
let host_suffix = host_labels
192-
.len()
193-
.checked_sub(suffix.len())
194-
.map(|start| &host_labels[start..]);
195-
return !suffix.is_empty()
196-
&& host_labels.len() > suffix.len()
197-
&& matches!(host_suffix, Some(host_suffix) if host_suffix == suffix);
193+
if suffix.is_empty() || host_labels.len() <= suffix.len() {
194+
return false;
195+
}
196+
let start = host_labels.len() - suffix.len();
197+
return labels_match(suffix, &host_labels[start..]);
198198
}
199199

200-
if !first_pattern_label.contains('*') {
201-
return false;
202-
}
200+
// Otherwise the pattern matches exactly one label per position. A `*` (or a
201+
// partial `*` glob) matches a single label, literal labels must be equal, and
202+
// wildcards may appear in any label — not just the first — to match the
203+
// runtime's whole-middle-label wildcards (e.g. `*.s3.*.amazonaws.com`).
204+
labels_match(&pattern_labels, &host_labels)
205+
}
203206

204-
// Runtime host wildcards only apply in the first DNS label. Wildcards in
205-
// later labels are not treated as policy globs here.
207+
/// Match `pattern_labels` against `host_labels` positionally: equal label counts,
208+
/// each `*`-bearing pattern label matched as a single-label glob and every other
209+
/// label compared literally.
210+
fn labels_match(pattern_labels: &[&str], host_labels: &[&str]) -> bool {
206211
pattern_labels.len() == host_labels.len()
207-
&& pattern_labels[1..] == host_labels[1..]
208-
&& wildcard_label_matches(first_pattern_label, host_labels[0])
212+
&& pattern_labels
213+
.iter()
214+
.zip(host_labels)
215+
.all(|(pattern, host)| {
216+
if pattern.contains('*') {
217+
wildcard_label_matches(pattern, host)
218+
} else {
219+
pattern == host
220+
}
221+
})
209222
}
210223

211224
fn wildcard_label_matches(pattern: &str, label: &str) -> bool {
@@ -419,10 +432,38 @@ mod tests {
419432
"api-*.github.com",
420433
"uploads.github.com"
421434
));
422-
assert!(!host_patterns_overlap(
435+
}
436+
437+
#[test]
438+
fn host_patterns_overlap_matches_whole_middle_label_wildcard() {
439+
// A `*` matches exactly one label in any position, mirroring the runtime
440+
// (e.g. the aws-s3 profile's `*.s3.*.amazonaws.com`).
441+
assert!(host_patterns_overlap(
423442
"api.*.github.com",
424443
"api.v3.github.com"
425444
));
445+
assert!(host_patterns_overlap(
446+
"*.s3.*.amazonaws.com",
447+
"bucket.s3.us-east-1.amazonaws.com"
448+
));
449+
assert!(host_patterns_overlap(
450+
"s3.*.amazonaws.com",
451+
"s3.eu-west-1.amazonaws.com"
452+
));
453+
// A single `*` label matches exactly one label — not zero, not several.
454+
assert!(!host_patterns_overlap(
455+
"s3.*.amazonaws.com",
456+
"s3.amazonaws.com"
457+
));
458+
assert!(!host_patterns_overlap(
459+
"*.s3.*.amazonaws.com",
460+
"bucket.s3.dualstack.us-east-1.amazonaws.com"
461+
));
462+
// A literal middle label must still match literally.
463+
assert!(!host_patterns_overlap(
464+
"api.*.github.com",
465+
"api.v3.gitlab.com"
466+
));
426467
}
427468

428469
#[test]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ pub use context::{DiscoveryContext, RealDiscoveryContext};
1919
pub use discovery::{discover_from_profile, discover_with_spec};
2020
pub use profiles::{
2121
CredentialRefreshProfile, ProfileError, ProfileValidationDiagnostic, ProviderTypeProfile,
22-
builtin_profiles, normalize_profile_id, parse_profile_json, parse_profile_yaml,
23-
profile_to_json, profile_to_yaml, profiles_to_json, profiles_to_yaml, validate_profile_set,
22+
builtin_profiles, is_gateway_mintable_strategy, normalize_profile_id, parse_profile_json,
23+
parse_profile_yaml, profile_to_json, profile_to_yaml, profiles_to_json, profiles_to_yaml,
24+
strategy_output_env_key, strategy_output_spec, strategy_primary_env_key, validate_profile_set,
2425
};
2526

2627
#[derive(Debug, thiserror::Error)]

0 commit comments

Comments
 (0)