Commit Graph
24 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
Noah Stride 24b7275d87 Fix panics caused by expiryless tokens (#22829)
* Fix panic due to expiryless token in bot add

* Fix other unprotected dereferences of *ProvisionToken.Metadata.Expires
2023-03-09 17:52:34 +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
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
Tiago Silva 40861809a6 Add RoleV6 resource type (#19324)
This PR includes a new Role resource version that is compatible with V5 spec.

The new resource introduces the `kubernetes_resources` definition that allows operators to limit the Kubernetes resources that each member can access. The `kubernetes_resources` entries must follow the following format: `{"kind":"<kind>", "namespace":"<namespace>","name":"<pod>"}`. Currently, it only supports objects of `kind` `pod`. Valid examples `<namespace>/<name>:
- `*/*`: matches all pods in all namespaces.
- `default/*`: matches all pods in the `default` namespace.
- `*/nginx-*`: matches every pod prefixed with `nginx-` in every namespace.

For older resource versions - V5, V4, V3 - `kubernetes_resources` is automatically populated with `{"kind":"pod","namespace":"*","name":"*"}` to keep compatibility. For the newest version, it's mandatory to define its value otherwise access to pods will be denied.

Part of #18434
2023-01-05 09:58:12 +00:00
Noah StrideandZac Bergquist 291d6d53a6 CircleCI Secure Joining (#17626)
* Add API types for CircleCI joining

* Add validation for CircleCI configuration

* Add JoinMethodCircleCI across codebase

* Add token validator and token source for circleci

* Update join methods RFD

* Add CircleCI token source to register.go

* Add serverside support for circleci joining

* Add test for TokenSource

* Add success case for token validation test

* Add expired test case

* Add test case for token from another org

* Test RegisterWithToken for CircleCI

* Refactor GitHub RegisterUsingToken tests

* Refactor CircleCI RegisterUsingToken tests

* Add tests for ProvisionTokenSpecV2

* Appease linters

* Go Imports files

* Fix failing test for msising IDtoken

* Update lib/auth/join_circleci.go

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

* Move test server cleanup closer to initialisation

* Fix weird import reordering

* Include unexpected type in error message

* Simplify boolean algebra :)

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-11-01 12:15:10 +00:00
Noah Stride a54de3bb64 GitHub Actions joining (#16938)
* Introduce Github Actions join support

* Go mod tidy

* run goimports on source files

* Address PR comments

* More PR review comments

* Changes to tests based on PR feedback

* Improve error message in github rule validation

* Add support for SHA

* Add short message describing which fields shouldb be included
2022-10-05 10:05:48 +00:00
Noah Stride eb42cabbea Revert "Introduce ProvisionTokenV3 (#16361)" (#16934)
This reverts commit 3fba50261f.
2022-10-03 14:14:01 +00:00
Yassine Bounekhla 09633dd47f Remove license feature flags for Moderated Sessions, Resource Access Requests, Machine ID (#16585) 2022-09-30 21:46:25 +00:00
Noah Stride 3fba50261f Introduce ProvisionTokenV3 (#16361)
* Introduce proto types for ProvisionTokenV3

* Add methods to ProvisionTokenV3 to support ProvisionToken iface

* Start building v3 support into the client

* add support for mashalling and unmarshalling ProvisionTokenV3

* Start unit testing ProvisionTokenV3

* Remove oneof to support yaml marshal/unmarshal

* Client should try V3 methods and fallback to v2

* More tests

* Fix join tests

* Fix integration tests

* Switch integration tests to use v3 spec

* Switch iam tests to use ProvisionTokenV3

* Change ec2 join tests to use V3 tokens

* Fix events tests for V3 token

* support ProvisionTokenV3 within API client events handler

* Explicitly specify JoinMethod

* Tidy up final usage of NewProvisionTokenV2FromSpec in tests

* Improve proto docs on ProvisionTokenV3

* Fix bot join tests

* Clarify error message for invalid join method

* Adjust resource version comment

* Fix comments and return error rather than bool in V2() method

* Catch incompatible conversions case

* Include V2 ProvisionToken in tests and add appropriate DELETE IN notes

* Fix linter warnings/unit test failures

* Use nolint rather than lint:ignore

* Add more DELETE IN notes

* Run goimports on join_ec2_test.go

* Address PR comments from tim.

* Add more deprecation/delete in notices

* Improve godoc comments on checkAndSetDEfaults for provider config

* Simplify implementation by dropping client-ahead compatability

* Add some support for client-ahead but with conversion to v3

* Update code comments to include responsible party

* Rename `Role` to `RoleARN` in EC2 configuration for clarity

* Fix tests for Role -> RoleARN rename

* Move MustCreateProvisionToken out of API and into test packages

* Properly go imports files
2022-09-27 17:05:32 +00:00
Noah StrideandPaul Gottschling 7c904714e9 Machine ID support for Logins trait (#15117)
* Support user traits in impersonated role certificates

* Add param to tctl bots add for specifying logins

* Update comment on desiredAccessInfoForRoleRequest to be mroe accurate

* Update docs for --logins support with Machine ID

* Rearrange bot tests and name them more in-line with standards

* Add test coverage for Server.createBot

* Test role impersonation preserves user traits

* pass traits directly into desiredAccessInfoForRoleRequests

* Drop underscores from test names

* Remove unnecessary initialization of traits

* Address PR comments

* Update docs/pages/machine-id/getting-started.mdx

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>

* Update docs/pages/machine-id/getting-started.mdx

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>

* Update docs/pages/machine-id/getting-started.mdx

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
2022-08-12 12:06:38 +00:00
Noah Stride 071bb116bc Skip cache during CreateBot RPC (#14899)
* Skip cache during CreateBot RPC

* Adjust calls to use .Service rather than .Identity

* Switch to CreateRole from UpsertRole
2022-08-02 13:39:48 +00: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
Nic Klaassen 489c26df1a Refactor services.AccessInfo (#14765) 2022-07-22 08:37:49 +01: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
Tim Buckley 207332d170 Add Machine ID enterprise license enforcement (#13914)
* Add Machine ID enterprise license enforcement

This adds two checks to Machine ID for license enforcement: one on
initial bot create, and another on join.

* Use modules.SetTestModules(); fix failing test
2022-06-29 16:27:18 +00:00
Tim Buckley 70a73355c9 Properly handle empty list of role requests (#13456)
* Properly handle empty list of role requests

Currently, an empty list of role requests results in an ambiguous
situation: we usually use the presence of role requests to determine
whether or not we'd return impersonated certs or not. An empty list
of role requests returns a fresh set of non-impersonated certs
(possibly renewed if allowed), while a non-empty list of role requests
returns certs with just those roles.  However, if a client _intends_
to request impersonated certs but provides an empty list of role
requests it will instead receive non-impersonated (possibly renewable)
certs with the full permissions of the original user.

This could theoretically result in privilege escalation if a Machine
ID bot: (a) had any worthwhile permissions of its own, which is not
the case unless the bot role was manually modified and (b)
accidentally handed certs off to an attacker.

In practice this bug is fairly difficult to hit: `tbot` always
auto-fills all requestable roles if they are otherwise unset, and
`tctl bots add` requires `--roles=` to be passed. An empty string
here can trigger the bug however it is unlikely a user would pass this
by accident. Moreover, a bot without requestable roles cannot
accomplish much of anything, so this is exceedingly unlikely to
be intended behavior.

Additionally, certificate generation checks help to mitigate the
issue: bots currently lock themselves by accident after the first
renewal when this bug is triggered as they don't explicitly handle
receiving renewable certs when impersonated certs are expected. If an
attacker were to attempt a renewal, the generation counter would
similarly limit access, and as noted previously, the bot role grants
only minimal read-only access anyway.

---

To resolve the issue, this adds a new `RoleRequestsOnly` flag to
`UserCertsRequest` that allows clients to unambiguously specify if
they wish to receive a non-impersonated, possibly renewable, cert with
all the original user's roles and permissions, or if they wish to
receive only role-impersonated certs (or an error if roles are empty).
Machine ID passes this flag in all situations where an impersonated
cert is desired.

Additionally, we also now ensure users add at least one role in
`CreateBot()` (called by `tctl bots add`) as this is almost certainly
an unintended situation.

Fixes #13411

* Address review feedback, rename flag to UseRoleRequests

* Return a local error if no roles are specified
2022-06-27 16:25:12 +00:00
Nic Klaassen 814664ab66 [Search-based access requests] Enforce resource access restrictions (#12651) 2022-06-03 00:04:44 +00:00
Tim Buckley e6a54dafa7 Use RoleV5 for new Machine ID bots (#11525)
The template bot role was downgraded from RoleV4 to RoleV3 in #10884.
This does work but unfortunately grants bots an overly broad set of
default permissions, including `*: *` access to apps, databases, and
k8s clusters.

This change moves to RoleV5 to clear default permissions.
2022-04-04 18:46:11 +00:00
Krzysztof Skrzętnicki d5d206ea16 Assign EmitAuditEvent to err for subsequent check. (#11501) 2022-03-28 15:00:52 +00:00
Tim Buckley 34fbced61d Fix meaning of bot_name in bot join tokens (#11039)
The `BotName` / `bot_name` was previously used to refer to the bot
_username_ rather than the bot name as entered by users. This leads
to confusion as the username is an implemention detail not obviously
visible to users.

This changes the meaning of the `bot_name` parameter to instead
consistently accept a bot name, which is converted to a username on
the backend where needed.
2022-03-10 22:08:07 +00:00
Brian Joerger 600022b290 Change NewRole to use V5 by default, old consumers now user NewRoleV3. (#10884) 2022-03-08 21:11:53 +00:00
Nic Klaassen 6e16ad6627 IAM join method support for tbot (#10535) 2022-03-01 00:35:34 +00:00
bb121d7b1e Certificate renewal bot (#10099)
* Add certificate renewal bot

This adds a new `tbot` tool to continuously renew a set of
certificates after registering with a Teleport cluster using a
similar process to standard node joining.

This makes some modifications to user certificate generation to allow
for certificates that can be renewed beyond their original TTL, and
exposes new gRPC endpoints:
 * `CreateBotJoinToken` creates a join token for a bot user
 * `GenerateInitialRenewableUserCerts` exchanges a token for a set of
   certificates with a new `renewable` flag set

A new `tctl` command, `tctl bots add`, creates a bot user and calls
`CreateBotJoinToken` to issue a token. A bot instance can then be
started using a provided command.

* Cert bot refactoring pass

* Use role requests to split renewable certs from end-user certs
* Add bot configuration file
* Use `teleport.dev/bot` label
* Remove `impersonator` flag on initial bot certs
* Remove unnecessary `renew` package
* Misc other cleanup

* Do not pass through `renewable` flag when role requests are set

This adds additional restrictions on when a certificate's `renewable`
flag is carried over to a new certificate. In particular, it now also
denies the flag when either role requests are present, or the
`disallowReissue` flag has been previously set.

In practice `disallow-reissue` would have prevented any undesired
behavior but this improves consistency and resolves a TODO.

* Various tbot UX improvements; render SSH config

* Fully flesh out config template rendering
* Fix rendering for SSH configuration templates
* Added `String()` impls for destination types
* Improve certificate renewal logging; show more detail
* Properly fall back to default (all) roles
* Add mode hints for files
* Add/update copyright headers

* Add stubs for tbot init and watch commands

* Add gRPC endpoints for managing bots

* Add `CreateBot`, `DeleteBot`, and `GetBotUsers` gRPC endpoints
* Replace `tctl bot (add|rm|ls)` implementations with gRPC calls
* Define a few new constants, `DefaultBotJoinTTL`, `BotLabel`,
  `BotGenerationLabel`

* Fix outdated destination flag in example tbot command

* Bugfix pass for demo

* Fixed a few nil pointer derefs when using config from CLI args
* Properly create destination if `--destination-dir` flag is used
* Remove improper default on CLI flag
* `DestinationConfig` is now a list of pointers

* Address first wave of review feedback

Fixes the majority of smaller issues caught by reviewers, thanks all!

* Add doc comments for bot.go functions

* Return the token TTL from CreateBot

* Split initial user cert issuance from `generateUserCerts()`

Issuing initial renewable certificate ended up requiring a lot of
hacks to skip checks that prevented anonymous bots from getting
certs even though we'd verified their identity elsewhere (via token).

This reverts all those hacks and splits initial bot cert logic into a
dedicated `generateInitialRenewableUserCerts()` function which should
make the whole process much easier to follow.

* Set bot traits to silence log messages

* tbot log message consistency pass

* Resolve lints

* Add config tests

* Remove CreateBotJoinToken endpoint

Users should instead use the CreateBot/DeleteBot endpoints.

* Create a fresh private key for every impersonated identity renewal

* Hide `config` subcommand

* Rename bot label prefix to `teleport.internal/`

* Use types.NewRole() to create bot roles

* Clean up error handling in custom YAML unmarshallers

Also, add notes about the supported YAML shapes.

* Fetch proxy host via gRPC Ping() instead of GetProxies()

* Update lib/auth/bot.go

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Fix some review comments

* Add renewable certificate generation checks (#10098)

* Add renewable certificate generation checks

This adds a new validation check for renewable certificates that
maintains a renewal counter as both a certificate extension and a
user label. This counter is used to ensure only a single certificate
lineage can exist: for example, if a renewable certificate is stolen,
only one copy of the certificate can be renewed as the generation
counter will not match

When renewing a certificate, first the generation counter presented
by the user (via their TLS identity) is compared to a value stored
with the associated user (in a new `teleport.dev/bot-generation`
label field). If they aren't equal, the renewal attempt fails.
Otherwise, the generation counter is incremented by 1, stored to the
database using a `CompareAndSwap()` to ensure atomicity, and set on
the generated certificate for use in future renewals.

* Add unit tests for the generation counter

This adds new unit tests to exercise the generation counter checks.

Additionally, it fixes two other renewable cert tests that were
failing.

* Remove certRequestGeneration() function

* Emit audit event when cert generations don't match

* Fully implement `tctl bots lock`

* Show bot name in `tctl bots ls`

* Lock bots when a cert generation mismatch is found

* Make CompareFailed respones from validateGenerationLabel() more actionable

* Update lib/services/local/users.go

Co-authored-by: Nic Klaassen <nic@goteleport.com>

* Backend changes for tbot IoT and AWS joining (#10360)

* backend changes

* add token permission check

* pass ctx from caller

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* fix comment typo

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* use UserMetadata instead of Identity in RenewableCertificateGenerationMismatch event

* Client changes for tbot IoT joining (#10397)

* client changes

* delete replaced APIs

* delete unused tbot/auth.go

* add license header

* don't unecessarily fetch host CA

* log fixes

* s/tunnelling/tunneling/

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* auth server addresses may be proxies

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* comment typo fix

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* move *Server methods out of auth_with_roles.go (#10416)

Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address another batch of review feedback

* Addres another batch of review feedback

Add `Role.SetMetadata()`, simplify more `trace.WrapWithMessage()`
calls, clear some TODOs and lints, and address other misc feedback
items.

* Fix lint

* Add missing doc comments to SaveIdentity / LoadIdentity

* Remove pam tag from tbot build

* Update note about bot lock deletion

* Another pass of review feedback

Ensure all requestable roles exist when creating a bot, adjust the
default renewable cert TTL down to 1 hour, and check types during
`CompareAndSwapUser()`

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-02-19 02:41:45 +00:00