Commit Graph
43 Commits
Author SHA1 Message Date
Trent Clarke 1ba6e939df Removes the entire notion of a DynamicAccessList from Teleport (#39222)
* Removes the entire notion of a DynamicAccessList from Teleport

Insurmountable security issues were found with the notion of dynamic
AccessList ownership and membership, so the entire concept is being
removed.

This PR removes all internal usage of the Dynamic access list
concept. The corresponding protobuf updates are coming in a later
PR.

Changelog: Removed Dynamic AccessList

* Fix API tests

* More API test fixes

* Fix integrations tests
2024-03-14 07:51:11 +00:00
Hugo ShakaandNoah Stride 29e1e5bc14 Refactor operator to support several types of resources + propagate labels (#38992)
* Refactor operator resource reconciler to support resource153 + add label propagation

I initially just wanted to add label propagation (which is required for
OpenSSH and OpenSSHEICE servers).

However I ran into an issue: not all Teleport resources implement the
`ResourceWithLabels` interface.  Basically we have 4 cases:
- resources implementing `ResourceWithLabels` (e.g. User, Role, ...)
- resources implementing `ResourceWithOrigin` but not
  `ResourceWithLabels` (e.g. GitHub connector, ProvisionToken, ...)
- resources that have been tweaked to implement only the operator
  `TeleportResource` interface (`LoginRule`)
- resources implementing `Resource153`

To support all those resoucres, we can either:
- edit each resource so they expose the same methods (e.g.
  ProvisionToken exposes `GetLabels` instead of `GetStaticLabels`)
- wrap each ressource in a wrapper that implements the operator
  TeleportResource interface
- add multiple reconcilers, one for each resource kind

I don't think it's sane for the operator to force changes on Teleport
resources. Especially as those are known to be non consistent. I also
don't want the operator to maintain a copy of each resource, this is not
viable on the long term.

For those reasons I chose the 3rd approach and built 3 reconcilers. Then
I deducplicated the code to end up with a generic reconciler that can be
tuned by passing an adapter. The adapter is an empty struct that has all
the methods to extract the information the operator requires from the
resource.

The resulting PR is large and heavily uses generics but the amount of
logical changes is quite low (the only diff is that we now copy labels).
I can walk you through the PR if needed.

With this PR, the operator supports properly any resource implementing
`types.Resource153`, this will be useful to add `TeleportBotV1` support.

* Update integrations/operator/controllers/reconcilers/base.go

Co-authored-by: Noah Stride <noah.stride@goteleport.com>

* use structured logging

---------

Co-authored-by: Noah Stride <noah.stride@goteleport.com>
2024-03-07 21:17:13 +00:00
Michael Wilson 0b526b50fe Ignore the status field in access list operator tests. (#38776)
The operator tests will now skip the access list status field.
2024-02-29 17:36:24 +00:00
Hugo ShakaandMarco André Dinis 288f87af1b integrations/operator: Add openSSH and openSSHEICE servers (#37651)
* integrations/operator: Add openSSH and openSSHEICE servers

* lint

* Update integrations/operator/controllers/resources/openssheiceserverv2_controller.go

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

* rename Openssh to OpenSSH and fix comments

* hide cmdlabels

---------

Co-authored-by: Marco André Dinis <marco.dinis@goteleport.com>
2024-02-20 23:07:26 +00:00
Hugo Shaka f95d1d9092 integrations/operator: Fix the operator deleting unowned resources (#37655)
* integrations/operator: Fix the operator deleting unowned resources

* Update integrations/operator/controllers/resources/teleport_reconciler.go

* add license
2024-02-03 02:09:51 +00:00
Hugo Shaka 3ffb95f984 fix operator role controller (#37275) 2024-01-25 19:42:25 +00:00
Hugo Shaka 9b45ebd1d4 Add role v6 and role v7 controllers (#36840)
* Add role v6 and role v7 controllers

* lint
2024-01-25 15:12:58 +00:00
Hugo Shaka fb97a39bde integrations/operator: add ignore and keep flags for CRs (#37182)
* integrations/operator: add ignore and keep flags for CRs

* lint + address feedback
2024-01-24 22:32:27 +00:00
Hugo Shaka 7b02cada13 integrations/operator: support multiple versions of the same resource in crdgen (#36715)
The commit contains the following changes:

- add multi-version support by creating new kinds. This is currently done via an override to maintain compatibility. At some point, we might migrate unversioned kinds (TeleportRole) to versioned kinds (TeleportRoleV5) and remove the override
- unify all resource statuses in a single struct. This simplifies the CRD building because we are not trying to guess which package is correct anymore when parsing go's AST
- update crdgen snapshots

This PR does not update the base CRDs in the operator or the Hlem chart. This will happen in the next PR, adding go types and controller support.

Note for reviewers: the changeset might seem large, but the changes are split into commits that are much more reviewable. You only need to review the first two commits.
2024-01-24 01:33:29 +00:00
Hugo Shaka ac7dff07ff Move role controller to standard Teleport controller (#36836) 2024-01-22 19:45:43 +00:00
Hugo Shaka b16513bc67 operator: fix access lists step by step mutation tests (#36897) 2024-01-18 23:57:26 +00:00
Hugo Shaka 4dfc23442f integrations/operator: use unstructured objects for all controllers (#36142)
This commit prepares everything for us to switch to a single reconciler for all resources. Part of https://github.com/gravitational/teleport/issues/21416

This commit does the following changes:
- setup controllers for the unstructured objects instead of the structured ones (like `Role` was doing). This is due to the bad behaviour of `utils.Strings` of serializing as a single string if the list contains a single element.
- use a single scheme for everything instead of multiple ones. We suffered from drifts between main and tests in the past.
- fetch the GVK for the unstructure objects from the scheme. This operation can fail and now a bunch of builder/init functions can return errors
- Introduce a new `Reconciler` interface to hide the controller internals
- unify how controllers are started in main and tests. This is not directly related to the PR goal (preparing the ground for a unified controller) but I was drawn into this when I made the constructors return errors.
2024-01-17 15:43:26 +00:00
Andrew Burke 840af310db Convert insecure-drop to drop for unsupported clients (#35803)
This change converts the insecure-drop host user creation mode
to drop for clients that don't support it.
2024-01-11 01:06:18 +00:00
Hugo Shaka c9b1ab013a Use cmp and cmpots properly in operator tests (#36215)
This commit creates a standard set of compare options for all tests that
handles the common use cases:
- ignore ID, labels and other dynamic metadata
- apply sane time comparison by default
- equates nil maps and empty maps (caused by proto serialization)

This solves a couple of comparison issues I faced in another PR.
2024-01-03 14:59:35 +00:00
Hugo Shaka 619f900e1c integrations/operator: Add AccessList support (#31771)
* integrations/operator: add support for access lists

* fixup! integrations/operator: add support for access lists
2023-12-18 19:36:39 +00:00
Hugo Shaka 856bb39ea9 Add a version server in the proxy + use it in agent chart (#35150)
This PR adds an embedded [version server](https://goteleport.com/docs/architecture/agent-update-management/#version-server-and-source-of-truth) in the proxy to address: https://github.com/gravitational/cloud/issues/6773

The version server can be configured through `teleport.yaml`:

```yaml
proxy_service:
  enabled: "yes"
  automatic_upgrades_channels:
    stable/cloud:
      forward_url: https://updates.releases.teleport.dev/v1/stable/cloud
    preview/cloud:
      static_version: v12.5.4
```

The forwarded call results are cached for a minute.
2023-12-12 01:03:45 +00:00
Andrew Burke 56e6ace218 Remove drop host user creation mode (#35524)
This change removes the drop host user creation mode.
2023-12-11 19:07:29 +00:00
rosstimothy 85c29d1cf4 Implement and use UpsertOIDCConnectorV2 (#35144)
While the api client already had support for the new upsert method
it was unimplemented server side and would always fallback to the
legacy UpsertOIDCConnector RPC. This implements the RPC handler
and updates the signature of UpsertOIDCConnector to return the
upserted connector in the same manner that Create and Update do.
2023-12-01 19:22:41 +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 88bb9cfd96 Implement and use UpsertSAMLConnectorV2 (#35208)
While the api client already had support for the new upsert method
it was unimplemented server side and would always fallback to the
legacy UpsertSAMLConnector RPC. This implements the RPC handler
and updates the signature of UpsertSAMLConnector to return the
upserted connector in the same manner that Create and Update do.
2023-11-30 19:09:44 +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
Hugo ShakaandTiago Silva f31a90d4a4 integrations/operator: Standalone operator with reusable client (#34482)
* Standalone operator using tbot

* Update integrations/operator/embeddedtbot/bot.go

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>

* make teleportClient private

* lint

---------

Co-authored-by: Tiago Silva <tiago.silva@goteleport.com>
2023-11-23 17:23:18 +00:00
Hugo Shaka f67478dd9d integrations/operator: split mutator interface in two (#34728)
- MutateExisting for resource update
- Mutate for resource creation
2023-11-22 18:38:05 +00:00
Hugo Shaka df257bed9c integrations/operator: re-use the teleport client instead of creating a new one (#34050)
* integrations/operator: re-use the teleport client instead of creating a new one

* fix race condition

* address feedback + add godocs
2023-11-07 22:05:42 +00:00
Hugo Shaka 0a51fa01b9 integrations/operator: remove require checks from Eventually funcs (#34270)
* use eventuallyWithT

* integrations/operator: remove require checks from Eventually funcs

* fixup! integrations/operator: remove require checks from Eventually funcs
2023-11-07 20:40:02 +00:00
Hugo Shaka 3a8a07f158 integrations/operator: propagate revision + fix tests (#34265)
* operator: propagate revision info + fix tests

* fixup! operator: propagate revision info + fix tests
2023-11-07 17:48:20 +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
Tiago Silva 9750a455e5 Fix Teleport update reconciliation on status updates (#34063)
* Fix Teleport update reconciliation on `status` updates

This pull request addresses the issue where the Teleport operator reconciliation runs every time the operator updates the `status` subresource.
This continuous reconciliation has led to an infinite loop, causing millions of reconciliations per minute.
When an error occurs, such as having invalid role properties, the Operator updates the status and returns an error, which should trigger a rescheduled reconciliation with exponential backoff. The problem arises because the operator failed to enforce a resource generation change, resulting in an immediate trigger of a new reconciliation when the `status` field is updated.

This pull request modifies the operator to avoid updating subresources and only trigger updates when there is a change in resource generation.

Special thanks to @strideynet for confirming my hypothesis and giving
the solution!

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* return proper status conditions on failures

* enforce condition update on silentUpdateStatus

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2023-11-02 22:27:23 +00:00
rosstimothy 2087a2fda8 Implement Create/UpdateRole on the auth server (#33491)
In addition to adding server and backend handling for create and
update roles, the services.Access interface was updated to return
a role from the existing Create/UpsertRole methods. Bumps the e
ref to incorporate the associated changes needed there to prevent
breaking the build.
2023-10-18 17:06:50 +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
Tiago Silva 9a556d8ab1 Add support for Protobuf Enums into Operator CRDs (#32469)
* Add support for Protobuf Enums into Operator CRDs

This PR marks the Teleport enum fields as integer or string values. The
integer option is to ensure we are backwards compatibile with
previously installed CRDs.

Users can now represent their roles in Kubernetes custom resources and
refer enum fields as strings while their protobuf wire type is int32.

Fixes #29686

* add tests

* fix unit test
2023-09-26 13:43:50 +00:00
Hugo Shaka 3eb16f55fe integrations/operator: Fix a bug that caused ProvisionToken.spec.github.allow rules to be ignored (#30065)
* integrations/crdgen: Support loading instructions from a file for easier debugging

* integrations/crdgen: Fix CRD generation for nested message declarations

* integrations/crdgen: Update CRDs and CRD snaphots after crdgen fix

* integrations/operator: Add a test covering machineID on GHA tokens

* document how to dump protoc requests
2023-08-08 15:53:31 +00:00
Michael Wilson 46f8fbe0c8 k8s operator supports Okta import rules. (#28158)
* k8s operator supports Okta import rules.

The k8s operator now supports Okta import rules, which will allow users to
use native k8s CRDs to provision Okta import rules in k8s environments.

* Fix helm test.

* Remove unneeded proto files.

* Use additionalProperties in the okta import rules CRD instead of properties.
2023-06-27 14:16:53 +00:00
Zac Bergquist 80707cd328 Remove duplicate imports (#27886) 2023-06-15 17:06:18 +00:00
Hugo Shaka e710b012c1 integrations/operator: Use a dedicated scheme in tests (#26782)
* integrations/operator: Use a dedicated scheme in tests

Relying on a global scheme can cause race-conditions when registering
schema in multiple tests. This commit does two things in an attempt to
fix https://github.com/gravitational/teleport/issues/26753:

- use a separate Scheme for tests to avoid being affected by what others
  might be doing with the scheme
- initiate the Scheme only once during import

* unexport scheme
2023-05-25 09:26:01 +00:00
Hugo Shaka 37aa916859 operator: ProvisionToken support (#18718)
* crdgen: properly index nested types

* integrations/operator: Add ProvisionTokenV2 CRD

* integrations/operator: regenerate CRDs

* integrations/operator: Add provisiontoken controller

* helm: update snapshots to include provisiontoken crs
2023-05-19 15:56:25 +00:00
Tiago Silva df3f5b3c45 Extend kubectl auth can-i support for kubernetes_resources RBAC rules (#26425)
This PR extends Teleport capabilities of `kubectl auth can-i` to support
evaluation of `kubernetes_resources`.

It also changes the error message to be clear to the users what's the
cause of the error and adds a warning when users try to edit invalid
roles.
2023-05-19 10:35:47 +00:00
Zac Bergquist 8d0769ef5f Remove duplicate imports (#24736) 2023-04-18 19:08:26 +00:00
Nic Klaassen a7ba75e511 chore: refactor k8s operator test helpers (#23552)
* refactor controller tests

* move envtest installation into envtest.mk for use in teleport.e
2023-03-28 14:43:27 +00:00
Nic Klaassen 5ec44bb962 feat: add login rule controller to k8s operator (#23416)
This PR adds a Login Rule controller to the k8s operator so that Login
Rules can be managed via kubectl and the k8s API.
2023-03-24 22:48:25 +00:00
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
Zac Bergquist 2ae9d770fc Refactor tctl's dependencies (#22693)
* Move configuration from lib/service to lib/service/servicecfg

The new servicecfg package will hold only configuration for services.
This will allow other packages (like tctl and tsh) to depend on
servicecfg without pulling in all of lib/service (which has a number
of platform-specific details).

This is the first step towards being able to build tctl for Windows.

* Move PAM and BPF config into servicecfg

This breaks a compile-time dependency on BPF/PAM for tctl.
2023-03-09 17:48:36 +00:00
Hugo Shaka 9e1f53d33a Move operator into integrations/ (#22618)
* Move operator into `integrations/`

* fixup! Move operator into `integrations/`

* fixup! fixup! Move operator into `integrations/`

* fixup! fixup! fixup! Move operator into `integrations/`

* fixup! fixup! fixup! fixup! Move operator into `integrations/`
2023-03-06 17:59:02 +00:00