Commit Graph
50 Commits
Author SHA1 Message Date
rosstimothy fa3bb9ac59 Ensure that the webclient closes connections (#22832)
The `http.Client.Transport` created in `newWebClient` wraps a
chain of `http.RoundTripper` over an underlying `http.Transport`.
Since we cannot guarantee that each `http.RoundTipper` has a
`CloseIdleConnections` method the usage of
`defer clt.CloseIdleConnections()` does not guarantee that the http
connections created during Find/Ping/etc are closed.

To prevent leaking connections implementations of `http.RoundTripper`
have added a `CloseIdleConnections` method added that forwards the
request on to the wrapped interface. The `otelhttp.Transport` does
not implement this method either so care has been taken to wrap it
in a `http.RoundTripper` which will call the root transport in
`enforceCloseIdleConnections`. An upstream issue has been filed
with otelhttp: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/3543
to get the method added to their `Transport` implementation.

This wasn't noticed prior to upgrading to go1.20 becuase prior to
[this](https://github.com/golang/go/commit/4e7e7ae1406c70d9cc0809ec11105a55a60a0b70)
commit the `ReadHeaderTimeout` set on the Proxy web api http.Server
would cause the connection to appear idle and get terminated by the
server.

`TestWebClientClosesIdleConnections` was added to capture the leak
in connections as reported in #22757 and prevent any regressions.
2023-03-10 15:21:16 +00:00
Jakub Nyckowski 8329021148 Skip building webassets in CI (#22549)
* Skip building webassets in CI

Building webassets is not always needed and many of our CI build just builds them and ends up not using them after.
This PR skips building the webassets for all pipelines where they are not needed. This should save us some time and $$.

* Make some changes to trigger CI

* Create the missing directory
2023-03-03 15:14:25 +00:00
Ryan Clark 15bd28ae82 Add caching to web assets (#22137) 2023-02-23 12:20:58 +00:00
Jakub Nyckowski 79ebdc89c8 Bump golangci-lint to v1.51.1 (#21440) 2023-02-08 00:44:08 +00:00
Ryan ClarkandZac Bergquist f2fbe92dcb Change the application access authentication flow (#17592)
* Change the application access auth flow to use a CORS POST request

* Remove auth state cookie

* Close the response body in tests

* Change the CSP to allow cross origin requests to the application

* Change the cookies to lax mode

* Update lib/web/app/handler_test.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Fix the proxy URL in tests

* Update webassets ref

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-01-12 21:57:01 +00:00
Gavin Frazar eccfd9342e Refactor app access (#19387)
* Move logic out of RoundTrip and into ServeHTTP as a middleware before handing off to oxy forwarder
* Move AWS signing service code into lib/utils/aws/signing.go
* use app server close context for audit event emitting
* add go doc comments.
* refactor request rewriting to make the copy in a more robust way.
* pass status code as uint32 rather than casting in audit emitter
* clone request instead of making a new request, and rewrite url to force https
* update header handling
* Set oxy forwarder to PassHostHeader=false to ensure the host header is
  the URL being sought.
* Remove code that deleted forwarding headers previously, we should keep
  those (X-Forwarded-*).
* Audit log the AWS Host sought rather than the incoming request Host
  header (prior behavior maintained, we just rewrite the request
  differently using Clone).
* Remove obsolete header copying helper func
2022-12-23 00:56:27 +00:00
Mike Jensen b835c21616 Update Referrer-Policy response header to strict-origin (#19114)
This is a slightly more restrictive response header which will result in protecting the origin if the request is downgraded to http.
Although no http listeners exist within the service, this should be a safe and slightly more secure default for us to use.
2022-12-06 22:07:02 +00:00
Mike Jensen 8c1e7be02d Security Response Header Uniformity Improvements (#18951)
Our need for customizing our security response headers primarily exists with the Content-Security-Policy.  Other headers can be applied more broadly to provide safe defaults across our service.

This commit changes httpheaders.go to allow for the CSP to be applied separate from the other headers.  Then the changes to httplib.go's handlers help make sure these headers are set generally (which we were already partially doing for caching directives).

Other changes were primarily making sure these tools are configured or used.  Or a removal of previous settings as this function is now being handled more centrally.
2022-12-06 00:56:59 +00:00
rosstimothy 02433f6eb2 Forward traces from the web UI (#18519)
* Forward traces from the web UI

Adds a `/webapi/traces` endpoint to the proxy web handler
to allow receiving traces from the UI so that they can
be forwarded to the configured exporter in the proxy_service.

To accomodate traces coming in via websockets the tracing
handler is updated to pull tracing context first from the
standard headers and fallback to retrieving it from a query
parameter as web sockets from the UI cannot alter headers.

Additionally update `web.Terminal` to propagate the tracing
context properly and instruments some of the functions
to ensure spans from the UI are properly correlated to spans
on the backend.
2022-11-18 13:46:41 +00:00
Michael b9371c0328 Add test for ConvertResponse and fix url.Err conditional (#18330) 2022-11-15 01:52:36 +00:00
jkaczmarkiewiczandAlan Parra 2a9167b03b set cluster connector name on signin for first cloud user (#17834)
* feat: set cluster connector name on first user signin

* perf: move is passwordless enabled before get users

* fix: move logic to correct handler

* test: test setting default passwordless connector name for cloud (positive case)

* test: add negative test cases

* refactor: flatten nested code

* fix: remove return in case auth preference was not set

* fix: run logic only in cloud

* docs: typo

* fix: run when passwordless

* test: move trySettingConnectorNameToPasswordless as separete method

* docs: add safety comments

* test: rephrase safety comment

* refactor: remove space between call and error check

* fix: remove unnessesery error log from trySettingConnectorNameToPasswordless

* refactor: pass context, rename session context

* docs: add description to trySettingConnectorNameToPasswordless

* test: add descriptive assertion text

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* refactor: simplify error handilng

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* fix: check for non default setting

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* test: correct RPID

* refactor: simplify user creation

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* docs: fix typo

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* test: reorder name filed in the test cases struct

* test: better names for test cases

* refactor: generate token instead of hardcoding arbitrary value

* test: remove user agent header

* fix: check for empty password

* docs: add passwordless check description

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* test: add "first cloud sign-in does not change custom connector"

* test: use correct number of users in "first cloud sign-in does not change custom connector"

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* test: remove is cloud check from test helpers, instead use config

* refactor: store is_passwordless_registration in variable

* test: first cloud sign-in with password does not change connector

* refactor: change isPasswordlessRegistration name

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2022-11-14 14:52:42 +00:00
Michael 4802d7d7e6 Fix incorrect logging when urls contain escaped characters (#16445) 2022-11-05 00:35:33 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Reed Loden d33444e411 Remove Stripe from Content-Security-Policy header (#15891)
Teleport Cloud no longer handles payments via Stripe, so no need to whitelist Stripe in CSP for `script-src` and `frame-src`.
2022-09-13 22:59:23 +00:00
rosstimothy 54d32e1aa8 Use tracing handler per server not per route (#16342)
Tracing handlers consume a large amount of memory over time, which
makes using one per route suboptimal (See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/2413).
Wrapping all `http.Server` handlers with a tracing handler provides
the same tracing abilities for a fraction of the memory usage. A new
span formatter is added which allows servers to still contain the
request span in the span name.
2022-09-13 16:31:53 +00:00
Alex McGrath f56dd09ebd Add an installer script resource type and public HTTP endpoint (#13146)
* Add an installer script resource type and HTTP endpoint

* Add default installer scripts

* Resolve comments

- run `shfmt` over the installer script
- add MustNewInstaller
- move default installer logic to GetInstaller
- only include PublicProxyAddr in server.Config

* Resolve comments

- move from auth_with_roles -> auth/grpcserver
- document `MustNewInstallerV1`
2022-08-15 10:27:33 +00:00
Russell Jones 823bbfcc22 Refactor tests under httplib package.
Refactored all tests under "lib/httplib" to use testify instead
of gocheck.
2022-08-12 17:11:13 -07:00
2717c1d2e0 Security fixes (#13298)
* Add CSRF mitigations

This commit includes two fixes:

1. Enforce an application/json Content-Type server-side.
2. When checking the bearer token, verify that the user
   associated with the token matches the user associated
   with the cookie.

* Fix TEL-Q122-13: Access Requests Denial Of Service Via Request Reason (#125) (#127)

* Ignore input when data flow is off in TermManager

When data flow is disabled in TermManager (at the beginning or when TermManager.Off was called) we should ignore all input we receive (currently we buffer it)

* Agent forwarding socket security fix.

Co-authored-by: Lisa Kim <lisa@goteleport.com>
Co-authored-by: Joel <jwejdenstal@icloud.com>
Co-authored-by: Przemko Robakowski <przemko@przemko-robakowski.pl>
2022-06-08 18:12:45 +00:00
rosstimothy 80d6bff4e5 Add auto instrumentation to http and grpc clients and servers (#12231)
Leverage otelhttp to generate spans for http clients and http handlers.
Additionally add spans for grpc clients and servers by using the
otelgrpc interceptors. This is step one in implementation of RFD 65.
Until further work is done, the spans generated will be a no-op
until the tracing provider is initialized.
2022-05-03 15:55:31 -04:00
Krzysztof SkrzętnickiandPrzemko Robakowski 66a676eb73 Switch to forked httprouter and enable UseRawPath option (#11068)
* Use forked httprouter with RawPath fix: gravitational/httprouter

* Enable UseRawPath everywhere.

* Test: allow MFA devices with `/` in names to be deleted

Co-authored-by: Przemko Robakowski <przemko.robakowski@goteleport.com>
2022-04-19 07:16:54 +00:00
Alexey Kontsevoy 54d5fe6c22 allow websocket connections to the same host (csp) (#7929) 2021-08-19 22:55:33 -04:00
Alexey Kontsevoy 79f7d4b1e7 Make CSP more strict (#7390)
closes https://gravitational.zendesk.com/agent/tickets/3062
2021-06-24 02:17:46 -04:00
Pierre Beaucamp c95de98c63 Improve error message for timeout errors (#6343)
This fixes #6074
2021-04-26 08:39:07 -07:00
Alexey Kontsevoy 472df28f2a Add "billing_information" RBAC resource (#5676)
* Expose GRPC client connection to plugins
* Replaces global plugin state with the PluginRegistry
2021-03-01 22:47:03 -05:00
Andrej Tokarčík ff18d38d7e Set cookies with '__Host-' prefix 2021-03-01 22:14:10 +01:00
Andrej Tokarčík c4faea980f Set stricter HTTP Content-Security-Policy directives 2021-03-01 22:14:10 +01:00
Andrej Tokarčík 89f0432ad5 Introduce utils.ReadAtMost to prevent resource exhaustion 2021-03-01 22:14:10 +01:00
Andrew Lytvynov 96019ce0be Make k8s errors responses decode-able by kubectl (#5166)
* Make k8s errors responses decode-able by kubectl

`kubectl` expects a k8s `Status` object in error responses.
Intercept generic handler errors and forwarder errors, and wrap them in
a `Status` object.
2020-12-18 15:27:45 -08: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 7ccdd87496 Enable more Go linters: varcheck,bodyclose,structcheck
All changes should be noop, except for
`integration/integration_test.go`.

The integration test was ignoring `recordingMode` test case parameter
and always used `RecordAtNode`. When switching to `recordingMode`, test
cases with `RecordAtProxy` fail with a confusing error about missing
user agent. Filed https://github.com/gravitational/teleport/issues/3606
to track that separately and unblock enabling `structcheck` linter.
2020-04-24 15:52:43 +00:00
Alexey Kontsevoy f46d284b15 Set SameSite attribute on CSRF cookie 2020-03-13 17:27:42 -07:00
Alexey Kontsevoy f42458f8b7 Add Referrer-Policy header 2019-09-03 13:44:20 -07:00
Sasha Klizhentas cece4be212 Initial implementation of Kubernetes support
This issue updates #1986.

This is intial, experimental implementation that will
be updated with tests and edge cases prior to production 2.7.0 release.

Teleport proxy adds support for Kubernetes API protocol.
Auth server uses Kubernetes API to receive certificates
issued by Kubernetes CA.

Proxy intercepts and forwards API requests to the Kubernetes
API server and captures live session traffic, making
recordings available in the audit log.

Tsh login now updates kubeconfig configuration to use
Teleport as a proxy server.
2018-06-03 12:55:13 -07:00
Sasha Klizhentas 3e144cb900 Teleport certificate authority rotation.
This commit implements #1860

During the the rotation procedure issuing TLS and SSH
certificate authorities are re-generated and all internal
components of the cluster re-register to get new
credentials.

The rotation procedure is based on a distributed
state machine algorithm - certificate authorities have
explicit rotation state and all parts of the cluster sync
local state machines by following transitions between phases.

Operator can launch CA rotation in auto or manual modes.

In manual mode operator moves cluster bewtween rotation states
and watches the states of the components to sync.

In auto mode state transitions are happening automatically
on a specified schedule.

The design documentation is embedded in the code:

lib/auth/rotate.go
2018-04-30 12:58:57 -07:00
Alexey Kontsevoy e86fffd28f (web) adding CSRF protection to OIDC and SAML callbacks 2017-10-06 16:19:05 -04:00
Roman Tkachenko b9b970162f Safe redirect for oidc/saml 2017-10-03 18:29:02 -07:00
Alexey Kontsevoy 07783385d3 (web) csrf protection of public API 2017-10-02 00:01:13 -04:00
Alexey Kontsevoy 50029e97ee (web) refactoring + ssh login 2017-08-16 17:58:49 -04:00
Alexey Kontsevoy ae39dc01d6 set HTTP response flags to ensure no-caching and to enhance web security 2017-07-17 18:44:26 -04:00
Sasha Klizhentas 698e615fd7 make API backwards compatible with pre-namespaces 2016-12-13 14:20:52 -08:00
Sasha Klizhentas b510f93cca add support for rewriting paths 2016-12-13 13:44:26 -08:00
Sasha Klizhentas 09398da494 more work on rewrites 2016-12-13 10:19:30 -08:00
klizhentas d68e693cad migrate to trace errors 2016-04-12 11:07:14 -07:00
klizhentas 3fdbeb8d77 expose connectors via config.json 2016-04-04 14:06:27 -07:00
klizhentas 4ff59c59b5 support draft console login 2016-04-03 15:06:50 -07:00
klizhentas 18a6e69323 use this 2016-04-03 12:09:00 -07:00
klizhentas 6edd6675e6 re-introduce reverse tunnels into teleport
Reverse tunnels are now first class citizens of teleport.
There's no longer static configuration for reverse tunnel agents
in the config. Instead, admins can add and remove reverse tunnels
using tctl reversetunnel (hidden) commands.

* tctl reversetunnel ls
  lists reverse tunnels

* tctl reversetunnel upsert a.example.com 10.0.0.4:2023,10.0.0.5:2033 --ttl=10m
  updates or inserts reverse tunnel for 10 minutes

* tctl reversetunnel del a.example.com
  deletes a reverse tunnel

Teleport proxies watch changes in the reverse tunnels on the backend and
spin up / spin down reverse tunnels according to these changes.
2016-03-18 17:13:22 -07:00
klizhentas 1eb952b89f properly propagate HTTP errors, fixes #172 2016-03-07 17:05:57 -08:00
klizhentas c64e3d4261 add working connect 2016-02-25 14:26:26 -08:00
klizhentas 6ef5f36037 refactor API to use JSON instead of forms, unify error handling 2016-02-23 12:03:34 -08:00