-
Notifications
You must be signed in to change notification settings - Fork 404
Question: pod not using the role defined on the ServiceAccount (IRSA) when fetching secrets (defaults to the EC2 node's role) #452
Comments
Currently there are some issues with IRSA usage due to #442 but this sounds like another issue. Your assumption that the KES pods role should be used and there shouldn't be a need to specify a |
Looking at https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/TokenFileWebIdentityCredentials.html, it seems like it could be either an AWS SDK version issue (I haven't checked the versions yet). Or a bug in the AWS SDK
EDIT I ran the following commands in an interactive console on the KES pod (as outlined in here aws/aws-sdk-js#3090 (comment)):
And it assumes the correct identity. |
I believe that in your test you are running your pod as
Therefore you should try setting As a side note... I believe this is a rather obscure and confusing mechanism. People in AWS seem to think the same, see this comment. |
The pod's already running with Also, the test pod's not running as the root user. |
Also experiencing this with The |
@tymokvo just to confirm, you are saying the REPL commands does not return your expected role (ie the service account role)? |
Yes that's correct. It returns the role of the node. |
had the same issue, fixed by adding to values:
worth adding a note to readme perhaps to "2. IAM roles for service accounts."? comment in values.yaml is quite easy to miss especially for "still learning" k8s noobs like me :) |
I'm having the same issue as @tymokvo (also installing with kubectl instead of helm instal), the service account has a role set and I can see it when I run Already tried adding the securityContext like @aliusmiles said but that didn't work. This is part of the error KES throws |
Please provide more details on environment. EKS version at least :) When running in the pod please verify if you can read the file set in the AWS env |
This is our EKS cluster version:
Could this be a problem with the node's IAM role? I also see |
@Flydiverny My bad! Followed this to create the policy and the role for the service account: https://docs.aws.amazon.com/eks/latest/userguide/create-service-account-iam-policy-and-role.html
I can read it if |
For the AssumeRuleWithWebIdentity, we made a mistake with a change introduced in 4.1.0, the revert is merged but not released (I cannot cut releases, only godaddy guys can 🤷). So for that case please stick to 4.0.0 if you can for now.
Aight, yeah the Will make some tests on my EKS cluster. |
I get the same results as I got on Fargate #442 (comment) My helm value overrides: env:
AWS_REGION: eu-west-1
AWS_DEFAULT_REGION: eu-west-1
DISABLE_POLLING: true
LOG_LEVEL: debug
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111111111111:role/eksctl-fargate-test-kes-iamserviceaccount-role
image:
tag: 4.0.0
securityContext:
fsGroup: 65534 Installing using helm 3 (using chart version 5.0.0): helm install external-secrets external-secrets/kubernetes-external-secrets -f values.yaml Printing AWS envs in container ❯ k exec -it external-secrets-kubernetes-external-secrets-db59955b-gc2fj printenv | grep AWS_
AWS_DEFAULT_REGION=eu-west-1
AWS_ROLE_ARN=arn:aws:iam::111111111111:role/eksctl-fargate-test-kes-iamserviceaccount-role
AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
AWS_REGION=eu-west-1
apiVersion: 'kubernetes-client.io/v1'
kind: ExternalSecret
metadata:
name: hello-service-with-role
spec:
backendType: secretsManager
roleArn: arn:aws:iam::111111111111:role/direct-role
data:
- key: hello-service/password
name: password |
Ok, thank you for the feedback, I will try rolling back to |
@Flydiverny A few updates from our side: Now we have a role tied to our service account and it can fetch secrets without issues. apiVersion: v1
kind: ServiceAccount
metadata:
name: secrets-kubernetes-external-secrets
namespace: default
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam:: 111111111111:role/test-eks-secrets
labels:
app: kubernetes-external-secrets After that I tried setting a apiVersion: 'kubernetes-client.io/v1'
kind: ExternalSecret
metadata:
name: external-secret-test
spec:
backendType: secretsManager
roleArn: arn:aws:iam::111111111111:role/eks-test-mysecret-getter
dataFrom:
- path/to/mysecret So apparently this works on But, I could only make it work if the service account has a role attached to it, it doesn't need to have any policies attached, I'm using one without and that makes the trick I guess. |
Yes, the service account needs to have a role set, otherwise you wouldn't get the AWS envs set right? I take it you got this working by having a trust relationship for {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111111111111:oidc-provider/oidc.eks.eu-west-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B716D3041E"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringLike": {
"oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B716D3041E:sub": "system:serviceaccount:SERVICE_ACCOUNT_NAMESPACE:SERVICE_ACCOUNT_NAME"
}
}
}
]
} This isn't the intended behavior as this bypasses the role used by the external-secrets service. The intended setup is to have a trust relationship from {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/test-eks-secrets"
},
"Action": "sts:AssumeRole"
}
]
} |
I faced the same issue today, I am using version 5.2.0. My external secret's SA has the annotation: 'eks.amazonaws.com/role-arn: arn:aws:iam::something:role/secrets_manager' which has the policy that allows it to get secret values. However, when I do 'kubectl get externalsecret -n my-ns' I see an error which complains about the Node not being allowed to perform 'secretsmanager:GetSecretValue'. Is there a fix for this? ERROR, User: arn:aws:sts::something:assumed-role/node/i-something is not authorized to perform: secretsmanager:GetSecretValue on resource: arn:aws:secretsmanager:eu-central-1:something: secret: mykey-something My ExternalSecret looks like:
|
@larsrnielsen
|
You were right - I had a typo. Thanks, Lars |
I also had a typo in my policy config, which improved the situation. |
I have set up a serviceaccount with an AWS role, and the correct AssumeRoleWithWebIdentity policy on it. I run kubernetes-external-secrets under the serviceaccount, and here's what I have: |
It looks like the IRSA logic has been removed completely in 5.2 so stick with 5.1. I was also hitting EACCES errors on 5.1 when running with the Helm chart's default securityContext (non-root):
The solution is described above by @riccardomc and you can read more details here and here. |
Create a service account, a trust relationship for the service account (or annotate the one created by helm chart) serviceAccount:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111111111111:role/eksctl-fargate-test-kes-iamserviceaccount-role
securityContext:
fsGroup: 65534 Trust relation ship for {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111111111111:oidc-provider/oidc.eks.eu-west-1.amazonaws.com/id/F5C083E55DB8AE8A685E5F11E3DDCAB8"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringLike": {
"oidc.eks.eu-west-1.amazonaws.com/id/F5C083E55DB8AE8A685E5F11E3DDCAB8:sub": "system:serviceaccount:*"
}
}
}
]
} ^ you should really have something more specific so not all service accounts can assume this role.. Either attach permissons to this role so it can fetch your secrets. Or create a secondary IAM role {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/eksctl-fargate-test-kes-iamserviceaccount-role"
},
"Action": "sts:AssumeRole"
}
]
} and use this role in your external secrets by setting Notice the different Action specified in these trust relationships. Either you get: |
For me it was not having the AWS CLI client version 2 installed on my Jenkins Slave. In other words, even though I had setup a service account for my slaves and configured that service account to assume a role with the OIDC provider in my EKS cluster. My AWS client was still using the previous credentials chain e.g. the node role. The same is true of the AWS Java SDK. One needs to use version 2 in order to use the web identity credentials chain for AWS.
Changing the file permissions and container user to root also helped to prevent further errors with authorization and authentication. |
I had a similar issue. The problem was my apps that were running within the pods were using much older versions of the AWS SDK. https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts-minimum-sdk.html |
Hey, I see the same issue with:
I wanted to debug by using stsClient.getCallerIdentity(), but that did change the role ... To summarize:
|
Faced the same issue..Controller using Node-Instance-Role instead of IRSA role set in Service Account.
|
This is more of a question than an issue.
I am trying to integrate the kubernetes-external-secrets (KES) into EKS based kubernetes cluster. I was trying to use IRSA (IAM Roles For Service Accounts) to add authentication.
I have added the role-arn (that's attached to a policy that provides access to the secrets-manager) to the ServiceAccount for KES. I have verified that assuming this role using the following command allows the secrets to be fetched (I ran another container with AWS-CLI in it and had it attached to the same ServiceAccount I am using for KES):
This works correctly, and allows me to fetch secrets correctly (in that other container I ran).
However, the KES pod doesn't assume the correct role. It assumes the role that's attached to the EC2 instance on which it is running. Even though
AWS_ROLE_ARN
is set as an env-var.My main question is: why am I required to put the roleArn within the ExternalSecret if I have already specified the role-arn as an annotation on the service-account (which does get added to the pod as
AWS_ROLE_ARN
env-var). Shouldn't it fallback to using the role that's specified for the ServiceAccount as a default?It's certainly possible I'm misunderstanding things though. Also, if it turns out that what I was expecting should be the default behavior, I'd be happy to submit changes to the code.
The text was updated successfully, but these errors were encountered: