Skip to content

Generate temporary security credentials without Amazon Secure Token Service.

0

Hi, I have a requirement to connect to an S3 bucket and perform some read/write operations on various S3 objects. To connect to S3 using C# AmazonS3Client(), Instead of using the permanent credentials (Access Key ID and Secret Access Key) from **Security Credentials ** section, I am trying to generate temporary security credentials and use them to connect to S3 using C# AmazonS3Client().

I evaluated the option of Amazon Secure Token Service (STS) and noticed that it requires the files config and credentials inside the .aws folder inside the logged in user profile directory. I don't want to store these permanent credentials (Access Key ID and Secret Access Key) locally and I am looking for an option to generate temporary security credentials without storing the permanent credentials locally on my machine.

I could see the below option of Retrieve security credentials from instance metadata for my use case: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-security-credentials.html Is my observation correct?

Also, I vaguely remember the above option is not supported and Amazon encourage to use Amazon VPC endpoint. Am I correct? Does using Amazon VPC provide the temporary security credentials to connect to S3?

Also, could you please help me if there are any other options for my use case to generate temporary security credentials without storing the permanent credentials locally on my machine.

-- Thanks PK

1 Answer
0

You're looking for ways to generate temporary security credentials without storing permanent credentials locally. Let me clarify your options:

First, your understanding about AWS STS is not entirely accurate. While AWS STS can use credentials from the .aws folder, it doesn't require storing permanent credentials locally. There are several approaches to obtain temporary credentials without storing permanent credentials on your machine:

  1. IAM Roles for EC2 Instances: If your application runs on an EC2 instance, you can assign an IAM role to the instance. The instance metadata service automatically provides temporary credentials to applications running on that instance. Your observation about retrieving security credentials from instance metadata is correct for this scenario. Applications can retrieve these credentials without any permanent credentials stored locally.

  2. IAM Roles for other AWS compute services: Similar to EC2, if you're using services like Lambda, ECS, or EKS, you can assign IAM roles to these resources, and they'll automatically receive temporary credentials.

  3. Identity Federation: You can use identity federation (SAML, OIDC, or custom federation) to authenticate users through an external identity provider and obtain temporary AWS credentials.

Regarding VPC endpoints: VPC endpoints don't provide temporary credentials themselves. They're a networking feature that allows private connectivity between your VPC and supported AWS services without requiring public internet access. While they enhance security by keeping traffic within the AWS network, they don't replace the need for authentication credentials.

For your specific C# use case with AmazonS3Client, if your application runs on an AWS compute service, the AWS SDK for .NET will automatically detect and use the role credentials without any explicit configuration. If running outside AWS, you'll need some form of authentication, but this could be through federation rather than storing permanent credentials.
Sources
Temporary security credentials in IAM - AWS Identity and Access Management
Programmatic access with AWS security credentials - AWS Identity and Access Management
Use temporary credentials with AWS resources - AWS Identity and Access Management

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.