Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UpsertTrustedClusterV2 RPC #49789

Merged
merged 24 commits into from
Dec 21, 2024
Merged

Conversation

bernardjkim
Copy link
Contributor

Closes #48309
Supports #22474

This PR introduces the UpsertTrustedClusterV2 rpc. This new rpc supersedes UpsertTrustedCluster. V2 performs resource name validation for trusted_clusters. This is required to support trusted_cluster resources with the kubernetes operator.

Approaches Considered

Previously in #49169, there was discussion about introducing a new TrustedClusterV3 to address #48309. This approach could work, but it is unnecessary because V3 would not introduce any breaking changes in the resource itself. We would also need to be careful not to break backwards compatibility while introducing this new resource version.

We also considered using the resource origin or label to identify if resource name validation is required. This would allow the auth server to only validate the resource name if the trusted_cluster origin is kubernetes. However, this approach would not be able to ensure name validation if the kubernetes operator connects to an older auth server.

We've decided that a new endpoint was the more appropriate solution. This approach enables the auth server to ensure trusted_cluster resource names are validated when created by the kubernetes operator. The kubernetes operator would also not be able to bypass the resource name validation when connected to an older auth server.

Deprecation/Migration

No current timeline to migrate other clients to use the UpsertTrustedClusterV2. UpsertTrustedCluster will be supported indefinitely for now.

This supersedes UpsertTrustedCluster rpc. V2 performs resource name
validation.
@bernardjkim bernardjkim added the no-changelog Indicates that a PR does not require a changelog entry label Dec 4, 2024
@github-actions github-actions bot requested a review from gzdunek December 4, 2024 20:12
api/client/client.go Outdated Show resolved Hide resolved
api/types/trustedcluster.go Show resolved Hide resolved
lib/auth/auth_with_roles.go Outdated Show resolved Hide resolved
lib/auth/grpcserver.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
integration/integration_test.go Outdated Show resolved Hide resolved
@programmerq
Copy link
Contributor

If a trusted cluster is upserted and labels are added/changed/modified, would that also propagate the label change to the corresponding remote_cluster object?

@bernardjkim
Copy link
Contributor Author

If a trusted cluster is upserted and labels are added/changed/modified, would that also propagate the label change to the corresponding remote_cluster object?

According to the documentation, labels are not support on trusted_cluster resources. https://goteleport.com/docs/admin-guides/management/admin/trustedclusters/#step-56-manage-access-to-the-trusted-cluster

api/client/client.go Outdated Show resolved Hide resolved
api/client/client.go Outdated Show resolved Hide resolved
api/client/client.go Outdated Show resolved Hide resolved
api/client/client.go Outdated Show resolved Hide resolved
api/client/client.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
- 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
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
api/types/trustedcluster.go Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
@vintage-maeve
Copy link

Thanks for putting this feature together!
Based on this PR, if I want to update only the attribute_to_roles section of the TC, would that require rejoining or having an active invitation token?

@bernardjkim
Copy link
Contributor Author

Based on this PR, if I want to update only the attribute_to_roles section of the TC, would that require rejoining or having an active invitation token?

I believe it is already possible to update the role mapping of a TC without having to rejoin or having an active join token. This PR should not affect this behavior.

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from gzdunek December 10, 2024 22:02
@bernardjkim
Copy link
Contributor Author

I've updated the PR to also include CreateTrustedClusterV2 and UpdateTrustedClusterV2 in response to #49920 (comment)

@rosstimothy
Copy link
Contributor

I've updated the PR to also include CreateTrustedClusterV2 and UpdateTrustedClusterV2 in response to #49920 (comment)

We should probably replace all of the V2 RPCs introduced here with new RPCs to the trust service.

Copy link
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding V2 RPCs to the auth service can we please add new RPCs to the trust service?

@bernardjkim bernardjkim force-pushed the bernard/upsert-trusted-cluster-v2 branch from 0401fcc to 4a4bb8d Compare December 12, 2024 01:42
@bernardjkim
Copy link
Contributor Author

I've moved the V2 RPCs to the trust service. I've left the logic in auth service for now to limit the size and scope of this PR.

lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Show resolved Hide resolved
Comment on lines 121 to 126
if existingCluster == nil {
return a.createTrustedCluster(ctx, tc)
return a.createTrustedCluster(ctx, tc, validateName)
}

if err := existingCluster.CanChangeStateTo(tc); err != nil {
return nil, trace.Wrap(err)
}
updated, err := a.updateTrustedCluster(ctx, tc, existingCluster)
return updated, trace.Wrap(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we give this a handful of tries? UpsertFoo should basically never fail due to concurrent writes, but this logic is liable to fail on a race between an upsert and a delete, or two upserts on a new trusted cluster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point. I think we can defer this to a separate PR though. We'd also be modifying the behavior of the existing Upsert method.

lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
lib/auth/trustedcluster.go Outdated Show resolved Hide resolved
@bernardjkim
Copy link
Contributor Author

Thanks for all the good feedback!

@bernardjkim bernardjkim added this pull request to the merge queue Dec 21, 2024
Merged via the queue into master with commit a221604 Dec 21, 2024
44 checks passed
@bernardjkim bernardjkim deleted the bernard/upsert-trusted-cluster-v2 branch December 21, 2024 04:43
@public-teleport-github-review-bot

@bernardjkim See the table below for backport results.

Branch Result
branch/v17 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v17 no-changelog Indicates that a PR does not require a changelog entry size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trusted_cluster resource renames itself, breaking subsequent updates
6 participants