Skip to content

Improve performance of MFA ceremony#24250

Merged
rosstimothy merged 1 commit intomasterfrom
tross/single_use_certs_only_if_required
Apr 14, 2023
Merged

Improve performance of MFA ceremony#24250
rosstimothy merged 1 commit intomasterfrom
tross/single_use_certs_only_if_required

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

To date clients attempting to access a resource first have to call proto.AuthService/IsMFARequired to determine if an mfa ceremony is needed for access to a resource. In an effort to reduce an extra round trip to the Auth server this can can be bundled into proto.AuthService/GenerateUserSingleUseCerts.

In order for RBAC to determine if mfa is required for SSH sessions the OS login of the session must be known. To accomodate this a new SSHLogin field was added to proto.UserCertsRequest.

The response to the initial request of the stream now contains a proto.MFARequired enum which indicates whether mfa is required, not required, or it's unknown if mfa is required. The last variant should only be returned when the SSHLogin field is unset in the initial request.

The (auth.Server) isMFARequired check was also modified for nodes to make use of ListResources. Instead of retrieving all nodes into memory and finding the matching ones, a request is made to ListResources with the SearchKeywords populated with the target from proto.IsMFARequiredRequest_Node.Node.Node. Care was taken to filter out any matches from labels to preserve the original matching behavior.

@rosstimothy rosstimothy force-pushed the tross/single_use_certs_only_if_required branch 11 times, most recently from fde04fc to 1861e33 Compare April 12, 2023 14:23
@rosstimothy rosstimothy requested a review from codingllama April 12, 2023 14:58
@rosstimothy rosstimothy marked this pull request as ready for review April 12, 2023 14:58
@github-actions github-actions Bot requested review from Joerger and ryanclark April 12, 2023 14:58
Comment thread api/proto/teleport/legacy/client/proto/authservice.proto
Comment thread api/proto/teleport/legacy/client/proto/authservice.proto
Comment thread lib/auth/auth.go
Comment thread lib/client/cluster_client.go
Copy link
Copy Markdown
Contributor

@Joerger Joerger left a comment

Choose a reason for hiding this comment

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

Sorry, I didn't mean to approve yet ^

Comment thread lib/auth/auth.go
Comment thread lib/auth/grpcserver_test.go
Comment thread lib/auth/grpcserver_test.go Outdated
Comment thread lib/auth/grpcserver_test.go Outdated
Comment thread lib/auth/grpcserver_test.go
Comment thread lib/client/cluster_client.go Outdated
Comment thread lib/client/cluster_client.go
Comment thread integration/integration_test.go Outdated
Comment thread integration/integration_test.go
Comment thread integration/integration_test.go Outdated
@codingllama
Copy link
Copy Markdown
Contributor

Looks good, nice to see this one out for review.

@rosstimothy rosstimothy force-pushed the tross/single_use_certs_only_if_required branch from e4f7e44 to fc178b6 Compare April 14, 2023 14:04
Comment thread tool/tsh/tsh_test.go Outdated
Comment thread tool/tsh/tsh_test.go Outdated
Comment thread tool/tsh/tsh_test.go Outdated
Comment thread tool/tsh/tsh_test.go Outdated
Comment thread tool/tsh/tsh_test.go Outdated
Comment thread lib/client/cluster_client.go Outdated
@rosstimothy rosstimothy force-pushed the tross/single_use_certs_only_if_required branch from 02f586e to 1e80da5 Compare April 14, 2023 16:50
@rosstimothy rosstimothy enabled auto-merge April 14, 2023 16:51
@rosstimothy rosstimothy force-pushed the tross/single_use_certs_only_if_required branch from 1e80da5 to 60445b5 Compare April 14, 2023 18:12
To date clients attempting to access a resource first have to call
`proto.AuthService/IsMFARequired` to determine if an mfa ceremony
is needed for access to a resource. In an effort to reduce an
extra round trip to the Auth server this can can be bundled into
`proto.AuthService/GenerateUserSingleUseCerts`.

In order for RBAC to determine if mfa is required for SSH sessions
the OS login of the session must be known. To accomodate this a
new `SSHLogin` field was added to `proto.UserCertsRequest`.

