-
Notifications
You must be signed in to change notification settings - Fork 249
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
[request]: RDS generate-db-auth-token for IAM authentication #147
Comments
There doesn't seem to be a way to maintain a connection to RDS through IAM without this. The token only lives for 15 minutes. |
Hello, sorry for the long delay! This is actually an unmodeled operation (which is why we aren't generating it). Now that we support presigned urls (#157), you can use aws-sig-auth directly to generate the presigned URL use aws_smithy_http::body::SdkBody;
use aws_types::region::{Region, SigningRegion};
use aws_types::{Credentials, SigningService};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use aws_sig_auth::signer::{self, SigningError, OperationSigningConfig, HttpSignatureType, RequestConfig};
fn generate_rds_iam_token(
db_hostname: &str,
region: Region,
port: u16,
db_username: &str,
credentials: &Credentials,
) -> Result<String, SigningError> {
let signer = signer::SigV4Signer::new();
let mut operation_config = OperationSigningConfig::default_config();
operation_config.signature_type = HttpSignatureType::HttpRequestQueryParams;
operation_config.expires_in = Some(Duration::from_secs(15 * 60));
let request_config = RequestConfig {
request_ts: SystemTime::now(),
region: &SigningRegion::from(region),
service: &SigningService::from_static("rds-db"),
payload_override: None,
};
let mut request = http::Request::builder()
.uri(format!(
"http://{db_hostname}:{port}/?Action=connect&DBUser={db_user}",
db_hostname = db_hostname,
port = port,
db_user = db_username
))
.body(SdkBody::empty())
.expect("valid request");
let _signature = signer.sign(
&operation_config,
&request_config,
&credentials,
&mut request,
)?;
let mut uri = request.uri().to_string();
assert!(uri.starts_with("http://"));
let uri = uri.split_off("http://".len());
Ok(uri)
} |
This is amazing! I have RDS IAM auth working now. Shall I make a PR for an example with rust-postgres? // I did get this error when trying to use the
To get around this, I used let token = generate_rds_iam_token(...).map_err(|e| e as Box<dyn Error>)?;` |
that would be awesome! the final home of it would be here: https://github.com/awslabs/smithy-rs/tree/main/aws/sdk/examples/rds/src/bin |
|
This feature request is for generate-db-auth-token in RDS to enable IAM authentication.
Granting
rds_iam
to a user to enable IAM authentication disables password authentication so this would be helpful to stay with IAM auth.The typical usage is setting the environment variable
which is then used to authenticate using your chosen method, e.g. psql or JetBrains AWS Toolkit.
[1] generate-db-auth-token on AWS Docs
[2] How do I connect to my RDS PostgreSQL instance using IAM authentication?
Maintainers notes
The text was updated successfully, but these errors were encountered: