Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oss): support define sts endpoint for oss #448

Merged
merged 7 commits into from
Jun 28, 2024
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
9 changes: 9 additions & 0 deletions src/aliyun/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct Config {
/// - this field if it's `is_some`
/// - env value: [`ALIBABA_CLOUD_OIDC_TOKEN_FILE`]
pub oidc_token_file: Option<String>,
/// `sts_endpoint` will be loaded from
///
/// - this field if it's `is_some`
/// - env value: [`ALIBABA_CLOUD_STS_ENDPOINT`]
pub sts_endpoint: Option<String>,
}

impl Default for Config {
Expand All @@ -52,6 +57,7 @@ impl Default for Config {
role_session_name: "resign".to_string(),
oidc_provider_arn: None,
oidc_token_file: None,
sts_endpoint: None,
}
}
}
Expand Down Expand Up @@ -79,6 +85,9 @@ impl Config {
if let Some(v) = envs.get(ALIBABA_CLOUD_OIDC_TOKEN_FILE) {
self.oidc_token_file.get_or_insert(v.clone());
}
if let Some(v) = envs.get(ALIBABA_CLOUD_STS_ENDPOINT) {
self.sts_endpoint.get_or_insert(v.clone());
}

self
}
Expand Down
1 change: 1 addition & 0 deletions src/aliyun/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub const ALIBABA_CLOUD_SECURITY_TOKEN: &str = "ALIBABA_CLOUD_SECURITY_TOKEN";
pub const ALIBABA_CLOUD_ROLE_ARN: &str = "ALIBABA_CLOUD_ROLE_ARN";
pub const ALIBABA_CLOUD_OIDC_PROVIDER_ARN: &str = "ALIBABA_CLOUD_OIDC_PROVIDER_ARN";
pub const ALIBABA_CLOUD_OIDC_TOKEN_FILE: &str = "ALIBABA_CLOUD_OIDC_TOKEN_FILE";
pub const ALIBABA_CLOUD_STS_ENDPOINT: &str = "ALIBABA_CLOUD_STS_ENDPOINT";
9 changes: 8 additions & 1 deletion src/aliyun/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Loader {
let role_session_name = &self.config.role_session_name;

// Construct request to Aliyun STS Service.
let url = format!("https://sts.aliyuncs.com/?Action=AssumeRoleWithOIDC&OIDCProviderArn={}&RoleArn={}&RoleSessionName={}&Format=JSON&Version=2015-04-01&Timestamp={}&OIDCToken={}", provider_arn, role_arn, role_session_name, format_rfc3339(now()), token);
let url = format!("{}/?Action=AssumeRoleWithOIDC&OIDCProviderArn={}&RoleArn={}&RoleSessionName={}&Format=JSON&Version=2015-04-01&Timestamp={}&OIDCToken={}", self.get_sts_endpoint(), provider_arn, role_arn, role_session_name, format_rfc3339(now()), token);

let req = self.client.get(&url).header(
http::header::CONTENT_TYPE.as_str(),
Expand All @@ -163,6 +163,13 @@ impl Loader {

Ok(Some(cred))
}

fn get_sts_endpoint(&self) -> String {
match &self.config.sts_endpoint {
Some(defined_sts_endpoint) => format!("https://{}", defined_sts_endpoint),
None => "https://sts.aliyuncs.com".to_string(),
}
}
}

#[derive(Default, Debug, Deserialize)]
Expand Down
Loading