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

Adds support for kubernetes_users, extend interpolation (#3404) #3418

Merged
merged 1 commit into from
Mar 8, 2020

Conversation

klizhentas
Copy link
Contributor

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:

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
Copy link
Contributor Author

@fspmarshall @russjones this is a forward port

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubernetes

@@ -566,6 +566,9 @@ message RoleConditions {
repeated string KubeGroups = 5 [(gogoproto.jsontag) = "kubernetes_groups,omitempty"];

AccessRequestConditions Request = 6 [(gogoproto.jsontag) = "request,omitempty"];

// KubeUsers is an optional kuberentes users to impersonate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubernetes

@klizhentas
Copy link
Contributor Author

retest this please

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 klizhentas merged commit 73ecb48 into master Mar 8, 2020
@klizhentas klizhentas deleted the sasha/ku-fwd branch March 8, 2020 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add kube_users impersonation
3 participants