SlideShare a Scribd company logo
1 of 14
Download to read offline
Assuming AWS-roles in Playbooks
Doug Bridgens

heyjobs.de
27/Nov/2018
(experimental)
AWS Multi-Account Best Practice
Ansible + Admin Account = BFG
aws_assume_role_wrapper
- pre-checks
- try load from cache
- else call AWS sts-assume-role
- set convenience vars
- save tokens to cache
pre-checks
# tasks file for roles/aws_assume_role_wrapper
- name: Get the current caller identity facts
aws_caller_facts:
register: aws_caller_facts
- name: set caller facts
set_fact:
aws_user_name: "{{ aws_caller_facts.arn.split('/')[1] }}"
aws_user_account: "{{ aws_caller_facts.account }}"
- name: ensure we have a username set
fail:
msg: "aws_user_name or aws_user_account not defined..."
when:
- aws_user_name is undefined
- aws_user_account is undefined
Try load from cache
# tasks file for roles/aws_assume_role_wrapper
- name: "Check for {{ cache_path }}{{ cache_file_name }}"
find:
path: "{{ cache_path }}"
file_type: file
age: "{{ cache_time }}"
age_stamp: mtime
patterns: "{{ cache_file_name }}"
register: stat_cache_file
- include_vars:
file: "{{ cache_path }}{{ cache_file_name }}"
name: aws_assume_role
when:
- stat_cache_file.matched == 1
- stat_cache_file.files[0].size > 0
# defaults file for roles/aws_assume_role_wrapper
cache_path: ~/.aws/
cache_file_name: “ansible_aws_assume_role.
{{ aws_account_id }}.{{ aws_role_session_name }}.cache"
cache_time: -10m
vars:
tasks:
Else, call assume-role
# tasks file for roles/aws_assume_role_wrapper
- name: require user supplied MFA code
pause:
prompt: "Enter mfa to assume role: {{ aws_role_session_name }}"
register: user_supplied_mfa_code
when:
- aws_assume_role is undefined
- name: call aws-assume-role to get temp sts credentials
sts_assume_role:
mfa_serial_number: "arn:aws:iam::{{ aws_user_account }}:mfa/{{ aws_user_name }}"
mfa_token: "{{ user_supplied_mfa_code.user_input }}"
role_arn: "{{ switch_to_aws_role_arn }}"
role_session_name: "{{ aws_role_session_name }}"
register: assumed_role
when:
- aws_assume_role is undefined
Set facts (vars)
# tasks file for roles/aws_assume_role_wrapper
- name: convenience vars for AWS assumed-role credentials
set_fact:
sts_aws_access_key: "{{ assumed_role.sts_creds.access_key }}"
sts_aws_secret_key: "{{ assumed_role.sts_creds.secret_key }}"
sts_security_token: "{{ assumed_role.sts_creds.session_token }}"
sts_assumed_role_id: "{{ assumed_role.sts_user.assumed_role_id }}"
when:
- aws_assume_role is undefined
Finally Cache Credentials
# tasks file for roles/aws_assume_role_wrapper
- name: "cache aws-assume-role sts credentials to {{ cache_path }}{{ cache_file_name }}"
copy:
content: "{{ assumed_role }}"
dest: "{{ cache_path }}{{ cache_file_name }}"
when:
- aws_assume_role is undefined
Using Assume-Role in Playbooks
Using Assume-Role in Tasks
---
# tasks file for roles/aws_iam_create_dev_users
- name: "Create users: using {{ sts_assumed_role_id }}"
iam_user:
name: "{{ create_user }}"
state: present
aws_access_key: "{{ sts_aws_access_key }}"
aws_secret_key: "{{ sts_aws_secret_key }}"
security_token: "{{ sts_security_token }}"
Demo
Summary
Enables easy use of granular AWS-roles
Will be extended to override MFA requirement
Could be improved with cleaner caching mechanism
EOF

More Related Content

What's hot

How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patternsSamuel ROZE
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloadingHaresh Jaiswal
 
openCypher: Introducing subqueries
openCypher: Introducing subqueriesopenCypher: Introducing subqueries
openCypher: Introducing subqueriesopenCypher
 
Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015
Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015
Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015CODE BLUE
 
Open Source KMIP Implementation
Open Source KMIP ImplementationOpen Source KMIP Implementation
Open Source KMIP Implementationsedukull
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to djangoIlian Iliev
 
Debugging Python with Pdb!
Debugging Python with Pdb!Debugging Python with Pdb!
Debugging Python with Pdb!Noelle Daley
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basicsgourav kottawar
 
Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup Divyanshu
 
Advanced task management with Celery
Advanced task management with CeleryAdvanced task management with Celery
Advanced task management with CeleryMahendra M
 
Chap XIII : calcul scientifique avec python
Chap XIII : calcul scientifique avec pythonChap XIII : calcul scientifique avec python
Chap XIII : calcul scientifique avec pythonMohammed TAMALI
 
Sujets de preparation bac tp (sayari)
Sujets de preparation bac tp (sayari)Sujets de preparation bac tp (sayari)
Sujets de preparation bac tp (sayari)mohamed_SAYARI
 

What's hot (20)

How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
 
openCypher: Introducing subqueries
openCypher: Introducing subqueriesopenCypher: Introducing subqueries
openCypher: Introducing subqueries
 
Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015
Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015
Is there an EFI monster inside your apple? by Pedro Vilaça - CODE BLUE 2015
 
Open Source KMIP Implementation
Open Source KMIP ImplementationOpen Source KMIP Implementation
Open Source KMIP Implementation
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
Django Celery
Django Celery Django Celery
Django Celery
 
Debugging Python with Pdb!
Debugging Python with Pdb!Debugging Python with Pdb!
Debugging Python with Pdb!
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
 
Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup Pentest Application With GraphQL | Null Bangalore Meetup
Pentest Application With GraphQL | Null Bangalore Meetup
 
Jurnal metasploit(revisi)
Jurnal metasploit(revisi)Jurnal metasploit(revisi)
Jurnal metasploit(revisi)
 
Advanced task management with Celery
Advanced task management with CeleryAdvanced task management with Celery
Advanced task management with Celery
 
Chap XIII : calcul scientifique avec python
Chap XIII : calcul scientifique avec pythonChap XIII : calcul scientifique avec python
Chap XIII : calcul scientifique avec python
 
Sujets de preparation bac tp (sayari)
Sujets de preparation bac tp (sayari)Sujets de preparation bac tp (sayari)
Sujets de preparation bac tp (sayari)
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
The FatRat
The FatRatThe FatRat
The FatRat
 
Function in C
Function in CFunction in C
Function in C
 

Similar to Ansible Assume AWS Role

Terraform, Ansible, or pure CloudFormation?
Terraform, Ansible, or pure CloudFormation?Terraform, Ansible, or pure CloudFormation?
Terraform, Ansible, or pure CloudFormation?geekQ
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLIAmazon Web Services
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDanilo Poccia
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014Amazon Web Services
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014
(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014
(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014Amazon Web Services
 
테라폼스터디5주차 1편
테라폼스터디5주차 1편테라폼스터디5주차 1편
테라폼스터디5주차 1편choi sungwook
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
AWS Cloud Formation
AWS Cloud FormationAWS Cloud Formation
AWS Cloud FormationMahesh Raj
 
AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017
AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017
AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017Amazon Web Services
 
Masterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIMasterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIDanilo Poccia
 
Workshop: Building Your First Big Data Application on AWS
Workshop: Building Your First Big Data Application on AWSWorkshop: Building Your First Big Data Application on AWS
Workshop: Building Your First Big Data Application on AWSAmazon Web Services
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
Building Your First Big Data Application on AWS
Building Your First Big Data Application on AWSBuilding Your First Big Data Application on AWS
Building Your First Big Data Application on AWSAmazon Web Services
 
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014Amazon Web Services
 
best aws training in bangalore
best aws training in bangalorebest aws training in bangalore
best aws training in bangalorerajkamal560066
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With PythonLuca Mearelli
 

Similar to Ansible Assume AWS Role (20)

Terraform, Ansible, or pure CloudFormation?
Terraform, Ansible, or pure CloudFormation?Terraform, Ansible, or pure CloudFormation?
Terraform, Ansible, or pure CloudFormation?
 
CLI.pptx
CLI.pptxCLI.pptx
CLI.pptx
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014
(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014
(SEC302) Delegating Access to Your AWS Environment | AWS re:Invent 2014
 
테라폼스터디5주차 1편
테라폼스터디5주차 1편테라폼스터디5주차 1편
테라폼스터디5주차 1편
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
AWS Cloud Formation
AWS Cloud FormationAWS Cloud Formation
AWS Cloud Formation
 
AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017
AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017
AWS CLI: 2017 and Beyond - DEV307 - re:Invent 2017
 
Amazon ECS Deep Dive
Amazon ECS Deep DiveAmazon ECS Deep Dive
Amazon ECS Deep Dive
 
Masterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIMasterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLI
 
Workshop: Building Your First Big Data Application on AWS
Workshop: Building Your First Big Data Application on AWSWorkshop: Building Your First Big Data Application on AWS
Workshop: Building Your First Big Data Application on AWS
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Building Your First Big Data Application on AWS
Building Your First Big Data Application on AWSBuilding Your First Big Data Application on AWS
Building Your First Big Data Application on AWS
 
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
 
My First Big Data Application
My First Big Data ApplicationMy First Big Data Application
My First Big Data Application
 
best aws training in bangalore
best aws training in bangalorebest aws training in bangalore
best aws training in bangalore
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With Python
 

Recently uploaded

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingWSO2
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

Ansible Assume AWS Role

  • 1. Assuming AWS-roles in Playbooks Doug Bridgens heyjobs.de 27/Nov/2018 (experimental)
  • 3. Ansible + Admin Account = BFG
  • 4. aws_assume_role_wrapper - pre-checks - try load from cache - else call AWS sts-assume-role - set convenience vars - save tokens to cache
  • 5. pre-checks # tasks file for roles/aws_assume_role_wrapper - name: Get the current caller identity facts aws_caller_facts: register: aws_caller_facts - name: set caller facts set_fact: aws_user_name: "{{ aws_caller_facts.arn.split('/')[1] }}" aws_user_account: "{{ aws_caller_facts.account }}" - name: ensure we have a username set fail: msg: "aws_user_name or aws_user_account not defined..." when: - aws_user_name is undefined - aws_user_account is undefined
  • 6. Try load from cache # tasks file for roles/aws_assume_role_wrapper - name: "Check for {{ cache_path }}{{ cache_file_name }}" find: path: "{{ cache_path }}" file_type: file age: "{{ cache_time }}" age_stamp: mtime patterns: "{{ cache_file_name }}" register: stat_cache_file - include_vars: file: "{{ cache_path }}{{ cache_file_name }}" name: aws_assume_role when: - stat_cache_file.matched == 1 - stat_cache_file.files[0].size > 0 # defaults file for roles/aws_assume_role_wrapper cache_path: ~/.aws/ cache_file_name: “ansible_aws_assume_role. {{ aws_account_id }}.{{ aws_role_session_name }}.cache" cache_time: -10m vars: tasks:
  • 7. Else, call assume-role # tasks file for roles/aws_assume_role_wrapper - name: require user supplied MFA code pause: prompt: "Enter mfa to assume role: {{ aws_role_session_name }}" register: user_supplied_mfa_code when: - aws_assume_role is undefined - name: call aws-assume-role to get temp sts credentials sts_assume_role: mfa_serial_number: "arn:aws:iam::{{ aws_user_account }}:mfa/{{ aws_user_name }}" mfa_token: "{{ user_supplied_mfa_code.user_input }}" role_arn: "{{ switch_to_aws_role_arn }}" role_session_name: "{{ aws_role_session_name }}" register: assumed_role when: - aws_assume_role is undefined
  • 8. Set facts (vars) # tasks file for roles/aws_assume_role_wrapper - name: convenience vars for AWS assumed-role credentials set_fact: sts_aws_access_key: "{{ assumed_role.sts_creds.access_key }}" sts_aws_secret_key: "{{ assumed_role.sts_creds.secret_key }}" sts_security_token: "{{ assumed_role.sts_creds.session_token }}" sts_assumed_role_id: "{{ assumed_role.sts_user.assumed_role_id }}" when: - aws_assume_role is undefined
  • 9. Finally Cache Credentials # tasks file for roles/aws_assume_role_wrapper - name: "cache aws-assume-role sts credentials to {{ cache_path }}{{ cache_file_name }}" copy: content: "{{ assumed_role }}" dest: "{{ cache_path }}{{ cache_file_name }}" when: - aws_assume_role is undefined
  • 10. Using Assume-Role in Playbooks
  • 11. Using Assume-Role in Tasks --- # tasks file for roles/aws_iam_create_dev_users - name: "Create users: using {{ sts_assumed_role_id }}" iam_user: name: "{{ create_user }}" state: present aws_access_key: "{{ sts_aws_access_key }}" aws_secret_key: "{{ sts_aws_secret_key }}" security_token: "{{ sts_security_token }}"
  • 12. Demo
  • 13. Summary Enables easy use of granular AWS-roles Will be extended to override MFA requirement Could be improved with cleaner caching mechanism
  • 14. EOF