Skip to content

Commit

Permalink
operator: Support trusted_cluster resources (#49920)
Browse files Browse the repository at this point in the history
* Add UpsertTrustedClusterV2 rpc

This supersedes UpsertTrustedCluster rpc. V2 performs resource name
validation.

* Replace confusing UpsertValidationTrustedCluster name

* Use UpsertTrustedClusterV2 in tests

* Address feedback

- Remove unnecessary ping
- Update error messages
- Use skipNameValidation consts
- Validate cluster name before establishing trust
- Do not reveal cluster name in error message
- Use BadParameter instead of CompareFailed

* Use webclient.Find

* Fix test/lint

* Allow label updates

* Fix test

* Update CRDs

1. Run `make manifests`.
2. Run `make -C crdgen update-protos`.
3. Run `make -C crdgen update-snapshot`.

* Implement trusted_cluster CRD

* Update docs

* Support secret lookup

* Update secret lookup docs

* Fix error handling

* Use V2

* Implement CreateTrustedClusterV2 and UpdateTrustedClusterV2

* Address feedback

* Minor fixes

* Use Create/Update instead of Upsert

* Update crdgen

* Update trusted_cluster tests

* Move V2 RPCs to the trust service

* crdgen

* Remove V2 suffix

* 2024 -> 2025

* Use slog
  • Loading branch information
bernardjkim authored Jan 13, 2025
1 parent 9948ed4 commit 646329d
Show file tree
Hide file tree
Showing 32 changed files with 2,074 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ of the Teleport Kubernetes operator CRs.
Some Teleport resources might contain sensitive values. Select CR fields can reference an existing
Kubernetes secret and the operator will retrieve the value from the secret when reconciling.

Currently only the GithubConnector and OIDCConnector `client_secret` field support secret lookup.
Currently supported fields for secret lookup:
- GithubConnector `client_secret`
- OIDCConnector `client_secret`
- TrustedClusterV2 `token`

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ could cause instability and non-deterministic behaviour.
</Admonition>

Currently supported Teleport resources are:
- users (`TeleportUser`)
- roles
- Users (`TeleportUser`)
- Roles
- `TeleportRole` creates role v5
- `TeleportRoleV6` creates role v6
- `TeleportRoleV7` creates role v7
- OIDC connectors (`TeleportOIDCConnector`)
- SAML connectors (`TeleportSAMLConnector`)
- GitHub connectors (`TeleportGithubConnector`)
- provision tokens (`TeleportProvisionToken`)
- Login Rules (`TeleportLoginRules`)
- OIDC Connectors (`TeleportOIDCConnector`)
- SAML Connectors (`TeleportSAMLConnector`)
- GitHub Connectors (`TeleportGithubConnector`)
- Provision Tokens (`TeleportProvisionToken`)
- Login Rules (`TeleportLoginRule`)
- Access Lists (`TeleportAccessList`)
- Okta Import Rules (`TeleportOktaImportRule`)
- OpenSSHEICE Servers (`TeleportOpenSSHEICEServerV2`)
- OpenSSH Servers (`TeleportOpenSSHServerV2`)
- Trusted Clusters (`TeleportTrustedClusterV2`)

### Setting up the operator

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: TeleportTrustedClusterV2
description: Provides a comprehensive list of fields in the TeleportTrustedClusterV2 resource available through the Teleport Kubernetes operator
tocDepth: 3
---

{/*Auto-generated file. Do not edit.*/}
{/*To regenerate, navigate to integrations/operator and run "make crd-docs".*/}

This guide is a comprehensive reference to the fields in the `TeleportTrustedClusterV2`
resource, which you can apply after installing the Teleport Kubernetes operator.


## resources.teleport.dev/v1

**apiVersion:** resources.teleport.dev/v1

|Field|Type|Description|
|---|---|---|
|apiVersion|string|APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources|
|kind|string|Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds|
|metadata|object||
|spec|[object](#spec)|TrustedCluster resource definition v2 from Teleport|

### spec

|Field|Type|Description|
|---|---|---|
|enabled|boolean|Enabled is a bool that indicates if the TrustedCluster is enabled or disabled. Setting Enabled to false has a side effect of deleting the user and host certificate authority (CA).|
|role_map|[][object](#specrole_map-items)|RoleMap specifies role mappings to remote roles.|
|token|string|Token is the authorization token provided by another cluster needed by this cluster to join. This field supports secret lookup. See the operator documentation for more details.|
|tunnel_addr|string|ReverseTunnelAddress is the address of the SSH proxy server of the cluster to join. If not set, it is derived from `<metadata.name>:<default reverse tunnel port>`.|
|web_proxy_addr|string|ProxyAddress is the address of the web proxy server of the cluster to join. If not set, it is derived from `<metadata.name>:<default web proxy server port>`.|

### spec.role_map items

|Field|Type|Description|
|---|---|---|
|local|[]string|Local specifies local roles to map to|
|remote|string|Remote specifies remote role name to map from|

Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
name: teleporttrustedclustersv2.resources.teleport.dev
spec:
group: resources.teleport.dev
names:
kind: TeleportTrustedClusterV2
listKind: TeleportTrustedClusterV2List
plural: teleporttrustedclustersv2
shortNames:
- trustedclusterv2
- trustedclustersv2
singular: teleporttrustedclusterv2
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: TrustedClusterV2 is the Schema for the trustedclustersv2 API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: TrustedCluster resource definition v2 from Teleport
properties:
enabled:
description: Enabled is a bool that indicates if the TrustedCluster
is enabled or disabled. Setting Enabled to false has a side effect
of deleting the user and host certificate authority (CA).
type: boolean
role_map:
description: RoleMap specifies role mappings to remote roles.
items:
properties:
local:
description: Local specifies local roles to map to
items:
type: string
nullable: true
type: array
remote:
description: Remote specifies remote role name to map from
type: string
type: object
type: array
token:
description: Token is the authorization token provided by another
cluster needed by this cluster to join. This field supports secret
lookup. See the operator documentation for more details.
type: string
tunnel_addr:
description: ReverseTunnelAddress is the address of the SSH proxy
server of the cluster to join. If not set, it is derived from `<metadata.name>:<default
reverse tunnel port>`.
type: string
web_proxy_addr:
description: ProxyAddress is the address of the web proxy server of
the cluster to join. If not set, it is derived from `<metadata.name>:<default
web proxy server port>`.
type: string
type: object
status:
description: Status defines the observed state of the Teleport resource
properties:
conditions:
description: Conditions represent the latest available observations
of an object's state
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
teleportResourceID:
format: int64
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ rules:
- teleportopensshserversv2/status
- teleportopenssheiceserversv2
- teleportopenssheiceserversv2/status
- teleporttrustedclustersv2
- teleporttrustedclustersv2/status
verbs:
- get
- list
Expand Down
8 changes: 8 additions & 0 deletions examples/chart/teleport-cluster/templates/auth/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ data:
- read
- update
- delete
- resources:
- trusted_cluster
verbs:
- list
- create
- read
- update
- delete
deny: {}
version: v7
---
Expand Down
4 changes: 4 additions & 0 deletions integrations/operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The operator supports reconciling the following Kubernetes CRs:
- TeleportRoleV7 (creates role v7)
- TeleportProvisionToken
- TeleportGithubConnector
- TeleportAccessList
- TeleportOpenSSHEICEServerV2
- TeleportOpenSSHServerV2
- TeleportTrustedClusterV2
- TeleportSAMLConnector [1]
- TeleportOIDCConnector [1]
- TeleportLoginRule [1]
Expand Down
96 changes: 96 additions & 0 deletions integrations/operator/apis/resources/v1/trusted_cluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Teleport
* Copyright (C) 2025 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/integrations/operator/apis/resources"
)

func init() {
SchemeBuilder.Register(&TeleportTrustedClusterV2{}, &TeleportTrustedClusterV2List{})
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// TeleportTrustedClusterV2 is the Schema for the trusted_clusters API
type TeleportTrustedClusterV2 struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TeleportTrustedClusterV2Spec `json:"spec,omitempty"`
Status resources.Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// TeleportTrustedClusterV2List contains a list of TeleportTrustedClusterV2
type TeleportTrustedClusterV2List struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TeleportTrustedClusterV2 `json:"items"`
}

// ToTeleport converts the resource to the teleport trusted_cluster API type.
func (r TeleportTrustedClusterV2) ToTeleport() types.TrustedCluster {
return &types.TrustedClusterV2{
Kind: types.KindTrustedCluster,
Version: types.V2,
Metadata: types.Metadata{
Name: r.Name,
Labels: r.Labels,
Description: r.Annotations[resources.DescriptionKey],
},
Spec: types.TrustedClusterSpecV2(r.Spec),
}
}

// TeleportTrustedClusterV2Spec defines the desired state of TeleportTrustedClusterV2
type TeleportTrustedClusterV2Spec types.TrustedClusterSpecV2

// Marshal serializes a spec into binary data.
func (spec *TeleportTrustedClusterV2Spec) Marshal() ([]byte, error) {
return (*types.TrustedClusterSpecV2)(spec).Marshal()
}

// Unmarshal deserializes a spec from binary data.
func (spec *TeleportTrustedClusterV2Spec) Unmarshal(data []byte) error {
return (*types.TrustedClusterSpecV2)(spec).Unmarshal(data)
}

// DeepCopyInto deep-copies one trusted_cluster spec into another.
// Required to satisfy runtime.Object interface.
func (spec *TeleportTrustedClusterV2Spec) DeepCopyInto(out *TeleportTrustedClusterV2Spec) {
data, err := spec.Marshal()
if err != nil {
panic(err)
}
*out = TeleportTrustedClusterV2Spec{}
if err = out.Unmarshal(data); err != nil {
panic(err)
}
}

// StatusConditions returns a pointer to Status.Conditions slice.
func (r *TeleportTrustedClusterV2) StatusConditions() *[]metav1.Condition {
return &r.Status.Conditions
}
Loading

0 comments on commit 646329d

Please sign in to comment.