Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vault no longer respects AWS_ROLE_ARN or AWS_WEB_IDENTITY_TOKEN_FILE for AWS KMS #21478

Closed
dqsully opened this issue Jun 27, 2023 · 14 comments
Closed
Labels
auth/oidc core/seal ecosystem helmchart Helm chart for deploying Vault on Kubernetes. Also consider hashicorp/vault-helm k8s secret/aws

Comments

@dqsully
Copy link

dqsully commented Jun 27, 2023

Describe the bug
AWS KMS seals no longer respect the AWS_ROLE_ARN or AWS_WEB_IDENTITY_TOKEN_FILE environment variables, which are required for assuming IAM roles via Kubernetes ServiceAccount tokens. Instead, Vault attempts to use the EC2 instance's IAM role (if available) to access the KMS key instead of using the Kubernetes ServiceAccount.

To Reproduce
Steps to reproduce the behavior:

  1. Create an AWS EKS cluster
  2. Connect the EKS cluster as an OIDC provider for AWS IAM
  3. Create an AWS KMS key
  4. Create an AWS IAM role with an assume-role policy authorizing that OIDC provider, and an inline policy authorizing that IAM role for actions on the KMS key you created
  5. Deploy Vault with an "awskms" seal, setting only kms_key_id, and adding a ServiceAccount annotation eks.amazonaws.com/role-arn: <IAM role ARN>

Expected behavior
Vault should assume the IAM role configured in the Kubernetes ServiceAccount annotation and referenced by AWS_ROLE_ARN (injected by EKS because of the annotation), using the Kubernetes ServiceAccount token file referenced by AWS_WEB_IDENTITY_TOKEN_FILE (also injected by EKS) for authentication with AWS.

Environment:

  • Vault Server Version: 1.14.0
  • Server Operating System/Architecture: running on EKS 1.24, deployed using Vault's official Helm chart v0.25.0

Vault server configuration file(s):

ui = true
listener "tcp" {
  tls_disable = 1
  address = "[::]:8200"
  cluster_address = "[::]:8201"
  x_forwarded_for_authorized_addrs = ["####", "####"]
  x_forwarded_for_reject_not_present = false
}
storage "consul" {
  path = "vault"
  address = "HOST_IP:8500"
}

service_registration "kubernetes" {}

seal "awskms" {
  region     = "us-east-1"
  kms_key_id = "######"
}

Additional context
There is an easy workaround for this bug, which is to set role_arn and web_identity_token_file in the seal settings like so:

seal "awskms" {
  region     = "us-east-1"
  kms_key_id = "######"

  # Fixes for Vault 1.14+
  role_arn = "arn:aws:iam::<account ID>:role/<role name>"
  web_identity_token_file = "/var/run/secrets/eks.amazonaws.com/serviceaccount/token"
}

Also, as far as I could trace it, the issue seems to come from this list of approved(?) environment variables for the AWS KMS wrapper?: 254d8f8#diff-8669cb5f3518deb7d1841c405e7e8b222348751cf85f81e6077a1184e9ed767dR15-R23

Hopefully the fix is as easy as adding AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN to that list.

@ubajze
Copy link

ubajze commented Jun 27, 2023

We are running into a similar issue, but unfortunatelly the workaround is not working for us.

I still get:

vault Error parsing Seal configuration: error fetching AWS KMS wrapping key information: NoCredentialProviders: no valid providers in chain. Deprecated.
vault     For verbose messaging see aws.Config.CredentialsChainVerboseErrors

This is how our seal configuration looks like:

    # Auto unseal is enabled using the AWS KMS service
    seal "awskms" {
      region = "us-east-2"
      kms_key_id = "KMS_KEY_ID"
      web_identity_token_file = "/var/run/secrets/eks.amazonaws.com/serviceaccount/token"
    }

@dqsully
Copy link
Author

dqsully commented Jun 27, 2023

@ubajze I apologize, I was in a bit of a rush to solve this issue on our own side, and I missed that apparently the AWS_ROLE_ARN environment variable is also not being recognized, so you have to set the role_arn setting in the seal too. I did that on my own end just in case, but I assumed that it wasn't important. I'll update my original comment with that additional info.

