Commit Graph
67 Commits
Author SHA1 Message Date
Michael Wilson 49c64aabcb Move the authorizer into its own package. (#22776)
* Move the authorizer into its own package.

The Authorizer and associated functions and constants have been moved into
their own package `authz`. This will allow us to more easily create separate
services for gRPC functionality so that we're not pushing as much into the
`lib/auth` package.

Though this PR is large, the only actual code change here is making
`ContextForLocalUser` exported and changing the `permissions_test.go` so that
it doesn't rely on the `lib/auth` package.

* Use context functions.

* Test and linting fixes.

* Add in a temporary alias file to ensure e still compiles.

* Use functions instead of var aliases for performance reasons.

* Adding in godocs, cleaning up tests.

* Fix tests.

* Add a few more aliases.
2023-03-09 02:21:10 +00:00
Nic Klaassen ff9e60fdf0 feat: evaluate login rules for GitHub users (#20627)
This commit enables login rule evaluation during login for users logging
in with a GitHub connector.

The GitHub connector is a bit different from the SAML and OIDC
connectors in that the user roles are not mapped from the traits
(claims/assertions) but from the user's GitHub organizations and teams
directly.
This makes login rules slightly less useful for GitHub logins because
they cannot affect the user's roles, only their traits.
However, GitHub login is mostly an OSS feature and login rules will be
enterprise-only.
Any enterprise users making use of GitHub login will still be able to
use some of the features (trait mapping).
2023-01-25 18:38:33 +00:00
Krzysztof Skrzętnicki f8fa2b9be2 Bump gravitational/trace package version (#19390) 2022-12-21 22:02:25 +00:00
Matheus e9f2ac7ade Export GithubConverter type (#18751) 2022-11-28 21:07:57 +00:00
Andrew LeFevre ba9fd70a92 Add ability to have multiple Github auth connector implementations (#17293)
* added Github auth creator

This will allow for multiple implementations of Github
auth connectors.

* work to allow multiple github auth connector implementations

* auth works, need to fix upserts

* fix upserting, add comments

* fix imports from merge

* removed now unused error

* point e submodule to master branch

* fix unit test

* use correct capitalization of 'GitHub'

* move Github auth connector conversions out of api module

* fix linter warning
2022-11-16 15:35:21 +00:00
Cam Hutchison 6bac096d28 auth: Split SAML connector code to own type (#18255)
Create a new type - `SAMLAuthService` - and move the implementation of
the SAML connector from the auth Service to this new type. This
decoupling will make it easier to move out of tree in a later commit.

This also lays the basic groundwork for running without the SAML
connector at all, returning a NotImplemented error for all the SAML
logic if the SAMLAuthService is not plugged in.

A number of names in the `auth` package have been exported to facilitate
moving the SAML connector out of this repository. The types exported do
not need to be exported for this commit, but for subsequent commits that
move the `SAMLAuthService` out of the `auth` package.

Also apply a small fix to to emit `apievents.SAMLConnector*` events of
`apievents.OIDCConnector*` events in the SAML connector.
2022-11-16 14:24:43 +11:00
Brian Joerger ce20b20753 PIV login enforcement (#15874)
Add private key policy enforcement.

  - Add private key policy cert extensions and enforcement.

  - Add private key policy settings and attestation logic.

  - Wire attestation request through login endpoints.

  - Store attestation data for reissue requests.

  - Add private key policy discovery and logic.

  - Relogin on hardware key policy errors.

  - Include integration with Teleport Connect.
2022-09-30 23:27:48 +00:00
rosstimothy 7e036cdf42 Generic retrieval of FnCache values (#16485)
Coverts getting values in the `FnCache` from `FnCache.Get` to
`utils.FnCacheGet[T any]`. This allows us to have compile time
guarantees for the type being loaded, which allows us to remove
some of the manual type checking required of callers today.
2022-09-20 12:36:03 +00:00
Alan Parra a75fcc21d8 Update golangci-lint to 1.49.0 (#16507)
Update metalinter, fix a few lint warnings and replace deprecated linters.

`deadcode`, `structcheck` and `varcheck` are abandoned and now replaced by [`unused`][1].

Since 1.19, `go fmt` reformats godocs according to https://go.dev/doc/comment. I've done a bulk-reformatting of the codebase to keep the linter happy. Backporting is mostly harmless (the exception being `lib/services/role_test.go`, that for some reason breaks the _old_ linter using the new format).

[1]: https://golangci-lint.run/usage/linters/

* Bump golangci-lint version
* Replace abandoned linters
* Fix bodyclose on lib/auth/github.com
* Fix bodyclose on lib/kube/proxy/streamproto/proto_test.go
* Fix bodyclose on lib/srv/alpnproxy/proxy_test.go
* Fix bodyclose on lib/web/conn_upgrade_test.go
* Silence staticcheck on lib/kube/proxy/forwarder_test.go
* Silence staticcheck on lib/utils/certs_test.go
* Address BuildNameToCertificate deprecation warnings
* Run `go fmt ./...`
* Run `go fmt ./...` on api/
* Ignore formatting in role_test.go
* Remove redundant initializers in lib/srv/uacc/
* Update e/
2022-09-19 22:38:59 +00:00
Andrew LeFevre 4d25801fab Deny Github organizations using external SSO on Teleport OSS (#14529)
* added check that blocks enterprise Github organizations using external SSO from using Github auth connectors on Teleport OSS

* added details to docs and changelog

* move check from init to on login

* cache org sso status; address small pieces of feedback

* use utils.FnCache instead of 3rd party cache

* addressed feedback

* addressed feedback

* revised docs

* addressed more feedback

* remove notes in changelog

* removed unused interface
2022-09-16 16:14:15 -04:00
Edoardo Spadolini 58b01b964b Embed auth.Cache in auth.Server (#14698)
* Embed auth.Cache in auth.Server

* Hit the backend during Auth initialization

* Bypass the cache when rotating CAs

* Services.UpsertTrustedCluster is different

* Bypass the cache in waitForTunnelConnections

* Fix infinite recursion

* More cache bypassing during init and rotations

* Rename Services to Uncached in auth.Server

* Further cleanups

* Don't start the auth cache immediately

* Go back to Services rather than Uncached

* Comments and a missing method
2022-07-27 21:05:53 +00:00
rosstimothy fea159fd1b Add context.Context to CreateWebSession and DeleteWebSession (#14663)
* Add context to CreateWebSession and DeleteWebSession

Updates the WebService interface to include a context.Context in
CreateWebSession. Other function signatures were changed as needed
to propagte the context.Context into all the call site of
CreateWebSession.
2022-07-19 22:05:23 +00:00
Andrew Burke b7efbcebb0 Add error message for failed SSO authorization (#9622)
This change, along with gravitational/webapps#530, adds a new error message for when a user successfully authenticates with SSO but fails to match any roles.
2022-07-15 23:55:25 +00:00
Marco André Dinis 24cb3e3124 WebAPI: update user traits (#14076)
* WebAPI: update user traits

Web API only supports updating the roles property for a given User.

This PR adds the possibility of updating User's traits
- Logins
- DB Users
- DB Names
- Kube Users
- Kube Groups
- Windows Logins
- AWS Role ARNs

It only updates if the requests contains a non-nil value for the trait's
list.
It deduplicates the trait's list before applying it.
2022-07-06 15:55:45 +01:00
Brian Joerger 2aae5b5899 Fix SSO AuthRequest backwards compatibility. (#13589) 2022-06-17 01:21:29 +00:00
Krzysztof Skrzętnicki 7f8a2e6e7b Adjust tctl sso commands to new teams_to_roles field. (#13463) 2022-06-14 10:10:27 +00:00
Joel dc13bb8750 Remove uneeded mapping length check (#13460) 2022-06-14 08:40:55 +00:00
Joel efd10847bf Modernize role mapping in github connectors (#10456) 2022-06-08 15:34:15 +00:00
Brian Joerger 9cc58cca44 gRPC conversions - SSO Auth Connectors (#13073) 2022-06-08 01:45:06 +00:00
Krzysztof Skrzętnicki 9377f7c681 New commands: tctl sso test, tctl sso configure for GitHub (#12783)
* Implement `tctl sso` commands for GitHub auth.

* Mark RFDs as implemented.
2022-05-26 23:26:35 +00:00
rosstimothy 550d23d15d Fix goroutine and memory leak in watchCertAuthorities (#10871)
* Fix goroutine and memory leak in watchCertAuthorities

The CA Watcher was blocking both on writing to a channel when the watcher
was closed and on HTTP calls that had no request timeout or context passed
to cause cancellation.

All resourceWatcher implementations that had a bug which may cause them to block
on writing to a channel forever were fixed by selecting on the write and ctx.Done.

Adding context.Context to all Get/Put/Post/Delete methods on the auth HTTPClient to
force callers to propagate context. Prior all calls used context.TODO which
prevents requests from being properly cancelled.

Add context propagation to RotateCertAuthority, RotateExternalCertAuthority,
GetCertAuthority, GetCertAuthorities. This is needed to get the correct ctx
from the CertAtuhorityWatcher all the way down to the HTTPClient that makes
the call.

Closes #10648
2022-03-10 11:05:39 -05:00
Edoardo Spadolini 2598401589 Add access requests to audit events (#9758)
* Refactor most uses of `UserMetadata` into a handful of functions

* Add access requests to `UserMetadata`

* Explanation for the reserved field in SessionStart
2022-01-25 16:56:18 +00:00
Alex McGrath 1ca73cd1e7 Add github teams to available traits 2022-01-24 10:59:59 +00:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Brian Joerger 24063e65f0 Remove SetTTL methods in favor of SetExpiry. (#7234) 2021-06-18 13:35:02 -05:00
Brian Joerger 4d36870ff0 Remove remaining API aliases (#7137) 2021-06-08 12:08:55 -07:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Lisa Kim 7931977d72 [web] Add ability to switchback to default roles/expiry (#6373)
- Preserve login time with WebSession when user first creates a web session to derive
"default" expiry when user wants to switch back
- Change the signature of ExtendWebSession to accept a 
NewWebSessionRequest struct that contains session information
- Create renewSessionRequest object to read from web request for endpoint renewSession
- Endpoint now also returns SessionExpires time that is used as countdown in UI
2021-04-19 18:53:09 -07:00
Lisa Kim 940c83c161 Make SSO login failure event emit more specific errors (#6108)
Purpose is to allow users with admin privilege that are able to view audit logs, 
to be able to debug SSO login failures from the UI as much as possible

* Return generic error message for sso console login failures to hide
  sensitive data from reaching client. Previously errors were returning as
  empty messages b/c of a trace bug.
* Remove emit event for createOIDCClient to allow outer caller to
  emit event and prevent double emits on error.
* Temporarily direct users to check teleports log on errors that come back 
  empty to tsh client.
2021-03-25 10:36:47 -07:00
Brian Joerger 4398797f14 Pass context through new gRPC converted endpoints. (#6118) 2021-03-23 18:26:52 -07:00
Lisa Kim 84a4f00114 Define cloud billing event types and codes (#6037)
* Exported auth.clientImpersonator and auth.clientUsername for use in e
2021-03-23 17:23:01 -07:00
Alexander Klizhentas f17625c1a8 Adds controls for impersonation requests. (#6009) (#6073)
Fixes #5352

```yaml
allow:
  impersonate:
    users: ['alice', 'bob']
    roles: ['*']
    where: 'contains(user.spec.traits["groups"], impersonate_role.traits)'
```

Adds "impersonator" to all X.509 and SSH client certs
issued using impersonation and does best effort to track
requests by impersonators in audit events.

Limits certs TTL to the impersonator's max session TTL.

Prevents impersonating users to recursively impersonate
other users.

Allows impersonating users to renew their own certificate,
for example to set route to cluster.

Adds missing token permission for editor role.
2021-03-19 16:04:43 -07:00
Andrej Tokarčík 89f0432ad5 Introduce utils.ReadAtMost to prevent resource exhaustion 2021-03-01 22:14:10 +01:00
Sasha Klizhentas 013f9680c9 OSS RBAC
Implements RFD #7

https://github.com/gravitational/teleport/blob/master/rfd/0007-rbac-oss.md

OSS users can use roles. Some FedRamp related role options
are limited to enterprise.

All users are migrated to a new role "ossuser".

This role is a limited access role downgrading all users
from OSS role "admin".

All trusted clusters are mapped to "ossuser" as well.

Github connector maps teams to generated roles.

For transition period, format `tctl users add alice` works
alongside with `tctl users add alice --roles=admin`, but prints
a warning.
2021-02-17 17:04:03 -08:00
a-palchikov 86908cc2f3 Web UI disconnects (#5276)
* Use fake clock consistently in units tests.
* Split web session management into two interfaces and implement them separately for clear separation
* Split session management into New/Validate to make it aparent where the sessions are created and where existing sessions are managed. Remove ttlmap in favor of a simple map and handle expirations
explicitly.
Add web session management to gRPC server for the cache.

* Reintroduce web sessions APIs under a getter interface.
* Add SubKind to WatchKind for gRPC and add conversions from/to protobuf. Fix web sessions unit tests.
* lib/web: create/insert session context in ValidateSession if the session has not yet been added to session cache.
lib/cache: add event filter for web session in auth cache.
lib/auth: propagate web session subkind in gRPC event.

* Add implicit migrations for legacy web session key path for queries.
* Integrate web token in lib/web
* Add a bearer token when upserting a web session
* Fix tests. Use fake clock wherever possible.

* Converge session cache handling in lib/web

* Clean up and add doc comments where necessary

* Use correct form of sessions/tokens controller for ServerWithRoles. Use fake time in web tests

* Converge the web sessions/tokens handling in lib/auth to match the old behavior w.r.t access checking (e.g. implicit handling of the local user identity).

* Use cached reads and waiters only when necessary. Query sessions/tokens using best-effort - first looking in the cache and falling back to a proxy client

* Properly propagate events about deletes for values with subkind.

* Update to retrofit changes after recent teleport API refactorings

* Update comment on removing legacy code to move the deadline to 7.x

* Do not close the resources on the session when it expires - this beats the purpose of this PR.
Also avoid a race between closing the cached clients and an existing reference to the session by letting the session linger for longer before removing it.

* Move web session/token request structs to the api client proto package

* Only set HTTP fs on the web handler if the UI is enabled

* Properly tear down web session test by releasing resources at the end. Fix the web UI assets configuration by removing DisableUI and instead use the presence of assets (HTTP file system) as an indicator that the web UI has been enabled.

* Decrease the expired session cache clean up threshold to 2m. Only log the expiration error message for errors other than not found

* Add test for terminal disconnect when using two proxies in HA mode
2021-02-04 16:50:18 +01:00
Brian Joerger ce87251ea0 api dependency reduction - marshalers (#5384)
Refactor Marshal logic on types, and move it into /lib/services to reduce dependencies in /api.
2021-02-01 10:26:50 -08:00
Brian Joerger 626ad243eb api dependency reduction - utils constants (#5363)
Moved constants and utils used in /api into /api/constants and /api/utils respectively.
2021-01-29 09:37:01 -08:00
Lisa Kim f7360b72ea Fix incorrect github login success event code (#4509) 2020-10-13 09:14:46 -07:00
Andrew Lytvynov 92ed2db38a Fixing golint warnings, batch 1
Mostly cosmetic changes:
- making receiver names consistent
- renaming `foo.FooBar` to `foo.Bar` (using package name as prefix)
- removing redundant `else` branches
- changing `a += 1` to `a++`
2020-10-13 00:22:49 +00:00
Andrew Lytvynov e095e30342 Add kubernetes cluster name to TLS certs
K8s cluster name is specified during login (for now) and gets plumbed to
a new extensions on the TLS cert. The name is validated against all
known k8s clusters reported via proxy heartbeats. If no name is
provided, the extension remains empty.

The name in the cert will get used by proxies for routing, once we fully
support multiple k8s clusters per teleport cluster.

This was tested with direct and github login flows.
2020-10-07 16:26:54 +00:00
Sasha Klizhentas d160507430 Session streaming
This commit introduces GRPC API for streaming sessions.

It adds structured events and sync streaming
that avoids storing events on disk.

You can find design in rfd/0002-streaming.md RFD.
2020-09-28 23:08:56 -07:00
Andrew Lytvynov 483153b4ec Plumb github username to TraitsFromLogins
This lets TraitsFromLogins to use that username for extra traits. No
changes in community edition, this will be used in enterprise.
2020-07-01 18:17:46 +00:00
Andrew Lytvynov 1b7401f670 Plumb RouteToCluster through SSO login flows
This lets the user log into a leaf cluster directly via tsh and
provision the correct k8s credentials for it.
2020-07-01 18:15:48 +00:00
Andrew Lytvynov 960f13efda Update e-ref 2020-06-18 19:01:35 +00:00
Andrew Lytvynov 5bd66a396e Plumb caller username for CRUD events via contexts
Our auth middleware already attaches a TLS identity as context value.
Plumb contexts through and extract the username when recording events.
If the received context doesn't have an identity attached, use "system"
as username.

Lots of noise here due to missing context.Context plumbing :(
We should eventually plumb contexts to all those RPC interfaces.

Updates #3816
2020-06-18 19:01:35 +00:00
Andrew Lytvynov a9eae02374 errcheck: add missing error handling in lib/auth 2020-06-03 21:57:04 +00:00
Lisa Kim da7500d671 Emit audit events when upserting/deleting auth connectors (#3736) 2020-05-19 17:08:23 -07:00
Lisa Kim 118ad19101 Emit correct event user who updates user records (#3635)
* Add UpdateUser rpc to proto
* Differentiate between create and update in github,oidc,saml
* Edit updated_by event field to be more generic (used with contexts to capture user modifying records)
* Update security issue by removing secrets from user when update/upsert/create (forrest)
* Update createUser in resource_command and require force for updates
2020-05-05 16:49:32 -07:00
Alexander Klizhentas 73ecb48232 Adds support for kubernetes_users, extend interpolation (#3404) (#3418)
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.
2020-03-07 16:32:37 -08:00