Commit Graph
62 Commits
Author SHA1 Message Date
Brian Joerger 424606ef35 Headless Login: proxy server changes (#22734)
* * Add proper context handling to auth.AuthenticateUser.

 * Move PublicKey field to AuthenticateUserRequest where it can be used
   for actual authentication.

 * Use a simple switch statement in /webapi/ssh/certs logic to switch
   between password, otp, and eventually headless login.

* Add Headless flow to /webapi/ssh/certs login enpdoint.

* Add 3 minute callback timeout.
2023-03-10 19:25:08 +00:00
Anton MiniailoandNoah Stride 13fad744d6 Adjust clientIP/pinnedIP fields according to IP pinning RFD (#21866)
* Adjust clientIP/pinnedIP fields according to IP pinning RFD

* Improve wording.

Co-authored-by: Noah Stride <noah.stride@goteleport.com>

---------

Co-authored-by: Noah Stride <noah.stride@goteleport.com>
2023-02-15 19:36:19 +00:00
Noah Stride 476a4a7e82 context.TODO() tidying (#21288)
* Use `ctx` rather than `context.TODO()` where available

* Further propagation of context

* Use `context.Background()` instead of `context.TODO()` where appropriate in tests

* Further remove `context.TODO` from tests

* Appease linter on parameter order
2023-02-07 09:01:35 +00:00
Brian Joerger 488af75797 Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00
Sam Freibergandrosstimothy 2c10c558e9 Fix known cases where audit log events can be bypassed by exceeding limit (#19486)
* Limit Device Name and User Agent lengths

* Spelling correction

* Increase ballast size while trimming message size

* Cleanup error message

* Remove additional check

* Adjust tests

* Add tests for large AuditEvent

* Rename func to add clarity

* Move limit to const and lowercase field name

* Add test for invalid device name length

* Add a test for trimming the user agent

* Replace custom emitter with MockEmitter

* Add additional background to const

* Add additional comments

* Fix import ordering

* Refactor trimN to better handle heavily quoted queries and add tests

* Convert to error assetion func

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

* Finish test refactor

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2022-12-29 21:41:05 +00:00
Anton Miniailo cd595c5d37 security: Prevent IP pinning bypass 2022-12-28 09:24:02 -08: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
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 adc37b4ba3 Add context.Context to AuthenticateWebUser and AuthenticateSSHUser (#14754)
Updates auth.ClientI to require that both methods take a
context.Context as the first argument. Context propogation required
some additional call sites to ensure the proper context is plumbed
down to the auth.ClientI calls.
2022-07-25 16:05:40 +00:00
Nic Klaassen 489c26df1a Refactor services.AccessInfo (#14765) 2022-07-22 08:37:49 +01:00
Andrew Burke 94b8a198df Add hint for --user flag in tsh login (#14168)
This change adds a hint to tsh login about the use of the --user flag.
2022-07-08 19:36:07 +00:00
Przemko Robakowski 951aff47ed IP-based validation for SSH (#13243)
This change adds IP-based validation for SSH certificates.
There's new option in role definition:

kind: role
metadata:
  name: dev
spec:
  options:
    pin_source_ip: true
When that is set to true client IP must be the same when generating certificates and using them. It uses source_address critical option that should be supported by both teleport and sshd and only applies to certificates we send to user (like in tsh login), we don't pin IP in certificates issued for web UI as they can't leak.
This change also omits machine ID (it uses different code path) - it will be added in separate PR.

Most of the lines changed are from regenerating types.proto, change itself is not that big

Relates #11719
2022-06-08 22:49:37 +00:00
Jakub NyckowskiandMarek Smoliński 9c046930ff Snowflake integration (#12564)
Add Snowflake integration.

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-06-06 17:49:38 +00:00
Nic Klaassen 814664ab66 [Search-based access requests] Enforce resource access restrictions (#12651) 2022-06-03 00:04:44 +00:00
Noah Stride 4f7a705b62 Add additional client information to login audit event (#12537)
* add client ip and user agent to `user.login` audit log

* reuse existing ConnectionMetadata message

* additional audit data for SSH logins made via proxy

* small unit test for clientMetaFromReq

* add franktentest for login checking audit event

* fix audit logging timestamps in web/auth tests
2022-05-18 18:31:47 +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
Alan Parra 5023235909 Add passwordless login/registration to auth and web (#10632)
Wire passwordless registration and authorization into Auth and Proxy APIs, thus
making passwordless logins possible.

API changes are described by RFD 52: Passwordless [1].

#9160

[1] https://github.com/gravitational/teleport/blob/master/rfd/0052-passwordless.md#authentication-api-changes

* Add passwordless settings to Auth protos
* Update generated protos
* Register: Apply DeviceUsage in lib/auth
* Register: Apply DeviceUsage in lib/web
* Login: Generate passwordless challenge
* Login: Allow passwordless authentication
* Wire passwordless in lib/web endpoints
* Make mocku2f passwordless setup a bit nicer
2022-03-04 18:41:35 +00:00
Alan Parra bac0ccdc99 Remove U2F support (#10476)
Follows up on #10466 by removing remaining U2F references, including proto/gRPC
surface and the lib/auth/u2f package itself.

#10375

* Remove U2F from lib/auth/ (1)
* Remove U2F from lib/auth/ (2)
* Remove U2F from lib/auth/ (3)
* Remove U2F from lib/services/
* Remove U2F from tsh mfa add suggestions
* Remove U2F protos
* Update generated protos
* Cleanup a few stragglers
* Remove lib/auth/u2f package
* Fix references to auth.MFAAuthenticateChallenge
* Revert needless lib/auth/password.go change
* Update e/ to ad8fd4a (U2F cleanup)
* Fix stragglers from latest master rebase
* Fix lint and compile failures
2022-02-24 19:54:28 +00:00
Lisa Kim f9788a1531 Return obscured user locked error message (#8596)
- Fixes a bug where proper user lock expire date wasn't used
- Have CreateAuthenticateChallenge return error as is instead 
  of overriding all errors with AccessDenied, which fixes a 
  backwards comp error where older proxies assume 
  AccessDenied type error means user got locked
2021-10-20 13:00:11 -07:00
Alan Parra 6187d00c74 Add Webauthn support to ChangePassword and Ping (#8337)
Add Webauthn support to a few outstanding endpoints and RPCs.

* Refactor and add Webauthn support to ChangePassword
* Add explicit JSON tag to AuthenticateUserRequest.Webauthn
* Add Webauthn support to /webapi/users/password/token
* Add Webauthn to /webapi/ping
* Add default Webauthn device name to ChangeUserAuthentication
* Tidy Ping tests
2021-09-23 13:34:30 -07:00
Alan Parra fd9394be38 Tidy up Webauthn login and registration (#8283)
Address a couple of outstanding TODOs:

* Keep SessionData in memory during registration

A nice to have that allows multiple concurrent registrations, plus it
matches how U2F works today.

* Remove test assertion for RegistrationIdentity
* Refactor authenticateUser to take advantage of validateMFAAuthResponse

Not as big as a gain as I was hoping for (due to password checking on
OTP), but at least we consolidate U2F/Webauthn challenges to a single
place.

* GenerateUserSingleUseCerts checks for Webauthn challenges
2021-09-17 14:59:37 -03:00
Zac Bergquist 839cdcfa97 Convert GenerateServerKeys to GRPC (#8193)
This commit contains 2 changes:

1. Rename GenerateServerKeys to GenerateHostCerts.
   This is a more accurate name and consistent with the existing
   GenerateUserCerts endpoint.
2. Change the request type to include a single role, rather than a
   list of roles. We only ever allowed a single role in the list
   anyway, so this change will prevent future mis-use of the API.

Note: a side effect of this change is we now have two similar endpoints:
- GenerateHostCert: old API that generates SSH cert only
- GenerateHostCerts: a newer API that generates SSH and TLS certs

To avoid making this change too big, we'll aim to deprecate
GenerateHostCert in the future.
2021-09-13 14:37:28 -07:00
Alan Parra d00d6b97f9 Wire Webauthn to login endpoints (#8094)
Allow login using Webauthn instead of U2F.

Installs with second_factor:on will automatically support Webauthn, generating
challenges for any U2F devices and allowing Webauthn to be used throughout the
entire login process.

Web REST API modified as follows:

Added /webapi/mfa/login/begin (1st login step)
Added /webapi/mfa/login/finish (2nd login step, SSH)
Added /webapi/mfa/login/finishsession (2nd login step, web session)
U2F endpoints deprecated, but support full breadth of MFA login options
(/webapi/u2f/signrequest, /webapi/u2f/certs and /webapi/u2f/sessions,
respectively)
Auth REST API modified as follows:

Added /:version/mfa/users/:user/login/begin (1st login step)
ssh/authenticate and web/authenticate now support Webauthn (2nd login step)
U2F endpoints deprecated, but support full breadth of MFA options as well
(/:version/u2f/users/:user/sign)

RFD: https://github.com/gravitational/teleport/pull/7808.

* Plug Webauthn into MFAAuth protos
* Generate protos
* Make CredentialAssertionResponse json-friendly
* Add Webauthn proto conversions
* Wire Webauthn to auth apiserver
* Wire Webauthn login to web apiserver
* Wire Webauthn to web login
* Add missing license headers
* Delete login_identity_test.go
* Use previously acquired devices on mfaAuthChallenge
* Take U2F App ID literally if it's not a proper URL
* Add direct tests for auth.Server
* Use trace.BadParameter consistently
* Include user name in "failed to authenticate" logs
* Add more login-related tests to auth.Server
2021-09-02 11:51:42 -07:00
Lisa Kim ab57eab5c0 [RC 2] Extend GetMFADevices to accept tokenID (#8036)
* Add withSecrets bool parameter to identity service GetMFADevices 
  that removes secret (totp key) if true
* Add web handlers for getting devices for authenticated users
* Fix data race with RecoveryAttemptsCRUD test
2021-08-26 19:19:35 -07: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 917df5ad02 gRPC conversions - Auth Preference (#7220) 2021-06-18 12:30:56 -05:00
Andrew Lytvynov d4247cb150 hsm: migrate CA storage schema (#7245)
* hsm: migrate CA storage schema

Migrate types.CertAuthorityV2 schema according to
https://github.com/gravitational/teleport/blob/master/rfd/0025-hsm.md#backend-storage

Includes proto changes, types.CertAuthority wrapper changes and data
migration.

Note that we keep and update the old fields for backwards-compatibility.
If a cluster is upgraded to v7 and then downgraded back to v6,
everything should keep working.

* Address review feedback
2021-06-16 12:17:03 -05:00
Andrej Tokarčík 2747cc75bf Move ClusterConfig auth fields into ClusterAuthPreference (#6876) 2021-06-07 11:07:02 -07:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
jane quin 7c9fd8e50d Add additional Prometheus Metrics (#6511) 2021-04-28 15:46:27 -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
Andrew Lytvynov f9f62ff902 mfa: audit events for adding/removing devices (#5665)
* mfa: audit events for adding/removing devices

Also add `With2FA` field to `UserLogin` when an MFA device is used
during login.

* Address review feedback

* mfa: reorganize audit event structure to be flat
2021-03-04 11:02:35 -08:00
5739b63e51 mfa: add new second_factor options "on" and "optional" (#5508)
* mfa: add new second_factor options "on" and "optional"

"on" means that 2FA is required for all users, either TOTP or U2F.

"optional" means that 2FA is supported for all users, but not required.
Only users with MFA devices registered will be prompted for 2FA on
login.

The login with both supported methods is using the same API as the U2F
login. It just now supports TOTP in addition. The API endpoints are
still named after "u2f", I'll rename those in a future PR (in a
backwards-compatible way).

* Apply suggestions from code review

Co-authored-by: Gus Luxton <gus@gravitational.com>
Co-authored-by: a-palchikov <deemok@gmail.com>

* Address reivew feedback

Co-authored-by: Gus Luxton <gus@gravitational.com>
Co-authored-by: a-palchikov <deemok@gmail.com>
2021-02-16 16:24:23 -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
Andrew Lytvynov 4b5bb54bf4 u2f: restructure MFA backend to support multiple devices (#5404)
Each user can now have multiple devices. This commit only changes the
backend structure to support it, the client and API haven't been updated
yet.

Also added a migration for existing MFA data on auth server startup.
2021-02-01 17:30:39 -08: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
Andrew Lytvynov 79b0d54ee8 u2f: extract registration/authentication logic into lib/auth/u2f (#5387)
This is just a refactoring without functional changes. Pull all the u2f
handling spread across multiple client and server packages into one
place.

Also clean up an obsolete vendored dependency, unrelated to this PR.
2021-01-29 11:30:15 -08:00
Brian Joerger 7f0c20d9a2 API Dependency Reduction - lib/jwt (#5295)
Refactor CertAuthority methods and GenerateAppToken to remove lib/jwt dependency.
2021-01-19 14:16:25 -08: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 17e10353a9 Prevent a username oracle via user lockout checks
User lockout check (auth.WithUserLock) would fail early in case a login
for unknown user was requested. The error is "user not found".
This can be used to enumerate the available Teleport users.
Even if the error message was more generic, timing can be trivially used
to infer whether a password was checked (bcrypt takes a while).

To avoid this, run the regular authentication flow regardless if the
user was found and return the generic "username or password invalid"
error.

Relatedly, fix a bug in the password verification. There's a timing
mitigation logic that replaces the expected password hash with a fake
one to perform a full bcrypt check. This fake has was for password
"barbaz".
If a login was requested for unknown user with password "barbaz", the
check would pass. Fortunately, the above user existence check in
auth.WithUserLock prevented this code path.
2020-06-03 21:57:19 +00:00
Andrew Lytvynov a9eae02374 errcheck: add missing error handling in lib/auth 2020-06-03 21:57:04 +00:00
Andrew Lytvynov 868303389e Add a unit test for auth.AuthenticateSSHUser
This method should correctly populate k8s principals and RouteToCluster.
2020-05-21 20:37:28 +00:00
Andrew Lytvynov 19e316f968 Plumb RouteToCluster and k8s principals on login
TLS credentials on login appear different from them on re-issue.
Specifically, they are missing kube users/groups in Subject, as well as
RouteToCluster.

With this change, user can now do:
$ tsh login --proxy=root-proxy leaf-proxy
$ kubectl get ...
and kubectl commands will get routed through root-proxy to leaf-proxy
and contain proper kube principals for the user.
2020-05-21 20:37:28 +00:00
Andrew Lytvynov 0add471f16 gosimple: remove comparisons to boolean constants
`if x == true` or `if x == false` should be just `if x` or `if !x`.
2020-05-15 16:32:45 +00:00
3c670d5d58 Merge Teleport V4.3 UI branch to master (#3583)
* Add monorepo

* Add reset/passwd capability for local users (#3287)

* Add UserTokens to allow password resets

* Pass context down through ChangePasswordWithToken

* Rename UserToken to ResetPasswordToken

* Add auto formatting for proto files

* Add common Marshaller interfaces to reset password token

* Allow enterprise "tctl" reuse OSS user methods (#3344)

* Pass localAuthEnabled flag to UI (#3412)

* Added LocalAuthEnabled prop to WebConfigAuthSetting struct in webconfig.go
* Added LocalAuthEnabled state as part of webCfg in  apiserver.go

* update e-refs

* Fix a regression bug after merge

* Update tctl CLI output msgs (#3442)

* Use local user client when resolving user roles

* Update webapps ref

* Add and retrieve fields from Cluster struct (#3476)

* Set Teleport versions for node, auth, proxy init heartbeat
* Add and retrieve fields NodeCount, PublicURL, AuthVersion from Clusters
* Remove debug logging to avoid log pollution when getting public_addr of proxy
* Create helper func GuessProxyHost to get the public_addr of a proxy host
* Refactor newResetPasswordToken to use GuessProxyHost and remove publicUrl func

* Remove webapps submodule

* Add webassets submodule

* Replace webapps sub-module reference with webassets

* Update webassets path in Makefile

* Update webassets

1b11b26 Simplify and clean up Makefile (#62) https://github.com/gravitational/webapps/commit/1b11b26

* Retrieve cluster details for user context (#3515)

* Let GuessProxyHost also return proxy's version
* Unit test GuessProxyHostAndVersion & GetClusterDetails

* Update webassets

4dfef4e Fix build pipeline (#66) https://github.com/gravitational/webapps/commit/4dfef4e

* Update e-ref

* Update webassets

0647568 Fix OSS redirects https://github.com/gravitational/webapps/commit/0647568

* update e-ref

* Update webassets

e0f4189 Address security audit warnings Updates  "minimist" package which is used by 7y old "optimist". https://github.com/gravitational/webapps/commit/e0f4189

* Add new attr to Session struct (#3574)

* Add fields ServerHostname and ServerAddr
* Set these fields on newSession

* Ensure webassets submodule during build

* Update e-ref

* Ensure webassets before running unit-tests

* Update E-ref

Co-authored-by: Lisa Kim <lisa@gravitational.com>
Co-authored-by: Pierre Beaucamp <pierre@gravitational.com>
Co-authored-by: Jenkins <jenkins@gravitational.io>
2020-04-15 15:35:26 -04:00
Alexander Klizhentas 8be98bcc21 Remove blacklisted FIPS ciphersuites, fix local_auth (#3103)
This commit fixes Web UI in FIPS mode when local_auth is false
and removes two ciphers banned by HTTP2 rfc spec:

https://tools.ietf.org/html/rfc7540#appendix-A

and used by FIPS, causing Teleport GRPC to fail.
2019-10-23 13:55:40 -07:00