Commit Graph
93 Commits
Author SHA1 Message Date
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
Andrew LeFevre e202393122 Allow users to specify separate API URL for github connectors (#23200)
* allow users to specify separate  API URL for github connectors

* fix resources test
2023-03-23 20:10:05 +00:00
Steven Martin 47d5f236ef Use GitHub camelcase for UI, examples, and Messages (#23369)
* Use GitHub camelcase

* Update example github to camelcase

* Update references to GitHub as camelcase
2023-03-22 22:10:12 +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
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
Krzysztof Skrzętnicki f8fa2b9be2 Bump gravitational/trace package version (#19390) 2022-12-21 22:02:25 +00:00
Matheus e9f2ac7ade Export GithubConverter type (#18751) 2022-11-28 21:07:57 +00:00
Andrew LeFevre ba9fd70a92 Add ability to have multiple Github auth connector implementations (#17293)
* added Github auth creator

This will allow for multiple implementations of Github
auth connectors.

* work to allow multiple github auth connector implementations

* auth works, need to fix upserts

* fix upserting, add comments

* fix imports from merge

* removed now unused error

* point e submodule to master branch

* fix unit test

* use correct capitalization of 'GitHub'

* move Github auth connector conversions out of api module

* fix linter warning
2022-11-16 15:35:21 +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
Brian Joerger ce20b20753 PIV login enforcement (#15874)
Add private key policy enforcement.

  - Add private key policy cert extensions and enforcement.

  - Add private key policy settings and attestation logic.

  - Wire attestation request through login endpoints.

  - Store attestation data for reissue requests.

  - Add private key policy discovery and logic.

  - Relogin on hardware key policy errors.

  - Include integration with Teleport Connect.
2022-09-30 23:27:48 +00:00
rosstimothy 7e036cdf42 Generic retrieval of FnCache values (#16485)
Coverts getting values in the `FnCache` from `FnCache.Get` to
`utils.FnCacheGet[T any]`. This allows us to have compile time
guarantees for the type being loaded, which allows us to remove
some of the manual type checking required of callers today.
2022-09-20 12:36:03 +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
Edoardo Spadolini 58b01b964b Embed auth.Cache in auth.Server (#14698)
* Embed auth.Cache in auth.Server

* Hit the backend during Auth initialization

* Bypass the cache when rotating CAs

* Services.UpsertTrustedCluster is different

* Bypass the cache in waitForTunnelConnections

* Fix infinite recursion

* More cache bypassing during init and rotations

* Rename Services to Uncached in auth.Server

* Further cleanups

* Don't start the auth cache immediately

* Go back to Services rather than Uncached

* Comments and a missing method
2022-07-27 21:05:53 +00:00
rosstimothy fea159fd1b Add context.Context to CreateWebSession and DeleteWebSession (#14663)
* Add context to CreateWebSession and DeleteWebSession

Updates the WebService interface to include a context.Context in
CreateWebSession. Other function signatures were changed as needed
to propagte the context.Context into all the call site of
CreateWebSession.
2022-07-19 22:05:23 +00: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
Marco André Dinis 24cb3e3124 WebAPI: update user traits (#14076)
* WebAPI: update user traits

Web API only supports updating the roles property for a given User.

This PR adds the possibility of updating User's traits
- Logins
- DB Users
- DB Names
- Kube Users
- Kube Groups
- Windows Logins
- AWS Role ARNs

It only updates if the requests contains a non-nil value for the trait's
list.
It deduplicates the trait's list before applying it.
2022-07-06 15:55:45 +01:00
Brian Joerger 2aae5b5899 Fix SSO AuthRequest backwards compatibility. (#13589) 2022-06-17 01:21:29 +00:00
Krzysztof Skrzętnicki 7f8a2e6e7b Adjust tctl sso commands to new teams_to_roles field. (#13463) 2022-06-14 10:10:27 +00:00
Joel dc13bb8750 Remove uneeded mapping length check (#13460) 2022-06-14 08:40:55 +00:00
Joel efd10847bf Modernize role mapping in github connectors (#10456) 2022-06-08 15:34:15 +00:00
Brian Joerger 9cc58cca44 gRPC conversions - SSO Auth Connectors (#13073) 2022-06-08 01:45:06 +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
rosstimothy 550d23d15d Fix goroutine and memory leak in watchCertAuthorities (#10871)
* Fix goroutine and memory leak in watchCertAuthorities

The CA Watcher was blocking both on writing to a channel when the watcher
was closed and on HTTP calls that had no request timeout or context passed
to cause cancellation.

All resourceWatcher implementations that had a bug which may cause them to block
on writing to a channel forever were fixed by selecting on the write and ctx.Done.

Adding context.Context to all Get/Put/Post/Delete methods on the auth HTTPClient to
force callers to propagate context. Prior all calls used context.TODO which
prevents requests from being properly cancelled.

Add context propagation to RotateCertAuthority, RotateExternalCertAuthority,
GetCertAuthority, GetCertAuthorities. This is needed to get the correct ctx
from the CertAtuhorityWatcher all the way down to the HTTPClient that makes
the call.

Closes #10648
2022-03-10 11:05:39 -05:00
Edoardo Spadolini 2598401589 Add access requests to audit events (#9758)
* Refactor most uses of `UserMetadata` into a handful of functions

* Add access requests to `UserMetadata`

* Explanation for the reserved field in SessionStart
2022-01-25 16:56:18 +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