The response to the initial request of the stream now contains a
`proto.MFARequired` enum which indicates whether mfa is required,
not required, or it's unknown if mfa is required. The last variant
should only be returned when the `SSHLogin` field is unset in the
initial request.

The `(auth.Server) isMFARequired` check was also modified for nodes
to make use of `ListResources`. Instead of retrieving **all** nodes
into memory and finding the matching ones, a request is made to
`ListResources` with the `SearchKeywords` populated with the target
from `proto.IsMFARequiredRequest_Node.Node.Node`. Care was taken
to filter out any matches from labels to preserve the original
matching behavior.
@rosstimothy rosstimothy force-pushed the tross/single_use_certs_only_if_required branch from 60445b5 to 0ccbb5f Compare April 14, 2023 18:54
@rosstimothy rosstimothy added this pull request to the merge queue Apr 14, 2023
Merged via the queue into master with commit 640bd01 Apr 14, 2023
@rosstimothy rosstimothy deleted the tross/single_use_certs_only_if_required branch April 14, 2023 19:23
rosstimothy added a commit that referenced this pull request May 5, 2023
The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619
rosstimothy added a commit that referenced this pull request May 8, 2023
The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619
rosstimothy added a commit that referenced this pull request May 8, 2023
* Add leaf resource test cases to TestGenerateUserSingleUseCert

Updates TestGenerateUserSingleUseCert to test certificate generation
for kube and db resources in a leaf cluster.

* Fix access to leaf resources

The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619

* Add desktop and app test case to TestGenerateUserSingleUseCert
github-actions Bot pushed a commit that referenced this pull request May 8, 2023
The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619
rosstimothy added a commit that referenced this pull request May 8, 2023
* Add leaf resource test cases to TestGenerateUserSingleUseCert

Updates TestGenerateUserSingleUseCert to test certificate generation
for kube and db resources in a leaf cluster.

* Fix access to leaf resources

The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619

* Add desktop and app test case to TestGenerateUserSingleUseCert
rosstimothy added a commit that referenced this pull request May 8, 2023
* Add leaf resource test cases to TestGenerateUserSingleUseCert

Updates TestGenerateUserSingleUseCert to test certificate generation
for kube and db resources in a leaf cluster.

* Fix access to leaf resources

The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619

* Add desktop and app test case to TestGenerateUserSingleUseCert
rosstimothy added a commit that referenced this pull request May 8, 2023
* Add leaf resource test cases to TestGenerateUserSingleUseCert

Updates TestGenerateUserSingleUseCert to test certificate generation
for kube and db resources in a leaf cluster.

* Fix access to leaf resources

The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619

* Add desktop and app test case to TestGenerateUserSingleUseCert
rosstimothy added a commit that referenced this pull request May 9, 2023
* Add leaf resource test cases to TestGenerateUserSingleUseCert

Updates TestGenerateUserSingleUseCert to test certificate generation
for kube and db resources in a leaf cluster.

* Fix access to leaf resources

The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619

* Add desktop and app test case to TestGenerateUserSingleUseCert
rosstimothy added a commit that referenced this pull request May 12, 2023
* Add leaf resource test cases to TestGenerateUserSingleUseCert

Updates TestGenerateUserSingleUseCert to test certificate generation
for kube and db resources in a leaf cluster.

* Fix access to leaf resources

The MFA required check added to the Auth server in
#24250 is now
only performed if the `RouteToCluster` indicates that the request
is for the local cluster and not a remote cluster. When the root
cluster checks if mfa is required to a resource in another cluster
it would always return a not found error since the resource didn't
exist in the root backend. This results in the behavior described
in #25619.

This step is now skipped for any resources in another cluster to allow
certificates for remote cluster resources to be generated by the root.
`tsh` detects that a resource is a leaf cluster and will first call
`proto.AuthService/IsMFARequired` on the leaf cluster before requesting
certificates from the root cluster to prevent a user from being
prompted to complete an MFA ceremony if one is not required.

Closes #25619

* Add desktop and app test case to TestGenerateUserSingleUseCert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants