59 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
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 fd55ac722d Run auth tests in parallel (#64066)
All tests in lib/auth that do not modify global variables (modules,
insecure dev mode) or make use of t.Setenv directly are now run in
parallel.
2026-03-02 14:01:09 +00:00
rosstimothy 6590c944b6 Inject modules into keygen (#62843)
Contributes to #62799.
2026-01-16 18:52:50 +00:00
Dan Upton 165ec1fdb4 MWI: Generate AutoUpdateBotInstanceReport resource (#59738)
* Add `AutoUpdateBotReport` resource definition

* Generate bot version report once per minute

* Add gRPC endpoint for reading bot report

* Add updater info to the bot heartbeat message

* Fix a couple of minor typos

* Add forgotten cache event plumbing

* Fix duplicate import

* Fix racy test

* Add missing license header

* Fill HostUUID in tests

* Rename "bot report" to "bot instance report"

* Fix formatting

* Make one of the expected values different

* Defend against expired instances being counted

* Closer align `AutoUpdateBotInstanceReport` resource with RFD 153

* Add endpoint for deleting report
2025-10-07 14:32:36 +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
rosstimothy 7541d6d7d0 Introduce logtest package (#56741)
Moves all test related logger initialization and creation to the
logtest package to reduce testing symbols in production code. The
existing helpers in lib/utils have been left in place until the
enterprise references can be converted.

Updates #51023.
2025-07-15 18:11:10 +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
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
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
Alan Parra 108d736eec chore: Bump github.com/jonboulle/clockwork to v0.5.0 (#51434)
* Update e/ reference

* chore: Bump github.com/jonboulle/clockwork to v0.5.0

* Rewrite clockwork.FakeClock to *clockwork.FakeClock

* Fix lib/srv/app/gcp/handler_test.go

* Add a linter exception for FakeClock.BlockUntil

* Change AppTestOptions.Clock to clockwork.Clock
2025-01-24 15:22:13 +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
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
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
Vadym Popov 894761bab9 Prevent auth from starting when an incompatible major upgrade is detected (#43520)
* Teleport auth should refuse to start when jumping major versions (#41782)

* linter fixes

* code review changes:
- replaced to use process storage and state itme
- regexp replaced with semver
- additional check for v18 for empty version record in storage

* code review changes:
- add integration test
- store latest version in separate key

* code review changes:
- table tests
- error message

* code review changes:
- minor changes

* code review changes:
- reuse context for write operation

* code review changes:
- simplify integration test
- add downgrade check
- minor changes

* code review changes:
- move logic to the auth init

* code review changes:
- add development env to skip version check
- init the process storage if it is not set

* code review changes:
- add interface for local process storage
- use semver in storage instead

* change interface to version storage

* add fake version storage for other tests
2024-07-12 22:01:21 +00:00
Nic Klaassen 8a72a03abf refactor keystore config (#43154)
* refactor keystore config

* rename Pin to PIN

* use constants for GCP KMS protection levels

* add missing godoc comments
2024-06-18 22:54:21 +00:00
Edoardo Spadolini e4ec728d4a Validate client redirects in SSO client logins (#41833) 2024-05-21 18:45:43 +00:00
rosstimothy aa800a083b Remove auth aliases left over from transitioning to authclient (#41666)
* Remove auth.UserTokenType aliases

* Remove auth/api.go

* Stop using auth.AccessCache aliases

* Stop using auth.Cache aliases

* Stop using auth.Announcer alias

* Stop using auth.ProxyAccessPoint alias

* Stop using auth.ReadProxyAccessPoint alias

* Stop using auth.RemoteProxyAccessPoint alias

* Stop using auth.NewRemoteProxyCachingAccessPoint alias

* Stop using auth.ReadKubernetesAccessPoint alias

* Stop using auth.KubernetesAccessPoint alias

* Stop using auth.ReadDatabaseAccessPoint alias

* Stop using auth.DatabaseAccessPoint alias

* Stop using auth.WindowsDestkopAccessPoint alias

* Stop using auth.AppsAccessPoint alias

* Stop using auth.DiscoveryAccessPoint alias

* Stop using auth.NodeAccessPoint alias

* Stop using auth.ReadAppsAccessPoint alias

* Stop using cache wrapper aliases

* fix test

* update e to include https://github.com/gravitational/teleport.e/pull/4175
2024-05-16 20:54:02 +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
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 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
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
Andrew LeFevre d4b3afe9a1 split recording session events and emitting audit events (#27873)
* split recording session events and emitting audit events

This is a refactor of how audit events and session events are handled.
Previously, all events were emitted using the same interface,
api/types/events.Emitter. This lead to event-related code getting to be
very confusing, as it was often unclear whether a given event was being
recorded as a session event and emitted as an audit event, or only one
of the two. Naturally, a few bugs arose due to this.

To simplify event handling, a separate interface for recording session
events has been created. A api/types/events.Recorder should now only be
used to record session events, and an Emitter should now only be used to
emit audit events. Instead of using a confusing TeeWriter that would
transparently (and confusingly, given its name) hold a few event types
that only belonged in session recordings, callers can now explicitly
record and/or emit an event when necessary.

* ensure e build won't break
2023-07-11 19:53:33 +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
Nic Klaassen 15d8544a82 add list of applied login rules to user login event (#26460) 2023-05-17 18:43:50 +00:00
Forrest edfb418cc3 fix github url formatting (#25089) 2023-04-24 17:03:18 +00:00
Nic Klaassen ff9e60fdf0 feat: evaluate login rules for GitHub users (#20627)
This commit enables login rule evaluation during login for users logging
in with a GitHub connector.

The GitHub connector is a bit different from the SAML and OIDC
connectors in that the user roles are not mapped from the traits
(claims/assertions) but from the user's GitHub organizations and teams
directly.
This makes login rules slightly less useful for GitHub logins because
they cannot affect the user's roles, only their traits.
However, GitHub login is mostly an OSS feature and login rules will be
enterprise-only.
Any enterprise users making use of GitHub login will still be able to
use some of the features (trait mapping).
2023-01-25 18:38:33 +00:00
Cam Hutchison 6bac096d28 auth: Split SAML connector code to own type (#18255)
Create a new type - `SAMLAuthService` - and move the implementation of
the SAML connector from the auth Service to this new type. This
decoupling will make it easier to move out of tree in a later commit.

This also lays the basic groundwork for running without the SAML
connector at all, returning a NotImplemented error for all the SAML
logic if the SAMLAuthService is not plugged in.

A number of names in the `auth` package have been exported to facilitate
moving the SAML connector out of this repository. The types exported do
not need to be exported for this commit, but for subsequent commits that
move the `SAMLAuthService` out of the `auth` package.

Also apply a small fix to to emit `apievents.SAMLConnector*` events of
`apievents.OIDCConnector*` events in the SAML connector.
2022-11-16 14:24:43 +11:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Nic Klaassen 847f13a8a9 refactor keystore config (#17907) 2022-10-28 11:30:49 -07:00
rosstimothy ebfbfd496e Use testauthority instead of native to generate keys in tests (#16486)
* use test authority

* use testauthority for InitConfig RSAKeyPairSource

* add named returns to test authority
2022-09-21 20:53:09 +00:00
Alan Parra a75fcc21d8 Update golangci-lint to 1.49.0 (#16507)
Update metalinter, fix a few lint warnings and replace deprecated linters.

`deadcode`, `structcheck` and `varcheck` are abandoned and now replaced by [`unused`][1].

Since 1.19, `go fmt` reformats godocs according to https://go.dev/doc/comment. I've done a bulk-reformatting of the codebase to keep the linter happy. Backporting is mostly harmless (the exception being `lib/services/role_test.go`, that for some reason breaks the _old_ linter using the new format).

[1]: https://golangci-lint.run/usage/linters/

* Bump golangci-lint version
* Replace abandoned linters
* Fix bodyclose on lib/auth/github.com
* Fix bodyclose on lib/kube/proxy/streamproto/proto_test.go
* Fix bodyclose on lib/srv/alpnproxy/proxy_test.go
* Fix bodyclose on lib/web/conn_upgrade_test.go
* Silence staticcheck on lib/kube/proxy/forwarder_test.go
* Silence staticcheck on lib/utils/certs_test.go
* Address BuildNameToCertificate deprecation warnings
* Run `go fmt ./...`
* Run `go fmt ./...` on api/
* Ignore formatting in role_test.go
* Remove redundant initializers in lib/srv/uacc/
* Update e/
2022-09-19 22:38:59 +00:00
Andrew LeFevre 4d25801fab Deny Github organizations using external SSO on Teleport OSS (#14529)
* added check that blocks enterprise Github organizations using external SSO from using Github auth connectors on Teleport OSS

* added details to docs and changelog

* move check from init to on login

* cache org sso status; address small pieces of feedback

* use utils.FnCache instead of 3rd party cache

* addressed feedback

* addressed feedback

* revised docs

* addressed more feedback

* remove notes in changelog

* removed unused interface
2022-09-16 16:14:15 -04:00
Andrew Burke b7efbcebb0 Add error message for failed SSO authorization (#9622)
This change, along with gravitational/webapps#530, adds a new error message for when a user successfully authenticates with SSO but fails to match any roles.
2022-07-15 23:55:25 +00:00
Russell Jones 2552b4ab25 Refactor tests under auth package.
Refactored all tests under "lib/auth" to use testify instead
of gocheck.

Switched backend for most tests to "memory".
2022-07-08 17:41:59 -07:00
Russell Jones f7144fe860 Refactor tests under services package.
Refactored "lib/services/suite" and "lib/services/local" packages to use
testify instead of gocheck.

Swapped backend from "lite" to "memory" to cut time to run tests in
half.
2022-07-07 17:40:34 -07:00
Joel efd10847bf Modernize role mapping in github connectors (#10456) 2022-06-08 15:34:15 +00:00
Krzysztof Skrzętnicki 9377f7c681 New commands: tctl sso test, tctl sso configure for GitHub (#12783)
* Implement `tctl sso` commands for GitHub auth.

* Mark RFDs as implemented.
2022-05-26 23:26:35 +00:00
Zac Bergquist 3b0127f00b Move MockEmitter to eventstestpackage 2022-03-29 12:12:01 -06:00
Alex McGrath 34a087ff43 Convert auth test from gocheck to standard lib 2022-02-10 16:04:27 +00:00
Alex McGrath 1ca73cd1e7 Add github teams to available traits 2022-01-24 10:59:59 +00:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Andrej Tokarčík d63d144e8e Move ClusterID field from ClusterConfig to ClusterName (#7050) 2021-06-18 18:42:09 +02:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Andrew Lytvynov fc1c1dbd14 Move all utils.InitLoggerForTests calls to TestMain
This prevents data races between changing the standard logger and it
acutally being used.
2021-02-23 18:04:55 -08:00