119 Commits
Author SHA1 Message Date
nixpigandNibras Ohin 1f1abdcbe2 Allow GitHub login for users whose roles come exclusively from access lists (#63829)
* Allow GitHub login for users whose roles come exclusively from access lists

* Update component test expectation

* chore: update design system to v0.2.0 (#68515)

* Add suggested nit changes

---------

Co-authored-by: Nibras Ohin <nibrasul.ohin@goteleport.com>
2026-07-27 14:51:41 +00:00
Dan Upton 1e7abe0873 Support username in role templates and expressions (#64888)
Adds a new variable `user.metadata.name` that can be used in role templates:

```yaml
allow:
  node_labels:
    owner: '{{user.metadata.name}}'
```

Or in expressions:

```yaml
allow:
  node_labels_expression: |
    labels["owner"] == user.metadata.name
```

So that you can create roles that allow access to user-owned resources such as
"Connect My Computer" nodes, or the upcoming Beams feature.
2026-04-15 16:29:41 +00:00
rosstimothy 02a1b0b537 Inject modules into the auth server (#62858)
Contributes to https://github.com/gravitational/teleport/issues/62799.
2026-04-09 20:54:27 +00:00
rosstimothy a1b789b89d Scopes: Pin SSO logins via tsh login (#61576)
Enables pinning SSO users to a scope when authenticating
via the command line. The plumbing for pinning SSO logins
via the WebUI was added as well, but is explicitly rejected
with an error for now.
2025-12-12 23:19:18 +00:00
Edoardo Spadolini cd0a0b330c Add support for using the relay in tsh and Machine ID (#59095)
* Support relay transport in the proxy client

* Support generating client options at login time

* Support storing, overriding and using the relay in tsh

* Set the default relay address based on a trait

* Display relay info from the profile in tsh status

* Add relay support to tbot ssh multiplexer

* use relay_server like proxy_server

* Make the trait name similar to other internal traits

* Simplify default status, add info in debug

* Only show relay address in status if set
2025-09-17 10:14:04 +00:00
rosstimothy c29eca5a4a Refactor auth test helpers (#56491)
* Move auth test helpers to authtest package

In an effort to remove testing symbols from the teleport binary
the auth helpers in lib/auth/helpers.go are being moved to a new
lib/auth/authtest package. This package is to be limited to only
being imported within _test.go files to prevent the helpers from
slipping back into production code.

* Convert lib/auth tests to use lib/auth/authtest

All tests within lib/auth that made use of the test helpers in
lib/auth/helpers.go now use the equivalent functionality provided
by lib/auth/authtest. To prevent import cycles the tests in lib/auth
have been moved to the auth_test package. This shift required some
extra work as a fair number of the existing tests relied on unexported
symbols. To work around this lib/auth/export_test.go has been added
for the sole purpose of exporting private types, methods, or extending
existing types with new exported received methods. This was chosen
over rewriting existing tests for time and simplicity. All future
tests should not rely on this hack and should instead stick to
testing the publicly exported items from the auth package.

* fix: allow specifying accepted usage in cert requests

* fix: restore test assertions in TestGenerateKubernetesUserCert

* fix: set remote cluster variables

* fix: restore test assertions in TestGenerateUserCertWithHardwareKeySupport

* fix: context passing to user cert generation

* fix: github connector API

* fix: pull renewable field from outer identity

* rename authtest.TestDevice authtest.Device

* fix: typos

* add clean up TODOs

* Refactor authtest helpers

* fix: convert additions to bound keypair tests

* fix: add plugin service to authtest helpers
2025-07-21 17:32:26 +00:00
Brian Joerger 57ed41be2e Remove unused function. (#56652) 2025-07-10 16:18:55 +00:00
Brian Joergerandrosstimothy 88473c4583 Validate that the "/web/sso_confirm" redirect URL is only used for MFA ceremonies (#56006)
* * Move ValidateClientRedirect from lib/auth/github.go to lib/client/sso/redirector.go

* Replace binary ssoTestFlow boolean with ceremony type to incorporate MFA ceremonies

* Validate that "/web/sso_confirm" is only used for MFA ceremonies

* Address comments.

* Add warning comment; Update error message.

* Update/Add tests.

* Require channel_id as exclusive query parameter for sso mfa web redirect.

* Update lib/client/sso/redirector.go

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

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2025-07-01 22:37:31 +00:00
Zac Bergquist ff374ff7fd Modernize lib/auth and lib/utils (#55976) 2025-06-22 10:53:52 +00:00
Brian Joerger 4e940685b5 * Enforce /web/sso_confirm path can only be used as a relative path for proxy redirect. (#55398)
* Ensure /web/sso_confirm is used as a relative redirect URL during callback.
2025-06-05 14:00:17 +00:00
Nic Klaassen 0336ebb3dd [chore] clean up DELETE IN 18 comments (#55118)
* [chore] clean up DELETE IN 18 comments

* remove remaining single key refs

* fix github_test
2025-05-24 17:30:24 +00:00
Brian Joerger 58f71101d8 feat: Hardware Key Agent - Add api/utils/keys/hardwarekey package (#53671)
* Move hardware key files into new hardwarekey package.

* Tidy up PIVSlot logic and remove its piv-go dependency.

* Add godoc comments to cliPrompt methods; Update cliprompt.go license year.

* Add godocs.
2025-04-07 19:31:11 +00:00
Noah StrideandMarco Dinis 0586278cde Migrate GetClusterName to gRPC (#53164)
* Adjust GetClusterName method signature to include context.Context

* Start hacking on gRPC GetClusterName impl

* Fix test mocks to match signature

* Fix integration tests

* Fix integrations tests

* Missing ctx

* New GetClusterName RPC implementatin

* Add fallback cluster name

* Correct godoc comment

* Remove unused method

* Remove unused import

* Fix E2E test

* Fix tests

* Fix deferred context cancel in test conflicting with parallel subtests

* Fix import

* Fix imports

* Update lib/auth/auth_with_roles.go

Co-authored-by: Marco Dinis <marco.dinis@goteleport.com>

---------

Co-authored-by: Marco Dinis <marco.dinis@goteleport.com>
2025-03-20 10:07:02 +00:00
rosstimothy 2cced62805 Fix violations of non-constant format strings linter (#51812)
Depends on https://github.com/gravitational/teleport.e/pull/6006.
Now that we are compliant, the ignore rule was removed from the
golangci-lint config to prevent future regressions.
2025-02-04 16:43:35 +00:00
rosstimothy ec2718b810 Convert lib/auth to use slog (#50577)
* Convert auth_with_roles to use slog

* allow benchmark tests to log

* remove last use of logrus in github.go

* remove last use of logrus in rotate.go

* remove auth package logrus logger

* convert auth.go to exclusively use slog

* convert db.go to exclusively use slog

* convert methods.go to exclusively use slog

* convert password.go to exclusively use slog

* convert join_ec2.go to exclusively use slog

* convert join_iam.go to exclusively use slog

* convert kube.go to exclusively use slog

* convert oidc.go to exclusively use slog

* convert saml.go to exclusively use slog

* convert sso_diag_context.go to exclusively use slog

* convert transport_credentials.go to exclusively use slog

* convert trustedcluster.go to exclusively use slog

* convert usertoken.go to exclusively use slog

* convert user.go to exclusively use slog

* remove logrus import

* fix: pass in context

* fix: remove new use of package logrus logger
2025-01-06 21:31:53 +00:00
rosstimothy 3cd1d08979 Convert lib/auth/github to use slog (#50519) 2024-12-21 02:07:45 +00:00
STeve (Xin) Huang 80a58fc82c GitHub proxy part 5: OAuth flow to retrieve GitHub identity (#49849)
* GitHub proxy part 5: OAuth flow to retrieve GitHub identity

* review comments round1

* review comments round 2 and update tsh git list

* make -C integrations/operator crd

* make -C integrations/terraform docs

* fix flaky test
2024-12-10 17:31:32 +00:00
rosstimothy 3db72b06b5 Convert github auth code to use x/oauth2 (#48598)
Replaces the dependency on go-oidc/oauth2 with x/oauth2 in the
github connector auth flows. One result of the switch is that it
permitted a lot of simplification - the github client cache used
by the auth server was removed entirely.
2024-11-18 14:49:30 +00:00
Brian Joerger 313acfa181 feat: SSO MFA - WebUI backend implementation (#47832)
* Add SSO MFA ceremony support to WebUI per-session MFA.

* Add display name to SSO MFA device; Add SSO MFA device to SSO challenge.

* Camel case json tags for front end.

* Add sso channel ID for front end broadcast channel logic.

* Fix backwards compatiblity issue; fix error message.

* Fix test.

* Fallback to connector id if display name isn't set.

* Fix test.

* Resolve comment.

* Use uuid.NewRandom.

* go mod tidy
2024-11-06 01:43:41 +00:00
Nic KlaassenandBartosz Leper acc08a3faa support split SSH/TLS keys in SSO login endpoints (#45876)
* proto

* api/types

* split ssh/tls keys for sso login

* fix sso testers

* fix typo in comment

Co-authored-by: Bartosz Leper <bartosz.leper@goteleport.com>

* improve test coverage of github auth APIs

* test proxy login APIs

* lint fix

---------

Co-authored-by: Bartosz Leper <bartosz.leper@goteleport.com>
2024-09-04 19:07:57 +00:00
Alan Parra dfbbba60ff chore: Bump golangci-lint to v1.60.1 (#45469)
* chore: Bump golangci-lint to v1.60.1

* Fix new golangci-lint offenders

* Fix api/ lint offenders
2024-08-14 14:46:57 +00:00
Andrew LeFevreandAndrew LeFevre bca2943dca add option to allow client redirects from IPs in specified CIDR ranges in SSO client logins (#44556)
Co-authored-by: Andrew LeFevre <Andrew LeFevre>
2024-07-30 21:02:57 +00:00
Alan Parra 14dccc6c4a fix: Issue DeviceWebToken during Github authn (#44656)
* Move trusted device mode calculation into CreateWebSessionFromReq

* Add the GithubAuthRequest.ClientUserAgent field

* Update generated protos

* Issue DeviceWebToken during Github authn

* Issue DeviceWebToken as part of CreateWebSessionFromReq

* nit: Move methods to sessions.go
2024-07-29 22:16:53 +00:00
Edoardo Spadolini 5087b0fb75 Clean up after client redirect fix (#43487) 2024-06-25 16:28:58 +00:00
Edoardo Spadolini e4ec728d4a Validate client redirects in SSO client logins (#41833) 2024-05-21 18:45:43 +00:00
rosstimothy 7fe7a6b2a0 Replace dependencies on lib/auth with lib/authclient (#41623)
* Remove authclient.Client/ClientI/NewClient aliases in lib/auth

* Remove WebSessionReq aliases in lib/auth

* Remove GithubAuthResponse aliases in lib/auth

* Remove GithubAuthRequest aliases in lib/auth

* Remove KubeCSR alias in lib/auth

* Remove KubeCSRResponse alias in lib/auth

* Remove OIDCAuthResponse alias in lib/auth

* Remove OIDCAuthRequest alias in lib/auth

* Remove ValidateOIDCAuthCallbackReq alias in lib/auth

* Remove OIDCAuthRawResponse alias in lib/auth

* Remove CreateUserTokenRequest alias in lib/auth

* Remove SAMLAuthResponse alias in lib/auth

* Remove SAMLAuthRequest alias in lib/auth

* Remove ValidateSAMLResponseReq alias in lib/auth

* Remove SAMLAuthRawResponse alias in lib/auth

* Remove ValidateTrustedClusterRequest alias in lib/auth

* Remove ValidateTrustedClusterRequestRaw alias in lib/auth

* Remove ValidateTrustedClusterResponse alias in lib/auth

* Remove ValidateTrustedClusterResponseRaw alias in lib/auth

* Remove AuthenticateUserRequest alias in lib/auth

* Remove ForwardedClientMetadata alias in lib/auth

* Remove PassCreds alias in lib/auth

* Remove OTPCreds alias in lib/auth

* Remove SessionCreds alias in lib/auth

* Remove AuthenticateSSHRequest alias in lib/auth

* Remove SSHLoginResponse alias in lib/auth

* Remove TrustedCerts alias in lib/auth

* Remove AuthoritiesToTrustedCerts alias in lib/auth

* Move auth.HostFQDN to authclient

* Move auth.WithClusterCAs, auth.DefaultClientCertPool and auth.ClientCertPool to authclient

* Switch alpn proxy to use authclient.CAGetter instead of auth.ReadProxyAccessPoint

* Use a smaller scoped interfaces in lib/proxy/peer to remove lib/auth dependency

* Move auth.TryCreateAppSessionForClientCertV15 to authclient

* Move auth.ErrNoMFADevices to authclient

* Move access point interfaces to authclient. Aliases left behind to prevent breaking builds

* remove lib/auth dependency from lib/reversetunnelclient

* fix lints

* fix license

* Bump e ref to include gravitational/teleport.e#4174

* Use authclient.Client in new tctl diag commands

* Stop using auth.UserTokenType aliases
2024-05-16 17:34:58 +00:00
rosstimothy e95f3d3ed5 Start using authclient.Client/ClientI/NewClient (#41539)
Consumes the new auth client created in #41460. The changes introduced
were performed with a series of gofmt rewrite rules.

```bash
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "ClientI -> authclient.ClientI" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "Client -> authclient.Client" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "NewClient -> authclient.NewClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.ClientI -> authclient.ClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.Client -> authclient.Client" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.NewClient -> authclient.NewClient" {} \;
```
2024-05-15 14:09:14 +00:00
rosstimothy 67f499a457 Refactor auth client code into lib/auth/authclient (#41460)
This starts separating the lib/auth client and server code into
distinct packages to reduce the dependency tree of client tools.
For the time being aliases were left to all things moved into
lib/auth/authclient to reduce the changeset and ensure code still
compiles. Future changes will be built off this to convert code
to use lib/auth/authclient where applicable, this was intentionally
left to a minimum amount of changes to facilitate backports.
2024-05-14 13:28:06 +00:00
Zac Bergquist 63afd5f277 Clean up some TODOs (#40001)
There were some playback APIs that I was hoping could be deprecated
for v16, but it turns out they are still used by Teleport Assist.
2024-04-07 23:34:58 +00:00
Steven MartinandZac Bergquist 274a0b2db5 Update GitHub update event code (#40110)
* Update GitHub update event code

* Handles prev github update event code in web ui

* reverts code to original github update version and handles in web ui

* ui test fix

* add comment on event code

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

* Update GitHub Auth connector event descriptions to use camelcase

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2024-04-02 15:00:10 +00:00
Edoardo Spadolini 86f2491cba Add hooks for SSO auth requests for future enterprise use (#40016) 2024-03-29 14:36:15 +00:00
Brian Joerger bbf447fe0d Move NewWebSessionRequest to lib/auth; add TODO. (#39741) 2024-03-28 23:59:45 +00:00
rosstimothy 1aec5414f1 Replace constants from trace with equivalents defined in teleport (#39307)
* Remove logging from circuit breaker

The logging is never output, and if it was would be very verbose.
Instead of dropping the level down to trace the logger is removed
entirely.

* Add constants from trace library

The logging functionality in trace is being removed in an upcoming
release. To prepare the logging component keys are copied from trace
into teleport.

* Convert trace.ComponentFields to teleport.ComponentFields

* Replace trace.Component with teleport.ComponentKey

* Replace trace logging constants
2024-03-14 13:04:29 +00:00
Marco André Dinis dc6cd0d9be Move TokenLenBytes to defaults package (#37254)
Some consts in the `auth` package are used in a lot of other packages.
This increases the probality of getting a cyclic dependency error.

This PR moves some of those consts to the defaults package and updates
all the required locations of their usage.

Only one is missing in the `/e/` repo, which I'm going to open a PR for
it.
After merging, we can also remove the `lib/auth.TokenLenBytes`
2024-01-25 18:30:43 +00:00
Gabriel Corado e6f61abc9e Add client remote address to some audit events (#36354)
* feat: add client addr to administrative events

* test(auth): update assert
2024-01-10 13:22:08 +00:00
fheinecke b178b8b732 Updated Teleport codebase to AGPL3 license (#35259)
Signed-off-by: Fred Heinecke <fred.heinecke@goteleport.com>
2023-12-01 17:48:14 +00:00
rosstimothy b2bc325703 Implement and use UpsertGithubConnectorV2 (#35132)
While the api client already had support for the new upsert method
it was unimplemented server side and would always fallback to the
legeacy UpsertGithubConnector RPC. This implements the RPC handler
and updates the signature of UpsertGithubConnector to return the
upserted connector in the same manner that Create and Update do.
2023-11-30 15:01:40 +00:00
rosstimothy 04b1598c91 Emit new update events when resources are updated (#33753)
Auth connectors, users, and roles have all recently had their APIs
extended to support create and update but were still only emitting
create events. This adds new update events and update metadata
and emits them instead of the create events.
2023-10-27 14:21:09 +00:00
rosstimothy f59a488155 Enable optimistic locking support for GitHub connectors (#33421)
Updates tctl edit and the web ui to start using optimistic locking.
The functionality to support optimistic locking already existed, the
APIs used by both clients were updated to use create/update instead
of upsert so that optimistic locking could be enforced. Most of the
changes introduced are tests to ensure that tctl edit, tctl create
and the web ui behave as expected.

Contributes to #30416.
2023-10-17 15:24:04 +00:00
Brian Joerger 3d83d51e5f Add web session attestation for IDP web login. (#33433) 2023-10-16 19:30:50 +00:00
rosstimothy 8905ec1d1f Implement Create/Update for auth connectors (#33181)
Updates services.UserService and auth.ClientI to contain the
Create and Update methods for all auth connectors and implements
them at the client, server, and services layer. Upsert was untouched
to prevent breaking e and will be addressed in a follow up PR.

Contributes to #30416.
2023-10-13 19:32:51 +00:00
rosstimothy b60ea81d54 Update users interface (#32987)
services.UsersService now takes a context and returns the user
from write operations as shown in the diff below. The bulk of the
changes are from modifying code to account for the additional
parameter and/or return value. Functional changes to better make
use of the new API will come in follow up PRs.

```diff
// UserGetter is responsible for getting users
type UserGetter interface {
	// GetUser returns a user by name
-	GetUser(user string, withSecrets bool) (types.User, error)
+	GetUser(ctx context.Context, user string, withSecrets bool) (types.User, error)
}

// UsersService is responsible for basic user management
type UsersService interface {
	UserGetter
	// CreateUser creates user, only if the user entry does not exist
-	CreateUser(user types.User) error
+	CreateUser(ctx context.Context, user types.User) (types.User, error)
	// UpdateUser updates an existing user.
-	UpdateUser(ctx context.Context, user types.User) error
+	UpdateUser(ctx context.Context, user types.User) (types.User, error)
	// UpdateAndSwapUser reads an existing user, runs `fn` against it and writes
	// the result to storage. Return `false` from `fn` to avoid storage changes.
	// Roughly equivalent to [GetUser] followed by [CompareAndSwapUser].
	// Returns the storage user.
	UpdateAndSwapUser(ctx context.Context, user string, withSecrets bool, fn func(types.User) (changed bool, err error)) (types.User, error)
	// UpsertUser updates parameters about user
-	UpsertUser(user types.User) error
+	UpsertUser(ctx context.Context, user types.User) (types.User, error)
	// CompareAndSwapUser updates an existing user, but fails if the user does
	// not match an expected backend value.
	CompareAndSwapUser(ctx context.Context, new, existing types.User) error
	// DeleteUser deletes a user with all the keys from the backend
	DeleteUser(ctx context.Context, user string) error
	// GetUsers returns a list of users registered with the local auth server
-	GetUsers(withSecrets bool) ([]types.User, error)
+	GetUsers(ctx context.Context, withSecrets bool) ([]types.User, error)
	// DeleteAllUsers deletes all users
-	DeleteAllUsers() error
+	DeleteAllUsers(ctx context.Context) error
}
```

Depends on gravitational/teleport.e#2346
Implements step 3 of #32949
2023-10-10 14:07:46 +00:00
rosstimothy 603bcf43ac Set revisions on SSO users (#32873)
Update GitHub users to always have the correct revision set when
updating the user.
2023-10-09 13:59:50 +00:00
Michael WilsonandLisa Kim 14afe47883 Make sure Teleport sessions use the user login state. (#31363)
The user login state is being generated properly but not being used for
the various sessions. UserLoginState is now properly integrated into
sessions. Additionally, it was noticed that user login state was not being
used for Github logins, so it's been added there as well.

Additionally, getUserOrLoginState has been exposed for use by the
enterprise repo.

Co-authored-by: Lisa Kim <lisa@goteleport.com>
2023-09-07 22:43:18 +00:00
Anton Miniailo 023a2d4be4 Provide client login IP when SSO initiated in a browser. (#27661) 2023-06-15 17:07:51 +00:00
Nic Klaassen 1f6a4a26ff fix: record applied login rules in github login event (#27437) 2023-06-07 02:16:23 +00:00
Andrew LeFevre 3243fa6e7d fix GitHub connector API endpoint URL path getting ignored when making HTTP requests (#24830) 2023-05-23 23:00:50 +00:00
Michael WilsonandAlan Parra 5d6b5adca4 Add login hooks. (#24828)
* Add login hooks.

Login hooks have been added to support performing arbitrary operations on
user login. This is done to support generating of an Okta assignment on
user login for the Okta service feature.

* Don't use error channel for calling hooks, test login hooks.

* Expose ResetLoginHooks for external testing.

* Provide user as part of login hook.

* Update lib/auth/methods.go

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

* Improve the documentation for LoginHook, AuthenticateUser returns types.User.

* Use user.GetName() instead of username in AuthenticateSSHUser response.

* Address nits and restore comments.

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-04-24 17:26:45 +00:00
Forrest edfb418cc3 fix github url formatting (#25089) 2023-04-24 17:03:18 +00:00
Anton Miniailo de52c3a790 Fix IP pinning for SSO login (#24343)
We didn't get login IP when generating certificates for
SSO logins, so we couldn't pin certificates.
2023-04-13 13:41:46 +00:00