Skip to content

Reissue kube certs when assuming access request#50553

Merged
gzdunek merged 8 commits intomasterfrom
gzdunek/reissue-kube-certs
Jan 14, 2025
Merged

Reissue kube certs when assuming access request#50553
gzdunek merged 8 commits intomasterfrom
gzdunek/reissue-kube-certs

Conversation

@gzdunek
Copy link
Copy Markdown
Contributor

@gzdunek gzdunek commented Dec 23, 2024

Closes https://github.com/gravitational/customer-sensitive-requests/issues/301

Currently, assuming or dropping an access request does not affect open kube local proxies. As a result, if an assumed request includes elevated permissions, the user must close the existing local proxy and reopen it for the changes to take effect. To address this issue, we can clear the certificates in the local proxy, allowing them to be reissued when a new request is made.

There's one downside to this approach: we can't determine which local proxies will be affected by the access request, so we must invalidate all of them. As a result, the user must then perform per-session MFA for all open kube proxies after assuming or dropping a request. Additionally, if the user has an open kube proxy and then assumes a request that doesn't allow access to that cluster, that proxy will become unusable. But I'm not sure if this is really an issue as it seems reasonable to expect that previous access might not be retained after assuming a request.

changelog: Assuming an access request in Teleport Connect now propagates elevated permissions to already opened Kubernetes tabs

Demo:

kube.assume.request.mov

For now I'm keeping it in draft (I need to add some tests) but any feedback is welcome!

Comment thread lib/srv/alpnproxy/kube.go
@gzdunek gzdunek requested review from ravicious and tigrato December 23, 2024 16:12
@gzdunek gzdunek force-pushed the gzdunek/reissue-kube-certs branch from 4f69915 to 2bad500 Compare January 2, 2025 15:38
@gzdunek gzdunek marked this pull request as ready for review January 2, 2025 15:38
@github-actions github-actions Bot requested review from camscale and nklaassen January 2, 2025 15:38
Comment thread lib/srv/alpnproxy/kube.go
Comment thread lib/srv/alpnproxy/kube.go
Comment thread lib/srv/alpnproxy/kube.go
Comment thread lib/teleterm/daemon/daemon.go
Comment thread lib/teleterm/gateway/kube.go Outdated
Comment thread lib/teleterm/daemon/daemon.go Outdated
@gzdunek gzdunek requested a review from ravicious January 3, 2025 17:07

// KubeClusterFromKubeLocalProxySNI returns Kubernetes cluster name from SNI.
func KubeClusterFromKubeLocalProxySNI(serverName string) (string, error) {
kubeCluster, _, _ := strings.Cut(serverName, ".")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we care about the teleport cluster?
It's possible you have the same cluster name in two different teleport clusters

Copy link
Copy Markdown
Contributor Author

@gzdunek gzdunek Jan 13, 2025

Choose a reason for hiding this comment

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

I'm reading the teleport cluster using TeleportClusterFromKubeLocalProxySNI() before reading the kube cluster.
Then m.certReissuer() is called with that pair of teleport + kube cluster.

Do you mean something else?

Comment thread lib/srv/alpnproxy/kube.go
defer s.mu.RUnlock()
for _, gw := range s.gateways {
targetURI := gw.TargetURI()
if !(targetURI.IsKube() && targetURI.GetRootClusterURI() == cluster.URI) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this correct? a gateway from a leaf cluster can be modified when you assume a root cluster role

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think so. As Grzegorz wrote in the PR description:

There's one downside to this approach: we can't determine which local proxies will be affected by the access request, so we must invalidate all of them.

If you assume a root cluster role, AFAIK we cannot easily tell if it affects leaf cluster resources.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, Rafał's explanation is correct.

Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

Looks good, but I'll wait until you address Tiago's feedback.

Comment thread lib/srv/alpnproxy/kube.go Outdated
defer s.mu.RUnlock()
for _, gw := range s.gateways {
targetURI := gw.TargetURI()
if !(targetURI.IsKube() && targetURI.GetRootClusterURI() == cluster.URI) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think so. As Grzegorz wrote in the PR description:

There's one downside to this approach: we can't determine which local proxies will be affected by the access request, so we must invalidate all of them.

If you assume a root cluster role, AFAIK we cannot easily tell if it affects leaf cluster resources.

Comment thread lib/srv/alpnproxy/kube.go
@gzdunek gzdunek requested review from ravicious and tigrato January 13, 2025 15:38
# Conflicts:
#	integration/proxy/teleterm_test.go
@gzdunek gzdunek enabled auto-merge January 14, 2025 13:27
@gzdunek gzdunek added this pull request to the merge queue Jan 14, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 14, 2025
@gzdunek gzdunek enabled auto-merge January 14, 2025 15:15
@gzdunek gzdunek added this pull request to the merge queue Jan 14, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 14, 2025
@gzdunek gzdunek added this pull request to the merge queue Jan 14, 2025
Merged via the queue into master with commit e4e09a1 Jan 14, 2025
@gzdunek gzdunek deleted the gzdunek/reissue-kube-certs branch January 14, 2025 16:13
@public-teleport-github-review-bot
Copy link
Copy Markdown

@gzdunek See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed
branch/v17 Create PR

gzdunek added a commit that referenced this pull request Jan 15, 2025
* Reissue kube certs when assuming access request

* Fix and add tests

* Explain when the cert can be not found

* Replace `clearCertsFn` with `middleware` field

* Improve iterating over gateways

* Improve a comment

(cherry picked from commit e4e09a1)
gzdunek added a commit that referenced this pull request Jan 15, 2025
* Reissue kube certs when assuming access request

* Fix and add tests

* Explain when the cert can be not found

* Replace `clearCertsFn` with `middleware` field

* Improve iterating over gateways

* Improve a comment

(cherry picked from commit e4e09a1)
github-merge-queue Bot pushed a commit that referenced this pull request Jan 15, 2025
* Reissue kube certs when assuming access request (#50553)

* Reissue kube certs when assuming access request

* Fix and add tests

* Explain when the cert can be not found

* Replace `clearCertsFn` with `middleware` field

* Improve iterating over gateways

* Improve a comment

(cherry picked from commit e4e09a1)

* Adjust logs to logrus

* Adjust tests

* Adjust logs to logrus

* One more logger fix

* Lint
github-merge-queue Bot pushed a commit that referenced this pull request Jan 15, 2025
* Reissue kube certs when assuming access request (#50553)

* Reissue kube certs when assuming access request

* Fix and add tests

* Explain when the cert can be not found

* Replace `clearCertsFn` with `middleware` field

* Improve iterating over gateways

* Improve a comment

(cherry picked from commit e4e09a1)

* Adjust logs to logrus

* Adjust logs to logrus

* Logger and lint
mvbrock pushed a commit that referenced this pull request Jan 18, 2025
* Reissue kube certs when assuming access request

* Fix and add tests

* Explain when the cert can be not found

* Replace `clearCertsFn` with `middleware` field

* Improve iterating over gateways

* Improve a comment
carloscastrojumo pushed a commit to carloscastrojumo/teleport that referenced this pull request Feb 19, 2025
* Reissue kube certs when assuming access request

* Fix and add tests

* Explain when the cert can be not found

* Replace `clearCertsFn` with `middleware` field

* Improve iterating over gateways

* Improve a comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants