热门标签 | 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



   



推荐阅读
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 本文介绍了如何使用JQuery实现省市二级联动和表单验证。首先,通过change事件监听用户选择的省份,并动态加载对应的城市列表。其次,详细讲解了使用Validation插件进行表单验证的方法,包括内置规则、自定义规则及实时验证功能。 ... [详细]
  • XNA 3.0 游戏编程:从 XML 文件加载数据
    本文介绍如何在 XNA 3.0 游戏项目中从 XML 文件加载数据。我们将探讨如何将 XML 数据序列化为二进制文件,并通过内容管道加载到游戏中。此外,还会涉及自定义类型读取器和写入器的实现。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细介绍了如何解决Uploadify插件在Internet Explorer(IE)9和10版本中遇到的点击失效及JQuery运行时错误问题。通过修改相关JavaScript代码,确保上传功能在不同浏览器环境中的一致性和稳定性。 ... [详细]
  • 本文介绍了如何利用JavaScript或jQuery来判断网页中的文本框是否处于焦点状态,以及如何检测鼠标是否悬停在指定的HTML元素上。 ... [详细]
  • 导航栏样式练习:项目实例解析
    本文详细介绍了如何创建一个具有动态效果的导航栏,包括HTML、CSS和JavaScript代码的实现,并附有详细的说明和效果图。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 在前两篇文章中,我们探讨了 ControllerDescriptor 和 ActionDescriptor 这两个描述对象,分别对应控制器和操作方法。本文将基于 MVC3 源码进一步分析 ParameterDescriptor,即用于描述 Action 方法参数的对象,并详细介绍其工作原理。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
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社区 版权所有