@dqsully dqsully changed the title Vault no longer respects AWS_WEB_IDENTITY_TOKEN_FILE for AWS KMS Vault no longer respects AWS_ROLE_ARN or AWS_WEB_IDENTITY_TOKEN_FILE for AWS KMS Jun 27, 2023
@ubajze
Copy link

ubajze commented Jun 27, 2023

@dqsully it is working after adding the role_arn. Thank you for the update.

@heatherezell heatherezell added secret/aws ecosystem auth/oidc k8s helmchart Helm chart for deploying Vault on Kubernetes. Also consider hashicorp/vault-helm labels Jun 27, 2023
@dqsully
Copy link
Author

dqsully commented Jun 28, 2023

@hsimon-hashicorp I don't know the conventions here but would this be better labeled under core/seal since that's the component that's affected? It's unrelated to the AWS secrets backend or the OIDC auth method, and while my example runs on Kubernetes with the Helm chart, this issue isn't unique to Kubernetes.

@igor-nikiforov
Copy link

We have the same issue after upgrade to 1.14.0. This config no longer works:

seal "awskms" {
    region     = "${data.aws_region.current.name}"
    kms_key_id = "${module.aws_kms_key.key_id}"
}

@tolleiv
Copy link

tolleiv commented Jun 30, 2023

This seems to be also relevant for the s3 storage backend which doesn't support the web_identity_token_file and role_arn configuration.

@shivshav
Copy link

shivshav commented Jul 5, 2023

Same issue here. We're in the middle of trying to get IRSA incorporated into our environments when we upgraded our staging instance to 1.14.0 to account for this CVE

Looks like this may be related to this issue about the same thing with the storage configuration and potentially this issue in the go-secure-stdlib library?

@igoritos22
Copy link

We have the same situation here.
With same EKS and CHart versions.

@rissson
Copy link

rissson commented Jul 10, 2023

This also breaks the AWS secret backend.

@heatherezell
Copy link
Contributor

Hi folks, thanks for the issue report, the repro steps, and the comments about this problem! Our engineering teams are working on a fix to be included in an upcoming release. Thanks for your patience in the meantime!

@fairclothjm
Copy link
Contributor

Resolved by #21951.

The fix will be available in Vault v1.14.1

@Suman-Mohan
Copy link

Hi ,
We are still seeing similar issues in Vault v1.14.1 . Is anyone else still facing this issue?

@nitrogear
Copy link

I still can reproduce the issue. Used the latest helm chart v0.25.0 with Vault v1.14.0 and v1.14.1.
Nothing below helped:

  • I set env var AWS_ROLE_ARN
  • added annotation to SA vault with "eks.amazonaws.com/role-arn"
  • added role_arn/web_identity_token_file to CM
    Vault still uses IAM role assigned to EC2 instance, not the one I created for it
    Here is the error:
Error parsing Seal configuration: error fetching AWS KMS wrapping key information: AccessDeniedException: User: arn:aws:sts::XXX:assumed-role/qa-eks-worker-nodes-NodeInstanceRole-SBBNZTGPBP3D/i-0b1b5e3943a6479a7 is not authorized to perform: kms:DescribeKey on resource: arn:aws:kms:eu-central-1:XXX:key/31a61ccb-71f4-44a8-abab-c78487d43998 because no identity-based policy allows the kms:DescribeKey action
	status code: 400, request id: 10061045-418a-4639-9885-64b991c7c890

@nitrogear
Copy link

nitrogear commented Aug 3, 2023

I got it working with Vault v1.14.1
The issue was in SA annotation. If you don't add the annotation "eks.amazonaws.com/role-arn" to the Vault's SA account then EKS won't mount token "/var/run/secrets/eks.amazonaws.com/serviceaccount/token" to vault pod.
Without that Vault ignores role_arn/web_identity_token_file in the configuration file

jokestax added a commit to konstructio/gitops-template that referenced this issue Oct 16, 2024
* add eks cluster autoscaler

* add cluster autoscaler name

* add ploicy for defualt node group

* add cluster autoscaler policy

* attach more policies

* add support for gitlab

* feat: kubefirst pro chart (#807)

* set next macro chart for kubefirst - 2.6.2-rc9

* set next macro chart for kubefirst - 2.6.2-rc10

* set next macro chart for kubefirst - 2.6.2-rc11

* set next macro chart for kubefirst - 2.6.2-rc12

* set next macro chart for kubefirst - 2.6.2-rc13

* set next macro chart for kubefirst - 2.6.2-rc14

* set next macro chart for kubefirst - 2.6.2-rc15

* set next macro chart for kubefirst - 2.6.2-rc16

* set next macro chart for kubefirst - 2.6.2-rc17

* set next macro chart for kubefirst - 2.6.2-rc18

* set next macro chart for kubefirst - 2.6.2-rc19

* set next macro chart for kubefirst - 2.6.2-rc20

* set next macro chart for kubefirst - 2.6.2-rc21

* set next macro chart for kubefirst - 2.6.2-rc22

* fix: wait label (#809)

* set next macro chart for kubefirst - 2.6.2-rc23

* set next macro chart for kubefirst - 2.6.2-rc24

* set next macro chart for kubefirst - 2.6.2-rc25

* set next macro chart for kubefirst - 2.6.2-rc26

* set next macro chart for kubefirst - 2.6.2-rc27

* set next macro chart for kubefirst - 2.6.2-rc28

* add gpu and ollama

* add civo ai and ollama

* feat:add ai for gitlab

* add inline ingress and rename ai to gpu

* add sync wave

* fix gpu template

* change k8s version

* add comma

* fix name

* fix irsa for pro api

* add annotation for api

* edit structure of policy

* fix gpu gitlab

* scope down permission policy for vault sa

* fix: update vault version 1.14.1

hashicorp/vault#21478

* add comma

* feat: create irsa for cluster-autoscaler

* add pro to api sa

* add pro to api sa

---------

Co-authored-by: Cristhian Fernández <[email protected]>
Co-authored-by: konstruct-bot <[email protected]>
jokestax added a commit to konstructio/gitops-template that referenced this issue Oct 16, 2024
* add eks cluster autoscaler

* add cluster autoscaler name

* add ploicy for defualt node group

* add cluster autoscaler policy

* attach more policies

* add support for gitlab

* feat: kubefirst pro chart (#807)

* set next macro chart for kubefirst - 2.6.2-rc9

* set next macro chart for kubefirst - 2.6.2-rc10

* set next macro chart for kubefirst - 2.6.2-rc11

* set next macro chart for kubefirst - 2.6.2-rc12

* set next macro chart for kubefirst - 2.6.2-rc13

* set next macro chart for kubefirst - 2.6.2-rc14

* set next macro chart for kubefirst - 2.6.2-rc15

* set next macro chart for kubefirst - 2.6.2-rc16

* set next macro chart for kubefirst - 2.6.2-rc17

* set next macro chart for kubefirst - 2.6.2-rc18

* set next macro chart for kubefirst - 2.6.2-rc19

* set next macro chart for kubefirst - 2.6.2-rc20

* set next macro chart for kubefirst - 2.6.2-rc21

* set next macro chart for kubefirst - 2.6.2-rc22

* fix: wait label (#809)

* set next macro chart for kubefirst - 2.6.2-rc23

* set next macro chart for kubefirst - 2.6.2-rc24

* set next macro chart for kubefirst - 2.6.2-rc25

* set next macro chart for kubefirst - 2.6.2-rc26

* set next macro chart for kubefirst - 2.6.2-rc27

* set next macro chart for kubefirst - 2.6.2-rc28

* add gpu and ollama

* add civo ai and ollama

* feat:add ai for gitlab

* add inline ingress and rename ai to gpu

* add sync wave

* fix gpu template

* change k8s version

* add comma

* fix name

* fix irsa for pro api

* add annotation for api

* edit structure of policy

* fix gpu gitlab

* scope down permission policy for vault sa

* fix: update vault version 1.14.1

hashicorp/vault#21478

* add comma

* feat: create irsa for cluster-autoscaler

* add pro to api sa

* add pro to api sa

---------

Co-authored-by: Cristhian Fernández <[email protected]>
Co-authored-by: konstruct-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth/oidc core/seal ecosystem helmchart Helm chart for deploying Vault on Kubernetes. Also consider hashicorp/vault-helm k8s secret/aws
Projects
None yet
Development

No branches or pull requests