Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Use of "iam.amazonaws.com/permitted" annotation causes conflicts with existing KIAM setups #174

Closed
1 task done
mmcaya opened this issue Oct 14, 2019 · 2 comments · Fixed by #179
Closed
1 task done

Comments

@mmcaya
Copy link

mmcaya commented Oct 14, 2019

I'm submitting a...

  • bug report

Issue 1:

What is the current behavior?

Kubernetes external secrets errors out when iam.amazonaws.com/permitted is present, has valid values intended for kiam, but is not provided a roleArn in the ExternalSecret descriptor.

This is a common use case when kiam is handling the IAM for the kubernetes-external-secret operator, and no additional role assumption is required by the individual ExternalSecret resources

To reproduce:

kind: ExternalSecret
metadata:
  annotations:
  name: test-service
secretDescriptor:
 #No Role ARN Provided
  backendType: secretsManager
  data:
  - key: test-service/password
    name: password

Namespace annotated for kiam support only:

kind: Namespace
metadata:
  annotations:
    iam.amazonaws.com/permitted: my-kiam-roles.* 
{"level":50,"time":XXX,"pid":16,"hostname":"XXX","type":"Error","stack":"Error: not allowed to fetch secret: test-service: namspace does not allow to assume role undefined
    at Poller._upsertKubernetesSecret (/app/lib/poller.js:110:14)
    at process._tickCallback (internal/process/next_tick.js:68:7)","msg":"failure while polling the secret test-service","v":1}

What's the expected behavior?

Secret sync should be allowed when namespace annotation is present, and no roleArn is provided.

{
     // test undefined
     ns: { metadata: { annotations: { 'iam.amazonaws.com/permitted': 'my-kiam-role.*' } } },
     descriptor: { roleArn: undefined },
     permitted: true
}, 

Issue 2

What is the current behavior?

kiam or kubernetes-external-secrets will now incorrectly permit (i.e. pass the regex and proceed to attempt an sts call) assumption of roles in a namespace not intended to be used by kiam or kubernetes-external-secrets. The sharing of an annotation allows for nondeterministic behavior from each operator when used at the same time.

Scenario (AWS ARNs truncated for brevity):

  • kubernetes external secret controller uses kiam to assume roles for processing, with that role (and all other allowed kiam roles) covered by the iam.amazonaws.com/permitted: kiam-roles.* annotation on the namespace

  • kubernetes external secrets ExternalSecret has a desired roleArn value my-team-external-secret-role.*

  • kiam policies are attached to kiam-server pods, and have no knowledge of ExternalSecret level kubernetes-external-secret role / polices

  • kubernetes-external-secret policies are assumed at runtime from the kubernetes-external-secret controller AFTER it assumes a role via kiam, and have no knowledge of all the other kiam level role / polices

In order to support this, one of the following must now happen:

  • regex updated to support both patterns: (kiam|my-team-external-secret-role).*
    • now kiam OR kubernetes-external-secrets is "permitting" roles they can not actually assume
  • naming convention updated to support a single shared pattern: namespace-iam-roles.*
    • same result, kiam OR kubernetes-external-secrets is still "permitting" roles they can not actually assume

What's the expected behavior?

One of the following should be done to kubernetes-external-secrets prevent conflicts

  • Backwards Compatible Break - change the support annotation for kubernetes-external-secrets to be something under the existing CRD naming of externalsecrets.kubernetes-client.io,

  • Allow the annotation to be configurable so that both kiam and kubernetes-external-secrets can run without conflict

  • Explicitly document this issue in the README.md

@mmcaya mmcaya changed the title Use of iam.amazonaws.com/permitted annotation causes conflicts with existing KIAM setups Use of "iam.amazonaws.com/permitted" annotation causes conflicts with existing KIAM setups Oct 15, 2019
@moolen
Copy link
Member

moolen commented Oct 18, 2019

Thanks @mmcaya for taking the time to do such a good write-up <3

In regard to issue 2:

As far as i understand (correct me if i'm wrong), Kiam is designed to "just" intercept the metadata API. If a pod has already assumed a role, Kiam can do nothing if the pod tries to "escalate" privileges (i.e. assume other roles).
Since there is a 2-way trust relationship between roles needed i don't see a big security issue here. The issue lies in the design/implementation of Kiam.

I personally 100% support documenting this issue and making the externalsecrets.kubernetes-client.io/permitted (or however one will call it) configurable.

I need to take some more time to dig into issue 1 you mentioned.

Just for clarity so no one wastes effort: is someone already working on these issues?

moolen added a commit to moolen/kubernetes-external-secrets that referenced this issue Oct 19, 2019
moolen added a commit to moolen/kubernetes-external-secrets that referenced this issue Oct 19, 2019
moolen added a commit to moolen/kubernetes-external-secrets that referenced this issue Nov 5, 2019
moolen added a commit to moolen/kubernetes-external-secrets that referenced this issue Nov 5, 2019
Flydiverny pushed a commit that referenced this issue Nov 5, 2019
…leArn even if annotations are set (#179)

* fix: missing roleArn should be allowed #174

* feat: make role-scope annotation configurable #174
@mmcaya
Copy link
Author

mmcaya commented Nov 5, 2019

👍 Sorry for the delayed response, thanks for the fixes!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants