热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Doesn'taskMFAtokencodewhenusingassume_rolewithMFArequired

WhenusingmultipleAWSaccountsitsgoodpracticetoonlyallowaccessviaAssumeRole

When using multiple AWS accounts it's good practice to only allow access via AssumeRole from a master account. This can be done with or without requiring MFA. Terraform supports assume_role with s3 state file and aws provider configurations, but doesn't seem to ask the MFA token code when one is required. This prevents using AssumeRole for credentials when MFA is required.

AWS documentation describing MFA with cross account AssumeRole: http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_configure-api-require.html#MFAProtectedAPI-cross-account-delegation

Terraform Version

1
2
$ terraform --version

Terraform v0.11.0


Affected Resource(s)

Both of these support assume_role, so they should also support asking for MFA token code:
- S3 backend configuration
- AWS provider configuration

Terraform Configuration Files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
hcl

terraform {

  backend "s3" {

    bucket = "terraform-state-bucket"

    key = "tf-state"

    region = "eu-west-1"

    role_arn = "arn:aws:iam::916005212345:role/OrganizationAccountAccessRole"

  }

}

provider "aws" {

  region = "eu-west-1"

  assume_role {

    role_arn = "arn:aws:iam::916005212345:role/OrganizationAccountAccessRole"

    session_name = "terraform-session"

  }

}


Actual Behavior (with DEBUG)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$ TF_LOG=debug terraform init

2017/11/23 13:36:12 [INFO] Terraform version: 0.11.0  

2017/11/23 13:36:12 [INFO] Go runtime version: go1.9.2

2017/11/23 13:36:12 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.11.0/bin/terraform", "init"}

2017/11/23 13:36:12 [DEBUG] Attempting to open CLI config file: /Users/***/.terraformrc

2017/11/23 13:36:12 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.

2017/11/23 13:36:12 [INFO] CLI command args: []string{"init"}

2017/11/23 13:36:12 [DEBUG] command: loading backend config file: /Users/***



Initializing the backend...

2017/11/23 13:36:12 [WARN] command: backend config change! saved: 16375281725947963338, new: 2383462577283113429

Backend configuration changed!



Terraform has detected that the configuration specified for the backend

has changed. Terraform will now reconfigure for this backend. If you didn't

intend to reconfigure your backend please undo any changes to the "backend"

section in your Terraform configuration.





2017/11/23 13:36:12 [INFO] Building AWS region structure

2017/11/23 13:36:12 [INFO] Building AWS auth structure

2017/11/23 13:36:12 [INFO] Setting AWS metadata API timeout to 100ms

2017/11/23 13:36:13 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id

2017/11/23 13:36:13 [INFO] Attempting to AssumeRole arn:aws:iam::***:role/OrganizationAccountAccessRole (SessionName: "", ExternalId: "", Policy: "")

2017/11/23 13:36:13 [INFO] AWS Auth provider used: "SharedCredentialsProvider"

2017/11/23 13:36:13 [DEBUG] plugin: waiting for all plugin processes to complete...

Error initializing new backend:

Error configuring the backend "s3": The role "arn:aws:iam::***:role/OrganizationAccountAccessRole" cannot be assumed.



  There are a number of possible causes of this - the most common are:

    * The credentials used in order to assume the role are invalid

    * The credentials do not have appropriate permission to assume the role

    * The role ARN is not valid



Please update the configuration in your Terraform files to fix this error

then run this command again.

该提问来源于开源项目:terraform-providers/terraform-provider-aws

1
2
3
4
5
6
7
8
9
10
11
12
13
14
provider "aws" {

  profile = "prod"

  region  = "eu-west-1"

  version = "3.4.0"

}

terraform {

  required_version = "0.13.2"

  backend "s3" {

    profile        = "prod"

    region         = "eu-west-1"

    dynamodb_table = "terraform-locks"

    bucket         = "prod-terraform-states"

  }

}

Also you could check with



1
2
export AWS_SDK_LOAD_CONFIG=1

aws --profile prod sts get-caller-identity

it should use credentials from aws-vault and ask for mfa only once

or run aws-vault directly:



1
env AWS_SDK_LOAD_CONFIG=0 aws-vault --some-backend-options --prompt=osascript exec --region eu-west-1 --duration=1h root --json



   



推荐阅读
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • 如何去除Win7快捷方式的箭头
    本文介绍了如何去除Win7快捷方式的箭头的方法,通过生成一个透明的ico图标并将其命名为Empty.ico,将图标复制到windows目录下,并导入注册表,即可去除箭头。这样做可以改善默认快捷方式的外观,提升桌面整洁度。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • Firefox火狐浏览器关闭到http://detectportal.firefox.com的流量问题解决办法
    本文介绍了使用Firefox火狐浏览器时出现关闭到http://detectportal.firefox.com的流量问题,并提供了解决办法。问题的本质是因为火狐默认开启了Captive portal技术,当连接需要认证的WiFi时,火狐会跳出认证界面。通过修改about:config中的network.captive-portal-service.en的值为false,可以解决该问题。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 使用在线工具jsonschema2pojo根据json生成java对象
    本文介绍了使用在线工具jsonschema2pojo根据json生成java对象的方法。通过该工具,用户只需将json字符串复制到输入框中,即可自动将其转换成java对象。该工具还能解析列表式的json数据,并将嵌套在内层的对象也解析出来。本文以请求github的api为例,展示了使用该工具的步骤和效果。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
  • 本文讨论了如何使用IF函数从基于有限输入列表的有限输出列表中获取输出,并提出了是否有更快/更有效的执行代码的方法。作者希望了解是否有办法缩短代码,并从自我开发的角度来看是否有更好的方法。提供的代码可以按原样工作,但作者想知道是否有更好的方法来执行这样的任务。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 本文介绍了如何清除Eclipse中SVN用户的设置。首先需要查看使用的SVN接口,然后根据接口类型找到相应的目录并删除相关文件。最后使用SVN更新或提交来应用更改。 ... [详细]
author-avatar
阳光-沙滩男人
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有