Files
teleport/api
Tim Buckleyandrosstimothy 6d2ab51d0d Allow impersonation of roles without users (#9561)
* Allow impersonation of roles without users

This adds the ability to impersonate one or more roles without
impersonating a particular user.

In Teleport today, when creating an impersonator role, both users and
roles must be specified as impersonation is fundamentally tied to an
existing Teleport user:
```yaml
allow:
  impersonate:
    users: ['jenkins']
    roles: ['jenkins']
```

This is inconvenient for two reasons:
 1. A user must exist for each set of roles you'd like to
    impersonate, creating a UX burden.
 2. It makes it difficult to use impersonation to reduce one's
    permissions as you always inherit all of the roles granted to the
    target user.

For the [certificate bot][bot] we'd instead like to use impersonation
to generate end-user (impersonated) certificates with a reduced set
of permissions. For example, given the following role:
```yaml
allow:
  impersonate:
    roles: ['jenkins', 'deploy']
```

We can then use `GenerateUserCerts` to issue certifices for a subset
of the allowed roles, e.g. one set of certificates with only the
`jenkins` role attached, and another with only `deploy`.

To that end, this patch:
 1. Removes the requirement that roles define both `users` and
    `roles` in impersonate conditions
 2. Introduces a new `RoleRequests` field in `UserCertsRequest`
 3. Modifies `generateUserCerts` to gather `roles` from
    `RoleRequests` if allowed by an `allow` (with no `users`)

[bot]: https://github.com/gravitational/teleport/pull/7986

* Add `determineDesiredRolesAndTraits`; audit log on role impersonation

This splits initial role and trait determination into a new function,
`determineDesiredRolesAndTraits`, to improve control flow and clarity
given the new branches introduced for role impersonation.

Additionally, this moves the call to `CheckRoleImpersonation` down
to match regular user impersonation's flow, and emits an audit log
event on failure.

* Formatting fix

* Unit testing for role requests

This adds a new set of unit tests for role requests.

Also discovered the `impersonator` field wasn't being set for
role impersonation, so it's now set to the user's own username.
In other words, role impersonation will appear (in the audit log and
elsewhere) as self-impersonation.

* Clean up testing users between runs

* Deny most reimpersonation cases and add tests

This attempts to deny most cases of reimpersonation, where an
impersonated certificate might be used to generate certificates for
other roles the user is allowed to impersonate.

One test case is currently failing pending a solution.

* Add new DisallowReissue certificate extension

This adds a new DisallowReissue certificate extension that, if set,
prevents that identity from interacting with `GenerateUserCerts`.

This flag is always set when RoleRequests are used to prevent
unintended privilege escalation (while avoiding breaking changes to
Teleport's existing certificate generation behavior).

* Fix test lints

* Fix typo

* Fix test doc typo, add testcase for user impersonation misuse

* Apply suggestions from code review

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Accept context in CreateRole per review feedback

* Fix misleading comment

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2022-01-14 15:15:13 -07:00
..
2021-10-05 15:28:42 -07:00