Commit Graph
476 Commits
Author SHA1 Message Date
Noah Stride acb255cd88 GitLab Delegated Joining (#22705)
* Add type for GitLab ProvisionToken

* Add default behaviour for domain

* Add IDTokenClaims for GitLab

* Add gitlab token source and token validator

* Thread GitLab support through auth and tbot packages

* Adjust cluster name fetching in token validator

* Initialize GitLab token validator in auth

* Improve comment on `sub`

* Working GitLab CI delegated joining

* Add additional token rule fields

* Add checking for new configuration fields

* add additional test cases for validation of gitlab config struct

* Add TestAuth_RegisterUsingToken_GitLab

* Add tests for IDTokenSource

* Fix imports

* Add tests for GitLab Token Validator

* Fix some comments that were incomplete

* Add license headers
2023-03-16 16:19:11 +00:00
rosstimothy b0dc78610e Migrate upserting CAs to gRPC (#23140)
Adds `UpsertCertAuthority` to the `teleport.v1.trust.TrustService`
and deprecates the HTTP api. The `services.Trust` interface was
also updated to include a `context.Context` in both
`CreateCertAuthority` and `UpsertCertAuthority.

To ensure backwards compatibility the `auth.Client` will first
attempt to use the gRPC client and if that fails with a not
implemented error it will fallback to using HTTP.

Part of #6394
2023-03-16 14:46:43 +00:00
Andrew LeFevre de2e55bb69 connect to registered OpenSSH nodes with certs signed by OpenSSH CA (#21953)
To prevent users from being able to directly connect to registered
OpenSSH (Agentless) nodes, the OpenSSH CA was introduced. When
connecting to Agentless nodes, the Proxy will forward the connection
so the session can be recorded. The forwarding SSH server is configured
to authenticate to the target node with a certificate signed by OpenSSH
CA, which users do not have access to.
2023-03-14 16:58:16 +00:00
Brian Joerger 51a511bcaf Headless Login: add headless authentication resource watcher (#22699)
* Add headless authentication resource watcher.

* Handle OpInit event and Watcher errors.
2023-03-13 19:44:25 +00:00
Jeff Pihach 1513294b7b Add CreatedBy and CreatedOn fields to locks. (#22667)
* Add CreatedBy and CreatedOn fields to locks.

* Move the setting of the CreatedBy and CreatedOn for locks to the server instead of the client.

* Add tests for the tctl resource lock import and for the tctl lock create command.

* Use clockwork for time in lock creation tests.

* Make fake clock optional and use the golang 0 date.

* Change CreatedOn to CreatedAt.

* Allow a custom time to be passed through as a fake clock.

* Actually accept a fake clock with useFakeClock.

* Pass Clock through as a configuration value when initializing Teleport for the tests.

* Test cleanup

* Set CreatedBy and CreatedAt values in test mocks.

* Fix failing test from enabling clock passthrough to auth.
2023-03-13 16:14:24 +00:00
matheus b0fb10ae4e Hide download center when not on dashboards and prevent license gRPC endpoint from being called (#22965)
* Hide download center when not on dashboards

* Prevent getLicense gRPC call on cloud
2023-03-13 16:03:23 +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
Michael Wilson 49c64aabcb Move the authorizer into its own package. (#22776)
* Move the authorizer into its own package.

The Authorizer and associated functions and constants have been moved into
their own package `authz`. This will allow us to more easily create separate
services for gRPC functionality so that we're not pushing as much into the
`lib/auth` package.

Though this PR is large, the only actual code change here is making
`ContextForLocalUser` exported and changing the `permissions_test.go` so that
it doesn't rely on the `lib/auth` package.

* Use context functions.

* Test and linting fixes.

* Add in a temporary alias file to ensure e still compiles.

* Use functions instead of var aliases for performance reasons.

* Adding in godocs, cleaning up tests.

* Fix tests.

* Add a few more aliases.
2023-03-09 02:21:10 +00:00
Anton Miniailo 8f3b2b181b Enabled IP pinning enforcement for Kube and DB (#22310) 2023-03-08 14:20:47 +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
Andrey Bulgakov d7fb53d08c Refresh remote cluster connection status periodically (#22455) 2023-03-02 23:00:41 +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
Michael Wilsonandrosstimothy d530f33b5c Create a generic local backend service. (#21078)
* Create a generic local backend service.

Many of the local backend services have a very similar pattern in terms of how
objects are retrieved and stored. This PR introduces a generic backend which
implements backend retrieval and storage of objects and migrates the SAML
IdP service provider service to it. More services could easily be migrated
to this generic service implementation.

* Feedback, add in generic tests.

* Tim's feedback, added in a test for updating a resource that doesn't exist.

* Tim's feedback.

* Apply suggestions from code review

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

* Edoardo's feedback.

* Added in UpdateAndSwap.

* Edoardo's feedback, Tim's feedback.

* Use a default page size if the page limit is not specified.

* More of Edoardo's feedback.

* Propagate error instead of panic.

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-02-24 15:59:16 +00:00
Michael Wilson 9527b6518c User group API and cache. (#21956)
The user group has been added to the API and to the cache.
2023-02-22 18:45:11 +00:00
Noah StrideandAlan Parra f3ba5750a8 Make tctl nodes add / tctl tokens add use CreateToken RPC (#21189)
* Start removing generateToken

* Refactor `tokens add` to use `CreateToken` RPC

* Correct deprecation version

* Remove calls to GenerateToken

* Start tests for token crud

* Allow user role rules to be provided wth CreateUserAndRole helper

* Add TestCreateToken to tls_test

* Add TestUpsertToken

* Add GetTokens test

* Add TestGetToken

* Add test for DeleteToken RPC

* Dedupe error assertions

* Add support for emitting trusted cluster token creation events to Create/UpsertToken

* Fix imports

* Change parameter order to appease linter

* Fix broken token expiry test

* Fix token expiry time for TestAuth_RegisterUsingToken

* Remove unnecessary cleanup

* Apply suggestions from code review

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

* Change test comment from deprecation notice

* `make gprc` after code review changes

* Update lib/auth/tls_test.go

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

* Update lib/auth/tls_test.go

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

* Update lib/auth/tls_test.go

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

* Update lib/auth/tls_test.go

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

* Rename tests

* Update lib/auth/tls_test.go

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

* More test cases for GetTokens

* Improve message on duplicate token

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-02-16 09:36:55 +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
Alan Parra 8c84d0a766 Add device lock support (#21667)
* Add Device to LocketTarget proto

* Refactor LockTarget.Match

* Test lib/srv.ComputeLockTargets

* Test lib/services.LockTargetsFromTLSIdentity

* Test device lock during cert issuance

* Add device lock targets where applicable

* Add --device to `tctl lock`

* Fix godocs (unrelated)

* Review: Drop redundant comments
2023-02-13 14:46:11 +00:00
Noah Stride 0181993047 Allow the creation and usage of expiryless ProvisionTokens (#21133)
* Allow the creation and usage of expiryless tokens

* Tidy up loose ends

* Fix imports

* Add tests for changes to expiryless behaviour

* Use new RPCs for new expiryless behaviour

* Add tests for new RPCs

* Remove unused import

* Recreate behaviour for tokens expiring in past

* Missing NoError check int ests

* Correctly americanize behavior
2023-02-10 13:45:36 +00:00
Alan Parra 3e96d0b540 Compare TLS and SSH principals independent of order (#21560)
* Reproduce principal mismatch bug

* Compare TLS and SSH principals independent of order

* Review: Rename filterAndSortPrincipals, more accurate test examples
2023-02-09 20:26:37 +00:00
Forrest b206fe4288 cache license warning load in ping (#21502) 2023-02-08 22:31:30 +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
STeve (Xin) Huang 704a514742 AWS IAM role matching for database users (#20610)
* Add database user matching logic for databases require AWS IAM role

* Fix UT

* fix lint/typo

* fix typo in error message

* reduce bool return
2023-02-03 18:33:56 +00:00
42cb80c3e4 Adding in a new SAML IdP certificate authority. (#21159)
* Adding in a new SAML IdP certificate authority.

A new SAML IdP certificate authority has been added. It has been added to
initialization, the cache, and the certificate can be rotated.

* Update lib/services/authority.go

Co-authored-by: Sam Freiberg <sfreiberg@goteleport.com>

* Update api/types/trust.go

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

* Only validate private key if it's present.

---------

Co-authored-by: Sam Freiberg <sfreiberg@goteleport.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-02-03 15:56:56 +00:00
Michael Wilsonandrosstimothy 7d40f37cb1 SAML IdP service provider APIs (#20992)
* SAML IdP service provider APIs

The SAML IdP service provider's associated APIs have been implemented. This
will support the use of Teleport as a SAML IdP by allowing Teleport users to
add service providers through the API.

* Correct permissions.

* Update lib/auth/grpcserver_test.go

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

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-02-03 14:09:33 +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
Nic Klaassen e89b9b8893 feat: add login rule evaluator to auth.Server (#20514)
This enables the enterprise plugin to install the real login rule
evaluator implementation during enterprise process startup.
2023-01-24 18:48:55 +00:00
Brian Joerger ccff88c282 Fix key attestation error on tsh login (#20314) 2023-01-24 17:57:55 +00:00
Alan Parra 11d58e25c7 Refactor AccessMFAParams and MFAParams to allow additional data (#20300)
Refactor `services.AccessMFAParams` and the accompanying `MFAParams` methods so
they may be extended to carry additional data (eg, information required to
perform device trust checks).

This PR refactors existing code without adding any new functionality, so it may
be backported to older branches to alleviate eventual conflicts. Follow up
changes will take advantage of it to add support for device trust.

Related to gravitational/teleport.e#514.
2023-01-17 20:02:38 +00:00
Andrew LeFevre e71f024a9f Add OpenSSH CA (#20020)
* WIP adding OpenSSH CA

* fix creating OpenSSH CA for tests

* fix a test name and tctl usage flag

* fix 'tctl status' not displaying openssh CA sometimes

* add OpenSSH CA to TestInit_bootstrap, remove TLS key pair

* add OpenSSH CA to a few more places

* make help text of 'tctl auth rotate' more helpful and accurate

* fix web cert export test

* tbot doesn't need to know about OpenSSH CA

* address feedback

* fix comment formatting
2023-01-13 18:23:19 +00:00
Alan Parra ba1282df62 Improve UserMetadata audit logging (#20081)
Improve UserMetadata audit logging by using `tlsca.Identity.GetUserMetadata()`
more consistently in audit logs.

There are still a handful of logs that don't include the data above for lack of
context (in the general sense and in the Go context sense), but many more
entries now call back to identity in some way.

Related to gravitational/teleport.e#514.
2023-01-11 21:03:17 +00:00
Krzysztof Skrzętnicki 0490ecd94e GCP CLI support: auth changes (#19788) 2023-01-11 14:21:02 +00:00
matheusandMichelle Bergquist 78a83b0b64 Add ListReleases and GetLicense endpoints (#19565)
* Add GetReleases and GetLicense methods

Co-authored-by: Michelle Bergquist <11967646+michellescripts@users.noreply.github.com>
2023-01-03 12:52:22 +00:00
Forrest Marshall ecef3465b6 instance heartbeats 2022-12-30 12:09:11 -08: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
Anton Miniailo cd595c5d37 security: Prevent IP pinning bypass 2022-12-28 09:24:02 -08:00
Vitor Enes 87f706d0ec Track active migrations in Prometheus and tctl top (#19520)
This commit adds a new Prometheus gauge `teleport_migrations` that
tracks for each migration if it is active (1) or not (0).

This gauge is then leveraged in `tctl top` to show a set of active
migrations.
2022-12-22 19:37:44 +00:00
Alan Parra ecf9e5c7d1 Enforce device extensions for SSH access (#19574)
Add device-aware authorization for SSH access, including both long-lived and
single-use certificates.

If the device trust mode is set to "required", then the presence of the
corresponding extensions is enforced. (Requires Teleport Enterprise.)

Adds logic related to TLS validation and single-use certificates as well, where
appropriate. TLS device-aware validation is not wired into Teleport yet, but
will be in follow up PRs.

gravitational/teleport.e#514
2022-12-21 22:54:13 +00:00
Krzysztof Skrzętnicki f8fa2b9be2 Bump gravitational/trace package version (#19390) 2022-12-21 22:02:25 +00:00
Marco André Dinis 69dc237fe2 DatabaseService resource: client and server CRUD (#19469)
* DatabaseService resource: client and server CRUD

In the context of Teleport Discover, we must be able to known if there's
any DatabaseService available to proxy a given Database resource.
If there's none available, we will offer a script for the user to run
and install a DatabaseService which proxies the desired Database
resource.

By DatabaseService, we mean the process that Teleport binary manages
when the `teleport.yaml` config has the following section:
```yaml
db_service:
  enabled: "yes"
```

To accomplish this we are creating a new resource: DatabaseService.
The UI will fetch all DatabaseServices and check if there's any
ResourceMatcher that matches the DatabaseLabels.

A previous PR created the DatabaseService resource.

This PR creates all the necessary CRUD operations:
- Add Service to manage DatabaseServices resources in the backend.
- Add GetAll, Upsert, Delete and DeleteAll operations to Client.
- Add DatabaseService support to ListResources.
- Add WebAPI endpoint to list DatabaseServices using ListResources.

The next PR will add the heartbeat mechanism to the DatabaseService
process.
2022-12-21 14:34:36 +01:00
Alan Parra 53e2d6cd0b Allow issuance of device-aware certificates (#19351)
Allow issuance of augmented, device-aware user certificates via auth.Server.

Device-aware certificate issuance takes as input existing user certificates and
augments them with the appropriate device extensions. The certificates to
augment must be valid, issued by the Teleport CA, match each other and the
current user, and share the same public key, among other criteria.

Device authentication is performed by Teleport Enterprise. The present PR adds
only the means to issue the certificates, but doesn't wire that functionality
to any endpoints.

gravitational/teleport.e#514
2022-12-15 20:13:59 +00:00
Russell Jones 7895fddc57 Added the ability to supply Access Request TTLs
Added the ability to specify two CLI flags for Access Requests:
"--request-ttl" and "--session-ttl".

Updated "CreateAccessRequest" to adhere to the following rules.

If an Access Request does not have a TTL set (expiration time
types.AccessRequest resource itself), a default of 1 hour is used. Next,
the request value is truncated by the lifetime of the certificate,
requested expiration, and then strictest session TTL on all roles
requested.

Similar logic is followed for the expiration time of the elevated
certificate that will be issued if the Access Request is approved. First
the requested value is truncated by the lifetime of the certificate,
requested expiration, and then strictest session TTL on all roles
requested.

The output of "tsh requests ls" and "tctl requests ls" has been updated
to display the TTL values.
2022-12-14 15:18:33 -08: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
Marco André Dinis 6fd0fa8ef3 Connection Diagnostics: Postgres Database tester (#18558)
* Connection Diagnostics: Postgres Database tester

When adding a new resource using the Web UI we want to allow users to
test connecting to it.

We have two connection testers already:
- for SSH Nodes
- for Kube clusters

This PR adds a third tester: Postgres Database.

Most of the required changes for any Database are already present but
we're focusing on Postgres for now. Other databases will be added as
future PRs.

Testing a Database is similar to the other tests:
- generate certs for the logged in user
- connect to the resource using those certs

When generating the certificate, we inject an ID so that the Database
Service can add Connection Diagnostic traces.
2022-12-13 18:55:40 +01:00
Krzysztof Skrzętnicki dd67a49ab5 Azure CLI access (#18675) 2022-12-12 19:34:53 +00:00
Isaiah Becker-Mayer fc33246807 Fixes dissonance between disconnect_expired_cert vs require_session_mfa (#18607) 2022-12-07 17:00:38 +00:00
Cam Hutchison 7b4c99b491 auth: Remove the OIDC connector login logic (#18999)
Remove the OIDC connector login logic which has now been moved to the
enterprise repository.
2022-12-06 15:51:03 +11: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
Hugo Shaka f0dd7d7d85 Kubernetes joinMethod (#18659)
This commit adds a new joinMethod as described in https://github.com/gravitational/teleport/pull/17905

This method allow pods running in the same Kubernetes cluster than the auth servers to join the Teleport cluster. It relies on Kubernetes tokens to establish trust. The goal is to be able to deploy proxies and auths separately and join them in a single cluser.

Pre Kubernetes 1.20, the tokens are static, long-lived, not bound to pods. We support them for compatibility reasons. Starting with Kubernetes 1.20, tokens are bound to pods (and starting with 1.21 they can be mounted through projected volumes). Starting with 1.21 we should only accept bound tokens. The chart will ensure tokens are properly mounted with projected volumes so we can benefit from the 1h to 10min token lifetime.
2022-12-02 20:30:52 +00:00
Cam Hutchison 616f6ea56a auth: Refactor the OIDC connector prior to moving out (#18892)
Refactor the OIDC connector to its own type so it is simpler to move out
of the `auth.Server` struct. This follows the same pattern as was done
with the SAML connector - a new struct that the OIDC request methods are
attached to, plugged into the `auth.Server`.

Move some small amount of code around so when it comes to removing it
later, it is largely confined to the oidc files and large contiguous
blocks - makes it slightly simpler to review.

Make `ValidateACRValues` a pure function as it did not use anything from
the struct it was a method on, and move the test for it into
`oidc_test.go`.

Move `isHTTPS()` from `auth.go` to `oidc.go` as it is only used there
and will later move out.

Export `validateOIDCAuthCallbackReq` and `oidcAuthRawResponse` and move
them to `oidc.go` so the web handler can also be moved to enterprise.
2022-12-01 22:36:03 +00:00