Commit Graph
431 Commits
Author SHA1 Message Date
rosstimothy c2fc9a9375 Add idle connection timeouts to http clients and servers (#22885)
Sets `http.Server.IdleTimeout` and `http.Client.IdleConnTimeout`
on clients and servers which didn't have them set. A default of
360s was chosen to be on par with the default of an NLB without
being identical.

This was added as another safety measure to prevent leaking any
idle connections indefinitely as seen in #22757.

`apidefaults.DefaultDialTimeout` was also renamed to
`apidefaults.DefaultIOTimeout` to better reflect its usage.
2023-03-10 16:47:06 +00:00
Tobiasz Heller 0b3a67f69f Remove GetSessionEvents from external loggers (#22071) (#22703)
Remove GetSessionEvents from external loggers
2023-03-07 15:48:00 +00:00
Tobiasz Heller 770e74a31a refactor: audit interface (#22070)
* refactor: shrinker interface for external audit loggers

* move StreamSessionEvents from ExternalAuditLogger

* fix comment of getLocalLog

* Rename IauditLog into AuditLoggerSessionStreamer
2023-03-06 10:44:16 +00:00
Michael WilsonandMarek Smoliński 1f32bbd7be Update SAML IdP auth attempt code variable name. (#22539)
* Update SAML IdP auth attempt code variable name.

The SAML IdP auth attempt code variable name now accurately mirrors the event
name.

* Update lib/events/codes.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

---------

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2023-03-02 14:18:30 +00:00
Michael Wilson 6973cd6527 SAML IdP audit events. (#22208)
* SAML IdP audit events.

SAML IdP audit events have been added. These events have been added to the UI
for proper rendering. Additionally, service provider events will be emitted
when managing service providers.

* Align the naming more with the existing events.

* Zac's feedback.

* Add in delete all event.

* Fix typo.

* Update story snapshot.

* Linting and test fixes.

* Audit auth failures.

* Removing the nopermissions test, as it's covered in the regular create test.
2023-03-01 20:01:40 +00:00
Edoardo Spadolini 6fd8a233e1 lib/usagereporter refactor and consolidation (#22460)
* services.usagereporter to lib/usagereporter/teleport

* teleterm/daemon/usagereporter to usagereporter/daemon

* usagereporter/daemon type aliases

* Move UsageAnonymizable newtypes in a separate file

* DiscardUsageReporter should be passed by value

* Type renames in usagereporter/teleport

* Move audit event to usage event conversion to lib/usagereporter

* package import renames

* Don't break the e build for now

* move web usage report events to lib/usagereporter

* forgot license blurb

* lib/usagereporter/discover.go to types_discover.go
2023-03-01 18:40:53 +00:00
Edoardo Spadolini e3ce1f83c4 Emit usage events for port, kube.request, sftp (#21740)
* Update prehog/teleport.proto

* Add port as a tp.session.start with kind ssh_port

* Emit tp.kube.request events

* update prehog teleport.proto

* Emit tp.sftp usage event
2023-02-15 09:51:43 +00:00
Edoardo Spadolini f622510dd0 Make UsageSessionStart report TCP app access separately (#21606)
* Make UsageSessionStart more selective and granular for app access

* Allow generic "app" kind for app.session.start

app.session.start is consistently emitted, just not consistently stored

* Avoid singling out aws app access

* Use the same check as app access
2023-02-13 10:13:18 +00:00
Joelandrosstimothy f93d401df2 Update Firestore and held-back dependencies (#21190)
* update dep

* implicit aggregate

* fix kind check

* remove cring address manip

* correct import

* invert if

* fix rename

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-02-10 14:20:15 +00:00
Michelle Bergquist 8dfa07559b capture custom role creation in prehog (#21123)
* add e2e role creation events

* add role name

* reset proto

* cleartext default role names

* constant
2023-02-09 19:23:29 +00:00
Jakub Nyckowski 79ebdc89c8 Bump golangci-lint to v1.51.1 (#21440) 2023-02-08 00:44:08 +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
Tim Buckley 95c5f1c6a8 Add usage events for certificate issuance and additional session types (#20662)
* Add usage events for certificate issuance and additional session types

This adds a new usage event for certificate issuance, emitted
whenever a new user certificate is generated. These events include
an anonymized username, TTL, and basic info about which requests are
present on the certificate (e.g. db/app/k8s requests).

Additionally, this captures additional session event types from the
audit log, including database, app, and desktop sessions, and also
properly tags k8s exec sessions which were previously grouped
together with SSH.

* Add `SessionStartV2` events, add `is_bot` flag to cert events

* Drop redundant `Event` prefix on `UsageCertificteIssued` event

* Rename `CertificateIssuedEvent` -> `UserCertificateIssuedEvent`
2023-02-01 21:29:59 +00:00
Zac Bergquist b590a1556b Disable desktop recording with a discard stream (#20901)
Prior to this, disabling desktop recordings would prevent them from
being uploaded, but AuditWriter would still write them to disk.
As a result, users who weren't recording sesions would still incur
both a performance penalty and unnecessary use of disk space.

Updates #16773
2023-01-31 17:42:16 +00:00
Nic Klaassen 3839483513 feat: add login rule audit event types (#20649)
This commit adds the types necessary in order to add audit events for
login rule resource actions.
The emission of these events will be added in a separate commit to
teleport.e, and the frontend display will be added later (currently
these show up as "Unknown" events).
2023-01-25 10:22:43 -08:00
Edward Dowling e1856cd8cb Add incomplete session upload metric to the teleport namespace (#20351)
Also change name to match prometheus naming practices
2023-01-18 19:43:40 +00:00
Edward Dowling a4f972bbc4 Add metric for incomplete file uploads (#19724) 2023-01-16 16:58:54 +00:00
Lisa Kim 48a5d786ff Add device trust event type conversion (#20163)
* Moved device trust event related code to
  events.proto to solve import cycling
2023-01-13 19:57:53 +00:00
Ulysses ff9065b2b5 Update Teleport capitalization (#11399) 2022-12-30 19:55:39 +00:00
Gavin Frazar 5bb0ef15db add dynamodb database access (#18843)
* Add a new db engine
* Add tests for new engine
* Update tsh db subcommands
* Refactor error message and suggestions for unsupported tsh commands
* Add dynamodb to test plan
* Add AWS external ID to db config and update protos
2022-12-30 18:22:30 +00:00
Grzegorz Zdunek ea9530d3ad Make UsageReporter reusable (#19378) 2022-12-30 18:24:44 +01: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
Steven Martin e1ebc332f8 spell fixes (#19419) 2022-12-16 19:01:28 +00:00
Tim Buckley 86c568a475 Add GetEmitter() to allow proper emitter wrapping for PreHog (#19356)
* Add `GetEmitter()` to allow proper emitter wrapping for PreHog

This is part of a fix for the PreHog usage reporter to resolve a bug
where an improper emitter implementation was wrapped, potentially
replacing a valid set of emitters. A new `GetEmitter` function is
added to `Server` to allow fetching of the correct implementation
so it can be wrapped overwritten sensibly.

Additionally, this changes the signature of `UsageLogger.New()` to
require just an `events.Emitter` interface rather than an `IAuditLog`
specifically.

Finally, this fixes a small bug in the PreHog submitter where failed
events were accidentally dropped too early.

* Add godoc for GetEmitter/SetEmitter

* Add warnings to godoc for SetEmitter and SetUsageReporter
2022-12-14 18:03:44 +00:00
Noah Stride 0433a9d5cb Add InstanceJoin/BotJoin audit events (#19044)
* Introduce NodeJoin/BotJoin events with GH support

* Remove Node -> Instance for clarity

* Add CircleCI join audit attributes

* Tidy implementation

* More tidying of implementation

* Add tests for audit event emission

* Appease linter with AmericaniZed spellings

* Fix imports

* Fix missing errcheck in Join test

* Update token safe name to omit entire token for shorter tokens
2022-12-13 17:04:15 +00:00
fba02d9f9d Add a new usage reporter (#18142)
* [draft] Add a new usage reporter

This adds a new usage reporter service to the auth server. It's
disabled by default in OSS and can only be turned on via startup hook
in Cloud / Enterprise. In OSS, the audit log wrapper is never
configured and any usage events are sent to a no-op discard reporter.

Usage events are defined in prehog and can be sent to the new
UsageReporter Service on the auth server. An audit event wrapper is
used to capture certain events that are otherwise difficult to hook.
Events are anonymized before submission, then held in a non-blocking
queue for batching and submission purposes.

* Remove dead code

* Add SubmitUsageEvent RPC to Auth.

This adds a new SubmitUsageEvent RPC to the Auth API that external
clients (e.g. the UI) can use to submit usage events externally.

* Slight refactor for unit testing

* Add Prometheus metrics and add initial working prehog submitter

* Add more metrics, tweak prehog client, and add unit tests

* Further tweak http transport settings based on Teleport defaults

* Add missing metrics

* Fix goimports

* Add new UI usage events

* Update e ref

* Add prehog directly for now. Improve logging.

* update prehog

* Add new prehog events; use username from request identity

* add HTTP server for user events

* Add username back to pre-onboard events

* unauthenticated user events

* Fix userevent build error

* Use event-provided username where appropriate

* Move barebones prehog reqs to lib/prehog and generate here.

Also, use prod tunable values.

* Fix license lints

* De-flake tests by adding unfortunate amounts of synchronization.

* Add missing license header

* Misc PR cleanup for review

* Update lib/events/usageevents/usageevents.go

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Address a batch of review comments

Adds `anonymizer.AnonymizeString` and parent loggers

* Update e ref

* Clean up comments

* Remove onboard prefix from recovery code event

* Address another batch of feedback

* Use defaults.HTTPClient()

* Remove a noisy log message

* Demote noisy log message to debug

* Temporarily revert e ref for merge

Co-authored-by: Michelle Bergquist <michelle.bergquist@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2022-12-05 17:13:54 +00:00
Zac Bergquist c9e64e1c0e Make the uploader responsible for creating the directories it needs
This removes a bunch of custom code where we manually create uploader
directories in tests because the full uploader service is not running.
2022-12-04 11:50:29 -05:00
Zac Bergquist 2314ebf7e6 uploader: move corrupted uploads to separate directory
This ensures that the uploader won't busy loop over the same corrupted
upload file, while ensuring that the file is still preserved.

Fixes #18936
2022-12-04 11:50:29 -05:00
Zac Bergquist 166dc5a1be Clean up defaults (#18860)
- Make vars const where possible
- Move constants that are only used by the audit log into lib/events
- Remove unused vars
2022-11-30 15:50:29 +00:00
Gavin Frazar c058f7ddb7 add dynamodb database access protos (#18737)
* Add proto for dynamodb db-access requests

* Make grpc for proto update

* Update comment
2022-11-29 17:51:16 +00:00
Vitor Enes 578afd9601 Include upload ID & session ID in failed upload warning logs (#18788)
Having the session ID in these logs should allow users to track down to
which users host the session belongs to.
2022-11-29 16:56:35 +00:00
Vitor Enes c96809399a Add server_hostname to session.* events (#18812)
With this commit, `session.*` events now also contain a `server_hostname` field.

Example:

```json
{
  "argv": null,
  "cgroup_id": 6926,
  "cluster_name": "vitor.teleport.sh",
  "code": "T4000I",
  "ei": 17,
  "event": "session.command",
  "login": "root",
  "namespace": "default",
  "path": "/usr/bin/date",
  "pid": 98679,
  "ppid": 98668,
  "program": "date",
  "return_code": 0,
  "server_hostname": "ip-172-31-10-157",
  "server_id": "8369d1d1-eea5-4074-8f64-0103f1e1fb00",
  "sid": "a40353c4-93dc-4d6b-a481-5546ecafb83e",
  "time": "2022-11-28T16:32:34.342Z",
  "uid": "cbd9e562-8932-405d-974c-11637f91d711",
  "user": "vitor@goteleport.com"
}
```
2022-11-28 20:28:41 +00:00
Zac Bergquist 5e31fbea45 GCS: don't swallow cleanup errors (#18670)
This fixes two issues with the GCS session handler.

1. The "pass through" function wasn't actually passing through anything.
   It always ignores errors from the delete call.
2. Prefer path over filepath here, since we always want paths delimited
   by `/`. This isn't a critical issue now, but would result in all
   sorts of failures if we were to try and run Teleport on systems like
   windows where the filepath separator is not `/`.
2022-11-22 22:49:17 +00:00
Steven Martin 00728c4f63 spell fixes (#18545) 2022-11-17 16:28:05 +00:00
Zac Bergquist da7680ad0b Use x/exp/slices instead of home grown utilities (#18524)
We were inconsistent throughout the codebase and would sometimes
use the slices package and other times use our own equivalents
in api/.

This removes our versions in favor of the golang.org/x package that
does the same, which has the added benefit of reducing the surface
area of the public API module.

Note: despite existing uses of the slices package, for some reason
it didn't show up in go.mod or go.sum. Fixed that too.
2022-11-17 15:25:46 +00:00
Gavin FrazarandTobiasz Heller d9b80fb2a7 Emit new event for DynamoDB requests via app access (#17595)
* protobuf update

* Update proto to use dynamodb request event specific to app-access

We will include a similar event for dynamodb via database-access.
We split the events so that app and database access events are not coupled.
This way we do not have to include optional database/app metadata in one event too.

* Update protos

* Update oneof

* Move AppMetaData up with the other metadata and add a 'target' field

* Remove operation plane

* Fix typo

* Configure signing service with transport instead of http client

* Protect from resource exhaustion attacks

* Add IsDynamoDB to types.Application

* Add new event and code for dynamodb requests

* Add async emitter to app access

* Add audit.go to unify app access auditing

* Refactor auditing in app access

* Use the new audit's onSessionChunk/onRequest methods
* Put the session context in the session chunk
* Use a TeeStreamer to send AppSessionDynamoDBRequest directly to audit log as well as session file
* Change streamWriter to streamCloser in sessionChunk to clarify that it should only be used for closing

* Update handler test to test dynamodb events

* Update test to use streamCloser

* Update sever test

* Add doc strings

* Return error from audit interface methods so callers can choose what do to with it

* Move app session start/end into audit interface

* Configure tcpServer to use the server's emitter instead of auth
  client, as an Audit interface.
* Have tcpServer call onSessionStart/End instead of emitting events
  itself.

* Remove unneeded check type

* Rename Transport -> RoundTripper

* Fix test after renaming field

* Rename drainBody and defer body closing

* Fix subtle named return mistake

* Update lib/service/service.go

Co-authored-by: Tobiasz Heller <14020794+tobiaszheller@users.noreply.github.com>

* Update lib/service/service.go

Co-authored-by: Tobiasz Heller <14020794+tobiaszheller@users.noreply.github.com>

* Rename ok->shouldSkipCleanup to make the purpose of it more clear

* Refactor request body decoding into aws utils

* Use request instead of signed request for audit event

* Determine if req is for a dynamo endpoint instead of checking app uri

* Remove obsolete app func IsDynamoDB

* Update handler test

* Use generic console app uri to test that we differentiate request by endpoint instead of app uri
* Use a dynamodb request which has a body to test that we include the body in the audit event
* Test for expected body JSON

* fix lint

* Fixup merge

Co-authored-by: Tobiasz Heller <14020794+tobiaszheller@users.noreply.github.com>
2022-11-15 22:58:15 +00:00
Isaiah Becker-Mayer 7c83501612 Shared Directory Audit events (#17410) 2022-11-10 19:11:44 +00:00
Jakub NyckowskiandAlan Parra bea2e89df5 Run GCI as make fix-imports (#17956)
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2022-11-04 15:46:46 +00:00
Zac Bergquist 698e377fb4 RFD 91: streaming session playback (#17949)
* Remove reference to GetSessionPlayer, which no longer exists
* Fix up incorrect godoc
* Add RFD 91: streaming session playback
2022-11-02 16:35:16 +00:00
Alan Parra 66fb45ec15 Add DeviceEvent and supporting constants (#17896)
Add DeviceEvent for registered/trusted device audit logs.

gravitational/teleport.e#514
2022-11-01 17:15:24 +00:00
Isaiah Becker-MayerandJoel Wejdenstål d2f5219106 Warn user when desktop is active (#17770)
Co-authored-by: Joel Wejdenstål <jwejdenstal@icloud.com>
2022-10-29 02:12:41 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Marek Smoliński 7aa224e430 Add Cassandra/Scylla database support (#15895) 2022-10-10 12:37:51 +02:00
Edoardo Spadolini 4feb7d1506 Remove azsessions (#17055) 2022-10-07 09:24:30 +00:00
Zac Bergquist e547957f93 Remove [direct] dependency on go.uber.org/atomic (#17035)
Reintroducing the change from #16884 now that Go 1.19.2 has been
released with the fix.

This reverts the revert from  09de0ba530.
2022-10-05 01:24:46 +00:00
Zac Bergquist 09de0ba530 Revert "Remove [direct] dependency on go.uber.org/atomic (#16884)" (#16918)
This reverts commit 4f3aa9a3f2.

We're unable to build for 32-bit Linux due to
https://github.com/golang/go/issues/55152,
which looks like it will be fixed with Go 1.19.2 next week.

We'll re-evaluate with the next Go release and reintroduce this change
as soon as we can.
2022-09-30 22:41:45 +00:00
Zac Bergquist 4f3aa9a3f2 Remove [direct] dependency on go.uber.org/atomic (#16884)
Go 1.19's sync/atomic package provides the same functionality
2022-09-30 20:39:05 +00:00
Alan Parra 5cda242067 Update various Go dependencies (#16861)
Update various "assorted" dependencies, that either are used throughout
(logging, testing), are mostly algorithmic or otherwise difficult to pinpoint
"ownership".

I've dropped a couple of deprecated/mostly meaningless dependencies. I suspect
`github.com/mitchellh/mapstructure` could be dropped to, but I didn't look
further now.

* Drop dependency on Clever/go-utils
* Drop dependency on github.com/pkg/errors
* Update various Go dependencies
* Use CompareAndSwap instead of CAS (uber/atomic)
* Add a comment after replaced dependencies
2022-09-30 14:01:51 +00:00
Zac Bergquist 7f1f8ec098 Remove upload completer grace period (#16809)
The 24-hour grace period was kept in Teleport 10 for backwards
compatibility, but is no longer necessary for Teleport 11 due
to the session tracker system.

As a result, it takes about an hour to complete an abandoned upload
instead of 24 hours.
2022-09-29 13:18:52 +00:00
Nic Klaassen d92cd32037 security: only allow one exec request per SSH channel (#16683) 2022-09-28 20:31:02 +00:00