Skip to content
New issue

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

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

Already on GitHub? # to your account

Extend variable interpolation syntax #3374

Closed
klizhentas opened this issue Feb 21, 2020 · 7 comments · Fixed by #7152
Closed

Extend variable interpolation syntax #3374

klizhentas opened this issue Feb 21, 2020 · 7 comments · Fixed by #7152
Assignees
Labels
rbac Issues related to Role Based Access Control

Comments

@klizhentas
Copy link
Contributor

klizhentas commented Feb 21, 2020

Description

Current role variables only support the following sytnax:

kuberentes_groups: ['{{variable_name}}']

with the proposal implemented, the following will become possible:

kuberentes_groups: ['IAM#{{variable_name}}-suffix']

In addition function calls will be possible with addition of regexp_replace function:

logins: ['{{regexp.replace(user.spec.traits[email], "^(.)@.*, "\1")}}']

Which is consistent with our current variable where syntax:

https://gravitational.com/gravity/docs/hub/#cluster-rbac-using-labels

where: contains(user.spec.traits["roles"], resource.metadata.labels["team"])

Functions

Two functions will be added:

Generic regexp replace function for common cases:

regexp.replace(what, expression, replacement)

Specific function to handle a very common edge case for capturing local part of the email:

email.local(user.spec.traits["email"])

Properties access

Our simplified version supported external and internal shortcuts. The extended version supports
access to arbitrary metadata of the user context:

# access to user traits dictionary
user.spec.traits
# access to user email trait
user.spec.traits["email"]
# access to cluster metadata labels
resource.metadata.labels
@klizhentas
Copy link
Contributor Author

@benarent @russjones @webvictim @fspmarshall please review

@benarent
Copy link
Contributor

This look good for adding extra data to variables.

My concern with regexp_replace is less to do with the syntax, but the unfriendliness of regex in general. In the example it looks like it has an unmatched closing parenthesis. We can help users by providing common examples in the docs, so the UX will be a little smoother.

@fspmarshall
Copy link
Contributor

I like how this is shaping up. As interpolation becomes more feature-rich it may be worth having a dedicated subsection of the docs just for this.

@webvictim
Copy link
Contributor

Yeah, 100% to an exclusive docs section. This is the sort of thing that's incredibly powerful, but also very hard for anyone who isn't involved with this stuff day-to-day to understand. It would also be very nice to output the evaluated role at DEBUG or even TRACE level logging - just to save manually having to evaluate options, count punctuation and stuff like that.

We should also define exactly what values can be used, so:

  • where does external.traits come from and what other values might be acceptable?
  • how does the customer show a list of usable traits for their own IDP?
  • is there a difference between internal and external traits, and if so, what?

Our docs are currently pretty nebulous on this for things like RBAC - we often get questions on "what's the full list of RBAC verbs supported and what does each one do?"

@klizhentas
Copy link
Contributor Author

@webvictim @fspmarshall @benarent @russjones good follow ups. I have added some clarifications. Note, most parts are already implemented and are part of Gravity featureset and Teleport feature set.

@klizhentas klizhentas self-assigned this Feb 21, 2020
klizhentas added a commit that referenced this issue Mar 4, 2020
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* If `kuberentes_users` part of the resulting role set will have one entry,
forwarding proxy will add this user to impersonate headers of the request, because
there is no ambiguity.

* If `kuberenetes_users` part of the resulting role set will have multiple entries,
forwarding proxy will not add any impersonating user headers by default, users
will have to set impersonate user headers.

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
klizhentas added a commit that referenced this issue Mar 5, 2020
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* By default, if no kubernetes_users is set, which is a majority of cases,
  user will impersonate themselves, which is the backwards-compatible behavior.

* As long as at least one `kubernetes_users` is set, the forwarder will start
  limiting the list of users allowed by the client to impersonate.

* If the users' role set does not include actual user name, it will be rejected,
  otherwise there will be no way to exclude the user from the list).

