mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
Support managed AWS access keys for Amazon Bedrock (#40481)
## What changed - Add the experimental `amazonBedrockAccessKeys` app-server login flow, persist its credentials in the configured auth store, and use them for SigV4-signed Bedrock requests. - Report `bedrockAccessKeys` as a distinct auth mode and document access-key login alongside AWS profile and environment credential setup. - Clear the selected Bedrock provider, AWS settings, and Bedrock-specific model on logout while leaving external AWS credentials and `.env` untouched. - Reject managed access-key login when higher-precedence configuration would prevent its region or profile settings from taking effect. ## Testing - Cover access-key login, storage, request signing, configuration conflicts, status reporting, and logout cleanup. GitOrigin-RevId: bbf297887c6503d3651ceb2aad85c4d626e32723
This commit is contained in:
1 parent
219c203417
commit
4f6d43c267
60 files changed
+1464
-389
No files matched your search
@@ -54,6 +54,11 @@ pub enum AuthMode {
|
||||
#[ts(rename = "bedrockApiKey")]
|
||||
#[strum(serialize = "bedrockApiKey")]
|
||||
BedrockApiKey,
|
||||
/// Amazon Bedrock AWS access keys managed by Codex.
|
||||
#[serde(rename = "bedrockAccessKeys")]
|
||||
#[ts(rename = "bedrockAccessKeys")]
|
||||
#[strum(serialize = "bedrockAccessKeys")]
|
||||
BedrockAccessKeys,
|
||||
}
|
||||
|
||||
impl AuthMode {
|
||||
@@ -61,7 +66,11 @@ impl AuthMode {
|
||||
pub fn has_chatgpt_account(self) -> bool {
|
||||
match self {
|
||||
Self::Chatgpt | Self::ChatgptAuthTokens | Self::PersonalAccessToken => true,
|
||||
Self::ApiKey | Self::Headers | Self::AgentIdentity | Self::BedrockApiKey => false,
|
||||
Self::ApiKey
|
||||
| Self::Headers
|
||||
| Self::AgentIdentity
|
||||
| Self::BedrockApiKey
|
||||
| Self::BedrockAccessKeys => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +82,7 @@ impl AuthMode {
|
||||
| Self::Headers
|
||||
| Self::AgentIdentity
|
||||
| Self::PersonalAccessToken => true,
|
||||
Self::ApiKey | Self::BedrockApiKey => false,
|
||||
Self::ApiKey | Self::BedrockApiKey | Self::BedrockAccessKeys => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3234,25 +3243,47 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn serialize_account_login_amazon_bedrock() -> Result<()> {
|
||||
let request = ClientRequest::LoginAccount {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: v2::LoginAccountParams::AmazonBedrock {
|
||||
api_key: "secret".to_string(),
|
||||
region: "us-west-2".to_string(),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
json!({
|
||||
"method": "account/login/start",
|
||||
"id": 2,
|
||||
"params": {
|
||||
for (params, expected_params) in [
|
||||
(
|
||||
v2::LoginAccountParams::AmazonBedrock {
|
||||
api_key: "secret".to_string(),
|
||||
region: "us-west-2".to_string(),
|
||||
},
|
||||
json!({
|
||||
"type": "amazonBedrock",
|
||||
"apiKey": "secret",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(&request)?,
|
||||
);
|
||||
}),
|
||||
),
|
||||
(
|
||||
v2::LoginAccountParams::AmazonBedrockAccessKeys {
|
||||
access_key_id: "access-key-id".to_string(),
|
||||
secret_access_key: "secret-access-key".to_string(),
|
||||
session_token: Some("session-token".to_string()),
|
||||
region: "us-west-2".to_string(),
|
||||
},
|
||||
json!({
|
||||
"type": "amazonBedrockAccessKeys",
|
||||
"accessKeyId": "access-key-id",
|
||||
"secretAccessKey": "secret-access-key",
|
||||
"sessionToken": "session-token",
|
||||
"region": "us-west-2"
|
||||
}),
|
||||
),
|
||||
] {
|
||||
let request = ClientRequest::LoginAccount {
|
||||
request_id: RequestId::Integer(2),
|
||||
params,
|
||||
};
|
||||
assert_eq!(
|
||||
json!({
|
||||
"method": "account/login/start",
|
||||
"id": 2,
|
||||
"params": expected_params,
|
||||
}),
|
||||
serde_json::to_value(&request)?,
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
json!({"type": "amazonBedrock"}),
|
||||
serde_json::to_value(v2::LoginAccountResponse::AmazonBedrock {})?,
|
||||
|
||||
@@ -106,6 +106,17 @@ pub enum LoginAccountParams {
|
||||
#[serde(rename = "amazonBedrock", rename_all = "camelCase")]
|
||||
#[ts(rename = "amazonBedrock", rename_all = "camelCase")]
|
||||
AmazonBedrock { api_key: String, region: String },
|
||||
/// [UNSTABLE] Managed Amazon Bedrock AWS access key login is experimental.
|
||||
#[experimental("account/login/start.amazonBedrockAccessKeys")]
|
||||
#[serde(rename = "amazonBedrockAccessKeys", rename_all = "camelCase")]
|
||||
#[ts(rename = "amazonBedrockAccessKeys", rename_all = "camelCase")]
|
||||
AmazonBedrockAccessKeys {
|
||||
access_key_id: String,
|
||||
secret_access_key: String,
|
||||
#[ts(optional = nullable)]
|
||||
session_token: Option<String>,
|
||||
region: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
|
||||
@@ -54,15 +54,6 @@ pub enum BedrockSetupParams {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(rename_all = "camelCase")]
|
||||
Environment { region: String },
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(rename_all = "camelCase")]
|
||||
AccessKeys {
|
||||
access_key_id: String,
|
||||
secret_access_key: String,
|
||||
#[ts(optional = nullable)]
|
||||
session_token: Option<String>,
|
||||
region: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
|
||||
Reference in new issue
Block a user