Commit Graph
8 Commits
Author SHA1 Message Date
Zac Bergquist 2519f40d8d Add anonymized device ID to tp.user.login event (#22994)
Updates gravitational/teleport.e#829
2023-03-14 16:06:15 +00:00
Edoardo Spadolini acdf61d931 usagereporter: Use the batched event ingest RPC (#22739)
* Sync prehog/v1alpha/teleport.proto

* Use the new SubmitEvents rpc

* Remove leftover file

* Warn against changing usageReporterMaxBatchSize
2023-03-14 08:58:03 +00:00
Edoardo Spadolini 86fb66ceaa Fix usagereporter tests (#22963)
This fixes a data race in TestUsageReporterErrorReenqueue and a deadlock
in TestUsageReporterTimeSubmit.
2023-03-13 13:23:24 +00:00
Vitor EnesandEdoardo Spadolini 6a1d1aedc3 Emit new AgentMetadataEvent (#22068)
* Emit new `AgentMetadataEvent`

Part of https://github.com/gravitational/cloud/issues/3550.

This commits adds a new `UpstreamInventoryAgentMetadata` that is sent
from a Teleport agent to an auth server.
Once received, it is transformed into an `AgentMetadataEvent` and sent
to PreHog.

Most `UpstreamInventoryAgentMetadata` fields are intentionally kept as
empty in this PR. Follow up PRs will be opened with the mechanisms
required to fill them (as described in #21337).

* server_id -> host_id

* compute OS and host architecture

* Compute OS version and container runtime

* Close stream if agent receives an agent metadata message

* cmd -> exec ; file -> read

* implement fetchOSVersion for linux

* Remove unused import

* Add note about `agentMetadataCh`

* Allow commands with args

* Remove parseFun abstraction

* fetch glibc version

* fetch container orchestrator

* Fix lint

* Fix TODO

* Add note about glibc version

* cmd -> command

* fetch cloud environment

* fetch install methods

* GLibCVersion -> GlibcVersion

* Use `http.NewRequestWithContext`

* Add missing comment

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

* GLibCVersion -> GlibcVersion

* Fix lint

* Fix helm unit tests

* Add missing comments

* 5 second timeout on http requests

* Spawn gorountine that fetches metadata on each new stream

* Use `defaults.HTTPClient()`

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

* Add missing import

* Handle error

* Revert "Spawn gorountine that fetches metadata on each new stream"

This reverts commit fe4f2790be.

* Send agent metadata to auth server once per stream

* Improve note about agentMetadataDone

* Don't process command output & file content on the agent

Since agents cannot be trusted, regex validation and sanitization should
happen in PreHog anyways. So this commit removes such logic in favor of
moving it to PreHog.

* Fix lint

* Trim space

* Move handling of `AgentMetadataEvent` to `handleControlStream`

* Use cached hello message

* Move metadata files to lib/inventory/metadata

* make sending of agent metadata more self contained

* Minimize diff

* Send all system roles to PreHog

* Remove unused import

* Add parsing of command output / file content back

* Usage reporter refactor

* Usage reporter refactor

* Add missing handling of inventory agent metadata msg

* Fix ICS usage reporter

* Improve comments

* Add cached `metadata.Get*` methods

* Use systemctl status instead of is-active

* Add `Metadata` struct

* return pointer in `FetchMetadata`

* Pass context to `GetMetadata`

* metadataFetchConfig -> fetchConfig

* GetMetadata -> Get

* Add note about `Get` result

* Ensure install methods are non-nil

* Exit `metadata.Get` if context is closed

* Replace sync.Once with atomic.Bool.Swap

* Initialize channel

* Fix lint

* Fix lint

* Make `metadata.Get` return an error instead of bool

* Allow multiple true/false values for env vars

* Use `strings.Cut`

* Use /etc/os-release ID instead of NAME

* Improve `autoEmitMetadata`

* Use `gnu_get_libc_version`

* Ubuntu -> ubuntu

* Use GOARCH

* gofmt

* Move import C up

* Variables may include quotes

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

* Default values for ID and VERSION_ID

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

* Blank lines are permitted

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

* Anonymize host id

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-03-10 12:45:29 +00:00
Edoardo Spadolini 8d8c3c94f0 usagereporter: Allow multiple batch submissions in a row (#22711)
* Allow multiple batch submissions in a row

* Test the new behavior

* Rework usagereporter's submission logic

* Fix tests

* Tweak the batch age timer logic

* len(foo) is never supposed to be negative

* Naming
2023-03-08 16:48:04 +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
Grzegorz Zdunek f42e5966bd Send Connect usage events before tshd closes (#20265) 2023-01-25 10:12:37 +00:00
Grzegorz Zdunek ea9530d3ad Make UsageReporter reusable (#19378) 2022-12-30 18:24:44 +01:00