44 Commits
Author SHA1 Message Date
Tiago Silva 05419f28b6 support where RBAC on application session recordings (#69630)
* support `where` RBAC on application session recordings

application session recordings are backed by AppSessionChunk events, but
those events were never wired into the session recording RBAC path, so
`where` clauses on `kind: session` rules could not match them.

Fixes https://github.com/gravitational/teleport/issues/67775

Signed-off-by: Tiago Silva <[email protected]>

* fix unit test

* handle feedback

---------

Signed-off-by: Tiago Silva <[email protected]>
2026-08-13 14:29:20 +00:00
Pawel Kopiczko 3be66d9dbc MCP: Fix http test case (#68511) 2026-07-09 20:39:24 +00:00
Zac Bergquist e31ae30864 Fix copy-paste error in app access test (#68259)
We were registering cleanup actions to close the same
streamableHTTPServer twice, and never closing streamableHTTPTLSServer.
2026-06-30 18:27:55 +00:00
Pawel Kopiczko d7ae6f8afb MCP: Fix HTTPS support for SSE (#68020)
* MCP: Fix HTTPS support for SSE

* Add streamable HTTP cases

* Change matching to include "://" instead
2026-06-23 12:30:07 +00:00
Zac BergquistandMichael b4381580e1 app access: improve handling of overlapping public addrs (#67519)
* app access: improve handling of overlapping public addrs

This change improves Teleport's handling of multiple apps with the
same public address by selecting apps based on both the app name
and its public address (rather than the public address alone).

This selection happens both at the proxy (in order to select an
app_service), and at the app service (in order to select the right
app from the set of apps the agent serves).

The change is backwards compatible, if the app name is not provided
then the selection happens based on public address alone, matching
the prior behavior.

It's worth noting that Teleport has always encoded the app name
in certificates for the CLI-based (tsh apps login) flow, but the
web UI's browser flow has not been including the app's name until
now. As a result, users will need to update auth, proxy, and app
agents to get the full set of fixes.

Note: there's still one pre-existing issue that remains unsolved.
We should address this separately. When a user navigates directly
to an app's FQDN in the browser without first having a valid session,
then addr-based resolution is the only option available. As of now,
this check is not RBAC-aware, and can select an app that the user
doesn't have access to. (There is no authz bypass, the user will get
an access denied error, but we should make this deterministic).

Fixes #67462

* Make FQDN-only resolution RBAC-aware

This covers the web UI case where a user navigates directly to an
app's FQDN without a valid Teleport session or without first clicking
launch in the Teleport UI.

Prior to this change, we'd select an app with a matching FQDN at
random. This selection wasn't RBAC-aware, so we could end up picking
an app the user doesn't have access to, guaranteeing they see an
access denied error.

* Add a leaf cluster integration test

* Update lib/auth/grpcserver_test.go

Co-authored-by: Michael <[email protected]>

---------

Co-authored-by: Michael <[email protected]>
2026-06-18 17:27:52 +00:00
rosstimothy fc72fdcdc2 Update tests to inject modules instead of relying on modulestest.SetTestModules (#65976)
This is a pass on replacing modulestest.SetTestModules with supplying modules
where already possible. Some additional uses of modules.GetModules were also
replaced with localized modules injection to permit the removal of
modulestest.SetTestModules in tests. Most of the changes here are mechanical,
the one notable change is in TestSSHCommands. The test was not passing locally
because the shell (fish) builtin echo behaves differently. The easiest way
to produce expected output was to change the command invocation to use
/bin/echo to bypass any shell builtins for consistent behavior.

Inject modules into tool tests

Inject modules into integration tests

Inject modules into join server

Remove superflous enterprise modules in TestAuthenticationConfig_Parse_deviceTrustPB

Inject modules into signature algorithm config tests

Inject modules into TestGithubConnectorCRUDEventsEmitted

Inject modules into TestGetHierarchyForUser

Inject modules into kube proxy tests

Inject modules into controller tests

make fix-imports

add integration/app/fixture as test package
2026-04-22 17:38:51 +00:00
Kenneth fc5bdb1535 Revert "Created check for device trust after MFA before creating web session (#62019)" (#63523)
This reverts commit ddc4586440.
2026-02-06 03:44:30 +00:00
Kenneth ddc4586440 Created check for device trust after MFA before creating web session (#62019) 2026-01-23 21:25:10 +00:00
Alan Parra 2740ad632a chore: Bump golangci-lint to v2.7.2 (#62066)
* chore: Bump golangci-lint to v2.7.2

* Update e/ reference

* Fix require.IsType issues

* Reverse require.Equal

* Simplify testWebsockets

* Fix TestCreateResources

* Remove trace.Unwrap
2025-12-09 17:59:21 +00:00
STeve (Xin) Huang 8489b48810 [mcp] server handler for streamable HTTP transport (#59499)
* [mcp] server handler for streamable hTTP transport

* review comments round 1

* add comments and fix flaky test
2025-09-29 17:42:09 +00:00
STeve (Xin) Huang 7da6004c23 [flaky] TestAppAccess/AuditEvents harden ensureAuditEvent (#59314) 2025-09-18 15:27:51 +00:00
Gabriel Coradoandrosstimothy c369e603ba Reduce TestAppAccess/TestAppServersHA test flakiness (#59262)
* test(appaccess): ensure applications are served by the started agent

* Update integration/appaccess/pack.go

Co-authored-by: rosstimothy <[email protected]>

---------

Co-authored-by: rosstimothy <[email protected]>
2025-09-17 22:39:37 +00:00
STeve (Xin) Huang 5a0a522a5f [MCP] server-side SSE support (#56051)
* MCP access part 12: server-side SSE support

# Conflicts:
#	api/types/app_test.go
#	api/types/events/events.pb.go
#	integration/appaccess/appaccess_test.go
#	lib/srv/mcp/memory.go
#	lib/srv/mcp/server.go
#	lib/srv/mcp/stdio_test.go
#	lib/utils/mcputils/protocol.go
#	lib/utils/mcputils/stdio.go

* parse uri for determining transport type

* fix pointer, atomic, and parse error

 Conflicts:
	lib/srv/mcp/server.go

* fix schema, etc

* switch to golang internal mcp sse parsing

* remove ParentCtx from logging

* fix build and address comments
2025-08-25 17:53:38 +00:00
STeve (Xin) Huang 1a9f35ec9c Teleport MCP demo server (#56637)
* Teleport MCP demo server

* replace guide tool with session tool, and switch to resource label

* add new flag to teleport configure

* replace teleport_session_id with mcp_transport_type
2025-07-15 13:16:43 +00:00
rosstimothy 2afdce29c5 Introduce modulestest package (#56721)
The new package is meant to house a test friendly implementation
of modules.Modules. Due to the pervasive and global nature of
modules, this package also contains a copy of of
modules.SetTestModules. In a perfect world this function wouldn't
be needed and modules would be injected where required, however,
that would take considerable effort. The existing test modules
are temporarily left in place until the enterprise tests can be
updated to use modulestest.
2025-07-14 21:55:07 +00:00
Zac Bergquist 6dbcf9b5d3 Modernize lib/backend, lib/cache, lib/cloud, and integration (#55921) 2025-06-21 15:05:11 +00:00
STeve (Xin) Huang 4f90594e64 MCP access part 9: tsh mcp connect, stub server, integration test (#55547)
* MCP access part 9: tsh mcp connect, stub server, integration test

* fix tests and lint
2025-06-13 13:18:54 +00:00
Rafał Cieślak 3653dda622 Add basic support for target port in gateways in Connect (#50912)
* Update type for targetSubresourceName on DocumentGateway

The way DocumentsService.createGatewayDocument is implemented means that
the targetSubresourceName property is always present, but it can be undefined.

* Use "local port" instead of "port" in DocumentGatewapApp

* Rewrite gateway FieldInputs to use styled components

* Update comments in protos

* useGateway: Stabilize useAsync functions of ports

* Add padding to menu label if it's first child

* Add support for required prop to Input and FieldInput

* Add UI for changing target port

* ActionButtons: Show ports of multi-port apps when VNet is not supported

Now that we have support for the target port in Connect's gateways, we
can show the ports and then open a gateway for that specific port on
click.

* Add RWMutex to gateways

* Clear app gateway cert on target port change

* Remove gateways/app.LocalProxyURL

It was used only in tests and it made sense only for web apps anyway.

* TestTCP: Close connections when test ends

* Create context with timeout in testGatewayCertRenewal

…instead of in each function that uses it.

* Add tests for changing the target port of a TCP gateway

* Parallelize app gateway tests within MFA/non-MFA groups

* Make testGatewayConnection take ctx as first arg

This will be needed in tests that check target port validation.

* Validate target port of app gateways

* Increase timeouts in app gateway tests

* Change icons from medium to small

* Use consistent spacing in AppGateway

* Add godoc for ValidateTargetPort

* Add retry with relogin to change target port
2025-01-13 16:55:41 +00:00
Rafał Cieślak 0ade3a8f58 Add TargetPort to RouteToApp & use it to route connections to multi-port TCP apps (#49047)
* Add TargetPort to RouteToApp and AppMetadata proto messages

* Pass TargetPort during cert generation

* Refactor Pack.makeTLSConfig to accept struct

This will make it easier to add targetPort to it.

* Add labels to UUIDs used by appaccess test pack app servers

This makes them easier to distinguish when routing doesn't work as expected.

* Refactor Pack.CreateAppSession to accept a struct

* TestTCP: Create app session within test

If we kept the old code, we'd need to manually create a session for each
target port, which would create a lot of duplication.

* Prepare integration test fixtures for multi-port tests

* Add api/utils/net.IsPortInRange

* Use TargetPort when routing TCP connections

* Inline dialMultiPortTCPApp, centralize logic

* Check target port when connecting to single-port app

* Reorder check in IsPortInRange

* Use int instead of uint16

* Extract picking dialTarget to separate function

* addr → uriAddr

* Improve err msg for single-port apps when targetPort != uriPort

* Fix unnecessary conversion to int
2024-12-03 13:55:00 +00:00
Michelle Bergquist 70b95e385d Surface Cloud Entitlements (#42394)
- Cloud entitlements are now available on Features
- Legacy logic applies if entitlements are not present
2024-06-28 00:22:13 +00:00
Brian Joerger 12c7689df5 Refactor GenerateUserCerts to create App Sessions (#39970)
* Add CreateAppSessionFromReq.

* Deprecate passing route_to_app.session_id in cert requests.

* Automatically create app sessions for app cert requests.

* Deprecate client use of CreateAppSession for app cert requests.

* Fix affected tests.

* Use traits and roles from existing user certificate for app sessions.

* Fix app access integration tests.

* go mod tidy.

* Fix TestTCP.

* Fix TestALPNSNIProxyAppAccess.

* Revert "go mod tidy."

This reverts commit cc6caa2485.
2024-04-25 05:13:55 +00:00
Brian Joerger b88251a278 CreateAppSession with MFA (#39650)
* Replace types.CreateAppSessionRequest with proto.CreateAppSessionRequest.

* Add MFA response proto.CreateAppSessionRequest.

* Verify MFA response in CreateAppSession.
2024-03-21 17:18:08 +00:00
rosstimothy 9734fcbdbd Convert SetSessionRecordingConfig usages to new Create/Update/Upsert API (#39249)
Migrates callers off the deprecated API and onto the new API so
that SessionRecordingConfig can be protected via optimistic locking
when appropriate.
2024-03-15 19:55:57 +00:00
Gabriel CoradoandAlan Parra 89d1aa460d Use time-based event index for app session events (#38495)
* feat(events): add event indexer based on time

* chore(events): code review changes

* chore: typos

* Apply suggestions from code review

Co-authored-by: Alan Parra <[email protected]>

* chore: code review changes

* test(integration): ignore index field on audit events

---------

Co-authored-by: Alan Parra <[email protected]>
2024-02-29 03:14:43 +00:00
fheinecke b178b8b732 Updated Teleport codebase to AGPL3 license (#35259)
Signed-off-by: Fred Heinecke <[email protected]>
2023-12-01 17:48:14 +00:00
rosstimothy d5a796c056 Enable testify lint (#34222)
Updates our golangci-lint configuration to enable testifylint and
fixes all issues found.

Bump e ref to include gravitational/teleport.e#2567
2023-11-06 20:38:38 +00:00
Michael Wilson b87a2c9853 Remove Cf-Access-Token header. (#32139)
The Cf-Access-Token header seems to be a infrequently used header that can
easily increase the size of the header by `len(roles) + len(traits)`, which
can cause problems. Users are able to add this in on their own if they need
it using header rewriting, so we'll remove this.
2023-09-19 22:14:57 +00:00
Tiago Silva ebecb59468 Replace graviational/oxy.Forwarder with httputil.ReverseProxy (#27761)
This PR replaces the usage of `gravitational/oxy.Forwarder` in our codebase with `httputil.ReverseProxy`.

`httputil.ReverseProxy` is part of Go's standard library and thus it is
 maintained by the Go team. Converting everything to use the std lib
 allows us to drop our `oxy` fork.

 There are some operational changes between the two versions:

 1. `httputil.ReverseProxy` handles WebSockets upgrades internally and
    reuses the `Transport` provided for the initial request. Thus, it does
    not require any special dialer or rewriter mechanisms for WebSockets only.

 2. `httputil.ReverseProxy` calls the `ErrorHandler` with the request
       after it was rewritten and after roundtrip was called. This was a
       problem because our `web.transport` deletes Teleport associated
       cookies and when the request failed, the request received by the
       `ErrorHandler` missed the cookies to generate a new session. This was
       fixed by cloning the request at `web.transport` round tripper.

 3. `httputil.ReverseProxy` uses std's `log.Logger`. `logrus` exposes a
       method `Writer` that allows it to be used with standard lib logger.

The API is similar to what our `oxy` fork has available.

Fixes #27412
2023-06-29 13:50:07 +00:00
cf2c7059a3 Add full IP pinning enforcement (#24743)
* Add full IP pinning enforcement

We're adding IP pinning check to `authorizer.Authorize` which is used for every call,
so now all communications with teleport should enforce IP pinning.
Also making sure we always provide login IP for user certificate creation
and correct client IP propagation everywhere.

* Add integration test for App IP pinning.

* Fix wording

Co-authored-by: Tiago Silva <[email protected]>

* Wrap error

Co-authored-by: Tiago Silva <[email protected]>

* Add godocs

* Clone TLS config

* Improve proxyHeaderSigner usage

* Wider use proxyHeaderDialer and remove adhoc writing of singed header

* Add helper function TLSDial

* Use proxyHeader dialer in authConnect

* Simplify tlsConfig manipulation

Co-authored-by: Przemko Robakowski <[email protected]>

* Remove redundant channels processing in TLSDial

* Reduce nesting

* Update generated protobufs

* Remove ignoring of bad IP on signed PROXY header generation

* Provide logger to CheckIPPinning function

---------

Co-authored-by: Tiago Silva <[email protected]>
Co-authored-by: Przemko Robakowski <[email protected]>
2023-04-23 17:09:49 +00:00
Zac Bergquist 2ae9d770fc Refactor tctl's dependencies (#22693)
* Move configuration from lib/service to lib/service/servicecfg

The new servicecfg package will hold only configuration for services.
This will allow other packages (like tctl and tsh) to depend on
servicecfg without pulling in all of lib/service (which has a number
of platform-specific details).

This is the first step towards being able to build tctl for Windows.

* Move PAM and BPF config into servicecfg

This breaks a compile-time dependency on BPF/PAM for tctl.
2023-03-09 17:48:36 +00:00
Gabriel CoradoandRafał Cieślak bc63dddd7b Verify if proxy can handle application requests when creating session (#20418)
* feat(app): ensure there are healthy app services when creating session

* Apply suggestions from code review

Co-authored-by: Rafał Cieślak <[email protected]>

* chore: code review updates

* refactor(app): preflight connection before creating session

* chore(web): change error message

* reafactor(app): change redirect to launcher rule

* refactor(app): rename preflight connection to health check app server

* refactor(apiserver): rename preflight connection

* refactor(apiserver): rename preflight connection

* refactor(apiserver): remove health check property

* test(appaccess): adjust new http status codes returned

---------

Co-authored-by: Rafał Cieślak <[email protected]>
2023-02-10 10:42:55 +00:00
Gavin Frazar 6d9bb25505 update app access reserved headers (#20741)
* Add x-teleport-api-error to reserved headers
* Update app tests for rewritten headers
* Add test case for x-teleport-api-error
* Fix test for XForwardedSsl since it was effectively untested before
* Refactor leaf test to parse the response from dumper app
* Update docs reference reserved headers
2023-01-27 00:01:02 +00:00
Jakub Nyckowski a611535dce Unbundle TestAppInvalidateAppSessionsOnLogout (#20027)
The "tets bundling" introduced in TesAppAccess() made TestAppInvalidateAppSessionsOnLogout test very unstable as other tests are modifying the state of the whole suit.
Removing the test from the bundle seems to fix it.
2023-01-10 15:44:46 +00:00
Michael 7d78090841 Update webapi/sessions route (#19892) 2023-01-05 12:23:28 -06:00
Gavin Frazar 4330e43cc9 security: Prevent app access authz bypass 2022-12-28 09:24:02 -08:00
Michael Wilson 7d7e574aa4 Eventually require connection failure in TestTCPCertExpiration tests. (#18978)
The TestTCPCertExpiration test may have a race condition where the connection
made to the test application immediately after the cert expiry may succeed.
Due to the wonky nature of using the fake clock in this test, I'm introducing
a requires.Eventually here to hopefully mitigate this race.
2022-12-07 21:49:37 +00:00
Michael Wilson bd0ef3efad Remove CertificateTTL from appaccess integration tests. (#18395)
The CertificateTTL causes problems after the introduction of the fake clock
into the appaccess tests due to the fake clock not being propagated properly
throughout the Teleport stack. Increasing the TTL should make this test much
less flaky.
2022-11-14 20:09:21 +00:00
Michael Wilson 607fefd7c8 Bump TCPCertExpiration test to advance 24 hours. (#18303)
Just to make sure that we're going beyond the cert's TTL, the
TestTCPCertExpiration test now advances 24 hours.
2022-11-09 23:17:20 +00:00
Michael Wilson 85fac93653 Make TestTCP* tests in appaccess more deterministic. (#18233)
The appaccess TestTCP* tests are highly reliant on time. This has been
reduced (but not eliminated) by using a fakeClock and a channel for
signaling monitor triggered connection closures.
2022-11-08 21:40:54 +00:00
Michael Wilson 3d483e2d13 Add in app access connection monitoring. (#17436)
Application access connection monitoring has been introduced so that, when a
lock is created, application access connections will be interrupted until the
lock has been cleared. This includes web sockets and TCP applications.
2022-11-05 02:44:57 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Mike Wilson a4af8ae256 Revert "Ensure audit logging of tsh app login."
This reverts commit 31859e5d30.
2022-10-04 11:14:12 -04:00
Mike Wilson 31859e5d30 Ensure audit logging of tsh app login.
Application sessions were previously only logged when launching an application
session via the UI, and not from the `tsh app login` command. This has been
corrected. The AppName and AppURI are now passed in as part of the gRPC
request to the auth server, which is then used to emit the audit event.
2022-09-30 12:53:13 -04:00
Trent Clarke 948417257f Split out appaccess and proxy integration tests (#16232)
* Proxy tests running

* rollback

* whitespace  fix

* Rollback port fix

* Linter appeasement

* License fix

* Update signals.go
2022-09-08 08:27:51 -06:00