Lesson 11 β AWS Security Token Service (STS) & Temporary Credentials
Learning Path
βοΈ Phase 2 β AWS Cloud Security
π Module 02 β Identity & Access Management (IAM)
π― Lesson Objective
Section titled βπ― Lesson ObjectiveβBy the end of this lesson, you will be able to:
- Understand AWS Security Token Service (STS).
- Explain temporary security credentials.
- Learn how AssumeRole works.
- Understand session tokens.
- Access AWS resources securely using temporary credentials.
- Understand enterprise use cases for STS.
- Apply STS using the AWS CLI.
π Lesson Information
Estimated Time: 4 Hours
Difficulty: Intermediate
Prerequisites: Lesson 10 β AWS IAM Identity Center
Hands-on Lab: Yes
Assignment: Yes
πΌ Business Value
Section titled βπΌ Business ValueβModern enterprises rarely use permanent AWS Access Keys.
Instead, they rely on temporary credentials that automatically expire after a limited period.
This approach significantly reduces the risk of:
- Credential theft
- Long-term credential exposure
- Insider threats
- Accidental credential leaks
- Compliance violations
AWS Security Token Service (STS) is the service responsible for issuing these temporary credentials.
π’ In the Company
Section titled βπ’ In the CompanyβCloudNova Technologies has adopted a Zero Trust security model.
Developers, Security Engineers and automated workloads must access AWS resources without storing permanent credentials.
The CISO introduces the following policy:
βNo long-term AWS Access Keys should be stored on laptops, servers or applications. All access must use temporary credentials issued by AWS STS.β
Your responsibility is to understand how AWS STS provides secure, temporary access.
π What is AWS Security Token Service (STS)?
Section titled βπ What is AWS Security Token Service (STS)?βAWS Security Token Service (STS) is a global AWS service that issues temporary security credentials.
These credentials allow users, applications and AWS services to securely access AWS resources for a limited period.
Temporary credentials automatically expire, reducing the risk of compromise.
π What Are Temporary Credentials?
Section titled βπ What Are Temporary Credentials?βTemporary credentials consist of three components:
- Access Key ID
- Secret Access Key
- Session Token
Unlike permanent IAM User credentials, these credentials have an expiration time.
Once the session expires, the credentials can no longer be used.
π How STS Works
Section titled βπ How STS WorksβUser / Application
β
Requests Temporary Access
β
AWS STS
β
Issues Temporary Credentials
β
Access Key IDSecret Access KeySession Token
β
Access AWS Resources
β
Credentials Expire Automaticallyπ Why Temporary Credentials?
Section titled βπ Why Temporary Credentials?βCompared to permanent Access Keys, temporary credentials offer several advantages.
| Permanent Credentials | Temporary Credentials |
|---|---|
| Never expire | Expire automatically |
| Manual rotation required | Automatic expiration |
| Higher security risk | Reduced attack surface |
| Difficult to manage | Easier to manage |
| Common target for attackers | Less valuable if stolen |
π Common STS Operations
Section titled βπ Common STS OperationsβAWS STS supports several operations.
| Operation | Purpose |
|---|---|
| AssumeRole | Access resources using an IAM Role |
| GetSessionToken | Temporary credentials for IAM Users |
| GetCallerIdentity | Identify the current AWS identity |
| AssumeRoleWithSAML | Federation using SAML |
| AssumeRoleWithWebIdentity | Federation using external identity providers |
π What is AssumeRole?
Section titled βπ What is AssumeRole?βAssumeRole allows a user or application to temporarily become another IAM Role.
Instead of assigning permanent permissions, AWS grants temporary credentials for the duration of the session.
This is the most common STS operation used in enterprise environments.
π’ Enterprise Example
Section titled βπ’ Enterprise ExampleβCloudNova employs a Security Engineer named Alice.
Alice normally has read-only permissions.
When an incident occurs, she temporarily assumes the following role:
IncidentResponseRoleAWS STS issues temporary credentials valid for one hour.
Once the investigation is complete, the credentials expire automatically.
Alice returns to her normal permissions without any manual changes.
β± Session Duration
Section titled ββ± Session DurationβTemporary credentials remain valid only for a limited period.
Common session durations include:
- 15 minutes
- 1 hour
- 4 hours
- 8 hours
- 12 hours (depending on configuration)
After expiration, users must request new credentials.
π‘ Benefits of AWS STS
Section titled βπ‘ Benefits of AWS STSβ- No long-term credentials
- Automatic expiration
- Improved security
- Better auditing
- Supports cross-account access
- Supports federation
- Simplifies credential management
- Reduces credential theft risks
π Enterprise Use Cases
Section titled βπ Enterprise Use CasesβCloudNova uses AWS STS for:
- Cross-account administration
- Incident response
- CI/CD deployments
- AWS Lambda execution
- Amazon EC2 instance access
- Kubernetes workloads
- Temporary contractor access
- Federated workforce authentication
π« Common Mistakes
Section titled βπ« Common MistakesβAvoid the following:
β Hardcoding Access Keys in applications.
β Sharing IAM User credentials.
β Creating permanent administrator accounts.
β Ignoring credential expiration.
β Using the Root User for automation.
β Enterprise Best Practices
Section titled ββ Enterprise Best Practicesβ- Prefer IAM Roles over IAM Users.
- Use AssumeRole wherever possible.
- Rotate temporary sessions frequently.
- Enable CloudTrail logging.
- Monitor STS API calls.
- Follow Least Privilege.
- Require MFA for privileged role assumptions.
π§ͺ Enterprise Mission 01 β Identify Your Current Identity
Section titled βπ§ͺ Enterprise Mission 01 β Identify Your Current IdentityβOpen PowerShell.
Run:
aws sts get-caller-identityReview:
- Account ID
- User ARN
- User ID
Document your findings.
π§ͺ Enterprise Mission 02 β Review IAM Role
Section titled βπ§ͺ Enterprise Mission 02 β Review IAM RoleβNavigate to:
IAM
β
RolesSelect:
CloudEngineerRoleReview:
- Trust Policy
- Attached Policies
- Permissions
π§ͺ Enterprise Mission 03 β Assume an IAM Role
Section titled βπ§ͺ Enterprise Mission 03 β Assume an IAM RoleβRun:
aws sts assume-role \--role-arn arn:aws:iam::ACCOUNT_ID:role/CloudEngineerRole \--role-session-name CloudNovaSessionObserve the response.
It includes:
- AccessKeyId
- SecretAccessKey
- SessionToken
- Expiration
π§ͺ Enterprise Mission 04 β Configure Temporary Credentials
Section titled βπ§ͺ Enterprise Mission 04 β Configure Temporary CredentialsβStore the temporary credentials as environment variables.
PowerShell:
$Env:AWS_ACCESS_KEY_ID="TEMP_ACCESS_KEY"$Env:AWS_SECRET_ACCESS_KEY="TEMP_SECRET_KEY"$Env:AWS_SESSION_TOKEN="TEMP_SESSION_TOKEN"Verify the active identity.
aws sts get-caller-identityπ§ͺ Enterprise Mission 05 β Review Session Expiration
Section titled βπ§ͺ Enterprise Mission 05 β Review Session ExpirationβObserve the following field returned by STS.
ExpirationAnswer:
- When will the credentials expire?
- What happens after expiration?
- How should applications obtain new credentials?
π§ͺ Enterprise Mission 06 β Review CloudTrail Events
Section titled βπ§ͺ Enterprise Mission 06 β Review CloudTrail EventsβNavigate to:
CloudTrail
β
Event HistoryFilter for:
AssumeRoleReview:
- User
- Time
- Source IP
- Event Details
π§ͺ Enterprise Mission 07 β Security Investigation
Section titled βπ§ͺ Enterprise Mission 07 β Security InvestigationβCloudNova detects unusual activity.
CloudTrail shows multiple AssumeRole API calls originating from an unexpected IP address.
Investigate:
- Who assumed the role?
- Which role was used?
- When was it used?
- Was MFA required?
- What actions should be taken?
Document your findings.
π§ͺ Enterprise Mission 08 β Enterprise Design Exercise
Section titled βπ§ͺ Enterprise Mission 08 β Enterprise Design ExerciseβCloudNova has:
- Developers
- Security Engineers
- DevOps Engineers
- Third-party Consultants
Design a temporary credential strategy.
Include:
- Which users should use STS?
- Which roles should be assumed?
- Recommended session durations.
- Logging and monitoring requirements.
π’ Enterprise Scenario
Section titled βπ’ Enterprise ScenarioβCloudNova hires an external security consulting company for a two-week security assessment.
The consultants require temporary access to AWS resources.
Management does not want to:
- Create permanent IAM Users.
- Share administrator credentials.
- Leave unused accounts after the engagement ends.
Design a secure solution using AWS STS and IAM Roles.
π Knowledge Check
Section titled βπ Knowledge Checkβ-
What is AWS Security Token Service?
-
What are temporary security credentials?
-
Which three values make up temporary credentials?
-
What does AssumeRole do?
-
Why are temporary credentials more secure than permanent credentials?
-
Which CLI command identifies your current AWS identity?
-
What happens when temporary credentials expire?
-
Why is CloudTrail important when using STS?
-
Give three enterprise use cases for AWS STS.
-
Why do modern organisations prefer IAM Roles with STS?
π Assignment
Section titled βπ AssignmentβPrepare an AWS STS & Temporary Credentials Implementation Guide.
Include:
- STS Overview
- Temporary Credentials
- AssumeRole
- Session Tokens
- Enterprise Use Cases
- Security Benefits
- AWS CLI Commands Used
- CloudTrail Monitoring
- Lessons Learned
Length: 5β6 Pages
π Lesson Completion Checklist
Section titled βπ Lesson Completion Checklistβ| Task | Status |
|---|---|
| Reviewed Current Identity | β |
| Reviewed IAM Role | β |
| Assumed IAM Role | β |
| Configured Temporary Credentials | β |
| Verified Caller Identity | β |
| Reviewed CloudTrail Events | β |
| Completed Security Investigation | β |
| Completed Enterprise Design | β |
| Completed Assignment | β |
π‘ Key Takeaways
Section titled βπ‘ Key TakeawaysβAfter completing this lesson, you should understand:
- AWS Security Token Service (STS) provides temporary security credentials for secure access to AWS resources.
- Temporary credentials include an Access Key ID, Secret Access Key and Session Token, and expire automatically.
- The
AssumeRoleoperation enables secure, temporary access without sharing long-term credentials. - AWS STS is widely used for cross-account access, federation, automation and enterprise security.
- Using IAM Roles with AWS STS is a cloud security best practice that reduces the risk associated with permanent credentials.
π Further Reading
Section titled βπ Further Readingβ- AWS Security Token Service User Guide
- AWS IAM Roles Documentation
- AWS IAM Best Practices
- AWS CloudTrail User Guide
- AWS Well-Architected Framework β Security Pillar
π Next Lesson
Section titled βπ Next Lessonββ‘οΈ Lesson 12 β Cross-Account Access