* If the `kuberentes_users` role set includes only one user
  (quite frequently that's the real intent), teleport will default to it,
  otherwise it will refuse to select.

  This will enable the use case when `kubernetes_users` has just one field to
  link the user identity with the IAM role, for example `IAM#{{external.email}}`

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
klizhentas added a commit that referenced this issue Mar 6, 2020
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* By default, if no kubernetes_users is set, which is a majority of cases,
  user will impersonate themselves, which is the backwards-compatible behavior.

* As long as at least one `kubernetes_users` is set, the forwarder will start
  limiting the list of users allowed by the client to impersonate.

* If the users' role set does not include actual user name, it will be rejected,
  otherwise there will be no way to exclude the user from the list).

* If the `kuberentes_users` role set includes only one user
  (quite frequently that's the real intent), teleport will default to it,
  otherwise it will refuse to select.

  This will enable the use case when `kubernetes_users` has just one field to
  link the user identity with the IAM role, for example `IAM#{{external.email}}`

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
klizhentas added a commit that referenced this issue Mar 7, 2020
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* By default, if no kubernetes_users is set, which is a majority of cases,
  user will impersonate themselves, which is the backwards-compatible behavior.

* As long as at least one `kubernetes_users` is set, the forwarder will start
  limiting the list of users allowed by the client to impersonate.

* If the users' role set does not include actual user name, it will be rejected,
  otherwise there will be no way to exclude the user from the list).

* If the `kuberentes_users` role set includes only one user
  (quite frequently that's the real intent), teleport will default to it,
  otherwise it will refuse to select.

  This will enable the use case when `kubernetes_users` has just one field to
  link the user identity with the IAM role, for example `IAM#{{external.email}}`

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
klizhentas added a commit that referenced this issue Mar 7, 2020
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* By default, if no kubernetes_users is set, which is a majority of cases,
  user will impersonate themselves, which is the backwards-compatible behavior.

* As long as at least one `kubernetes_users` is set, the forwarder will start
  limiting the list of users allowed by the client to impersonate.

* If the users' role set does not include actual user name, it will be rejected,
  otherwise there will be no way to exclude the user from the list).

* If the `kuberentes_users` role set includes only one user
  (quite frequently that's the real intent), teleport will default to it,
  otherwise it will refuse to select.

  This will enable the use case when `kubernetes_users` has just one field to
  link the user identity with the IAM role, for example `IAM#{{external.email}}`

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
klizhentas added a commit that referenced this issue Mar 8, 2020
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* By default, if no kubernetes_users is set, which is a majority of cases,
  user will impersonate themselves, which is the backwards-compatible behavior.

* As long as at least one `kubernetes_users` is set, the forwarder will start
  limiting the list of users allowed by the client to impersonate.

* If the users' role set does not include actual user name, it will be rejected,
  otherwise there will be no way to exclude the user from the list).

* If the `kuberentes_users` role set includes only one user
  (quite frequently that's the real intent), teleport will default to it,
  otherwise it will refuse to select.

  This will enable the use case when `kubernetes_users` has just one field to
  link the user identity with the IAM role, for example `IAM#{{external.email}}`

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
@aelkugia
Copy link
Contributor

This was addressed in 4.2.6. Closing ticket

@webvictim
Copy link
Contributor

webvictim commented Apr 20, 2020

This actually wasn't addressed fully in 4.2.6. It's my understanding that support was added for email.local but not for regexp.replace. @klizhentas Please confirm?

I think if we want to close this then we should change the scope of this issue and open a new one for the missing feature.

@webvictim webvictim reopened this Apr 20, 2020
@awly awly assigned awly and unassigned klizhentas Sep 17, 2020
@awly awly modified the milestone: 4.4 "Rome" Sep 17, 2020
@awly awly added this to the Runway Milestone milestone Nov 23, 2020
@awly awly removed their assignment Nov 23, 2020
@awly awly added the rbac Issues related to Role Based Access Control label Nov 23, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
rbac Issues related to Role Based Access Control
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants