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

Granular matching for role labels, kubernetes_labels, etc #10204

Closed
Tracked by #22526
programmerq opened this issue Feb 7, 2022 · 12 comments
Closed
Tracked by #22526

Granular matching for role labels, kubernetes_labels, etc #10204

programmerq opened this issue Feb 7, 2022 · 12 comments
Assignees
Labels
c-acf Customer Github Issues c-dc Internal Customer Reference c-fl Internal Customer Reference c-fx Internal Customer Reference c-gd Internal Customer Reference c-pu Internal Customer Reference c-sy Internal Customer Reference c-te Internal Customer Reference c-to Internal Customer Reference c-ud Internal Customer Reference c-uh Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements rbac Issues related to Role Based Access Control

Comments

@programmerq
Copy link
Contributor

programmerq commented Feb 7, 2022

What

Currently, if a role specifies multiple key value pairs in the labels or kubernetes_labels section, it will allow access only to clusters that match all the criteria. As far as I can tell, there is not currently a way to specify key/value pairs where any of the criteria match.

If you want to have it match any one of the label key/value pairs, then you must split it out into a role of its own.

It would be nice to have the ability to specify the behavior as AND (current) or optionally OR. AND is certainly the sane default behavior, but it can get unwieldy when you need to have OR type functionality and end up creating additional roles for each set of criteria.

How

Perhaps, a list of maps would be treated as an OR list of sets. (this particular syntax may be too confusing)

So

kubernetes_labels:
    foo: bar

would be equivalent to:

kubernetes_labels:
   - foo: bar

and this being in one role would be the same as having two separate roles:

kubernetes_labels:
    - foo: bar
      bing: baz
    - key: value
      env: prod

Why

Sometimes OR behavior is necessary when there are many labeling methods in use. Attaching all the necessary access for a given role is ideal without needing to split the role up into multiple roles.

Workaround

Split up a role. (can get unwieldy for a large number of matches)
gz#3987

gz#4161

@programmerq programmerq added the feature-request Used for new features in Teleport, improvements to current should be #enhancements label Feb 7, 2022
@programmerq programmerq changed the title Slack Conversation #teleport-flexport @Anthony Scheller Granular matching for kubernetes_labels Feb 7, 2022
@programmerq programmerq added the c-fl Internal Customer Reference label Feb 7, 2022
@stevenGravy
Copy link
Contributor

This would be a general ask for roles, to have multiple match ability for labels for all protocol types

@stevenGravy stevenGravy added the rbac Issues related to Role Based Access Control label Feb 8, 2022
@programmerq
Copy link
Contributor Author

A more verbose explanation follows. Say I have the following three kubernetes clusters with the corresponding labels:

  • kube1
    • team=qa
    • env=stage
  • kube2
    • team=dev
    • env=stage
  • kube3
    • team=qa
    • env=prod

I would like to write a single role that gives access to all three clusters.

If I write a role that has the following label section, the user would only see kube1 and kube3 but not kube2:

kubernetes_labels:
  team: qa

If I write one that has the following, then the user would see only kube1 and kube2, but not kube3:

kubernetes_labels:
  env: stage

If I write the following, then I see only kube2 but not kube1 nor kube3:

kubernetes_labels:
  team: qa
  env: stage

This seems to be due to the fact that teleport wants all the labels listed in kubernetes_labels to match. I don't see a way where I can specify that any of them should match.

My proposal to add the ability for kubernetes_labels to be a list of maps instead of just a map would be a way to get OR capabilities without making many changes to the syntax. It would need to be documented very well, and other implementations to get the same functionality would be appreciated.

For use cases where there may be five or six conditions that need to be evaluated as an OR type condition, this can artificially inflate the necessary number of roles that need to exist in the system and it becomes unwieldy.

@knisbet
Copy link
Contributor

knisbet commented Feb 9, 2022

Sorry, helicoptering in a bit, but I do want to note that the proposed configuration could lead to lots of footguns.

kubernetes_labels:
    - foo: bar
      env: prod

vs

kubernetes_labels:
    - foo: bar
    - env: prod

That very subtle difference has a completely different meaning.

@programmerq
Copy link
Contributor Author

@knisbet yes, I agree that my specific proposed syntax could be problematic. The functionality is the heart of the request and the specific syntax can be altered. I'm happy to edit the original description to make the "how would you do it" less specific.

@klizhentas
Copy link
Contributor

Our idea is to support or matching for labels, for example:

kubernetes_labels:
   or:
       - foo: bar
       - env: prod

@programmerq programmerq added the c-te Internal Customer Reference label Feb 17, 2022
@programmerq
Copy link
Contributor Author

Editing the description to make it be not exclusive to kubernetes labels since we've had interest for other role lists per @stevenGravy's comment.

@programmerq programmerq changed the title Granular matching for kubernetes_labels Granular matching for role labels, kubernetes_labels, etc Feb 17, 2022
@pschisa pschisa added the c-to Internal Customer Reference label Feb 18, 2022
@deusxanima deusxanima added the c-ud Internal Customer Reference label Mar 1, 2022
@zmb3
Copy link
Collaborator

zmb3 commented Jun 7, 2022

See also #4468

@zmb3
Copy link
Collaborator

zmb3 commented Jun 8, 2022

See also #9441 - it looks like roletester interprets this incorrectly.

@codersofthedark
Copy link

+1. we need this badly. We have to maintain too many subroles because of this.

@JayArjunan JayArjunan added c-sy Internal Customer Reference c-fl Internal Customer Reference and removed c-fl Internal Customer Reference labels Aug 29, 2022
@russjones
Copy link
Contributor

We won't be able to address this in Q3 but will discuss potentially addressing this in Q4.

@klizhentas
Copy link
Contributor

Here @nklaassen we can use expression syntax (and/or) isolated to labels that will cover a lot for us

@nklaassen nklaassen self-assigned this Feb 14, 2023
@pnrao1983 pnrao1983 added the c-uh Internal Customer Reference label Mar 10, 2023
@pschisa pschisa added the c-fx Internal Customer Reference label Mar 10, 2023
@oshati oshati added the c-dc Internal Customer Reference label Apr 13, 2023
@pnrao1983 pnrao1983 added c-gd Internal Customer Reference c-acf Customer Github Issues labels May 18, 2023
@nklaassen
Copy link
Contributor

This is addressed by label expressions released in 13.1.1

For example you can now write:

kubernetes_labels_expression: |
  labels["foo"] == "bar" || labels["env"] == "prod"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-acf Customer Github Issues c-dc Internal Customer Reference c-fl Internal Customer Reference c-fx Internal Customer Reference c-gd Internal Customer Reference c-pu Internal Customer Reference c-sy Internal Customer Reference c-te Internal Customer Reference c-to Internal Customer Reference c-ud Internal Customer Reference c-uh Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements rbac Issues related to Role Based Access Control
Projects
None yet
Development

No branches or pull requests