Skip to content

Bootstrap kubernetes RBACs when running EKS auto discovery#41693

Merged
tigrato merged 3 commits intomasterfrom
tigrato/teleport-discovery-access-entry
May 28, 2024
Merged

Bootstrap kubernetes RBACs when running EKS auto discovery#41693
tigrato merged 3 commits intomasterfrom
tigrato/teleport-discovery-access-entry

Conversation

@tigrato
Copy link
Copy Markdown
Contributor

@tigrato tigrato commented May 17, 2024

This PR extends the ability of discovery_service to self-bootstrap the required permissions for the kubernetes_service to dial and forward requests to the Kubernetes API on behalf of the users.

When EKS auto-discovery was initially developed, it wasn't possible to bootstrap the required permissions without having prior access to the cluster itself. Recently, AWS releases a new API to configure access to IAM identities. By default, there are just a few predefined permissions that either don't have the required permissions for kubernetes_service to be operational or are the equivalent of cluster-admin RBAC role.

To bypass it, discovery_service temporarily escalates itself to cluster-admin by creating an EKS AccessEntry and associates the policy
arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy.

Once access is granted, it creates a Kubernetes RBAC ClusterRole and ClusterRoleBinding with the minimal required permissions for kubernetes_service to be operational. These permissions are bonded to teleport:kube-service:eks.

Finally, it deletes the previously created AccessEntry and creates another for the target ARN that Kubernetes Service uses.

Fixes #39021

Changelog: Extended Discovery Service to self-bootstrap necessary permissions for Kubernetes Service to interact with the Kubernetes API on behalf of users.

@tigrato tigrato force-pushed the tigrato/teleport-discovery-access-entry branch 2 times, most recently from 75605b4 to f862008 Compare May 17, 2024 15:37
@tigrato tigrato marked this pull request as ready for review May 17, 2024 15:43
@tigrato tigrato requested a review from AntonAM May 17, 2024 15:43
Comment thread lib/srv/discovery/fetchers/eks.go
Comment thread lib/srv/discovery/fetchers/eks.go Outdated
Comment thread lib/srv/discovery/fetchers/eks.go
Comment thread api/proto/teleport/legacy/types/types.proto
@tigrato tigrato force-pushed the tigrato/teleport-discovery-access-entry branch from 4d02431 to 4df52d9 Compare May 23, 2024 09:34
@tigrato tigrato requested a review from AntonAM May 23, 2024 10:14
Comment thread lib/srv/discovery/fetchers/eks.go
@tigrato tigrato force-pushed the tigrato/teleport-discovery-access-entry branch from 4df52d9 to 1a56fdb Compare May 27, 2024 08:30
@tigrato
Copy link
Copy Markdown
Contributor Author

tigrato commented May 27, 2024

@gabrielcorado @smallinsky can you please take a look?

Comment thread lib/kube/utils/eks_token_signed.go Outdated
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.

Do we need to call strings.TrimRight ? rstrip('=')

Suggested change
return v1Prefix + base64.RawURLEncoding.EncodeToString([]byte(presignedURLString)), tokenExpiration, nil
return v1Prefix + base64.RawURLEncoding.EncodeToString([]byte(presignedURLString)), tokenExpiration, nil

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.

It's not required. = represents padding in b64 and it works anyway.
aws cli strips them but iam authenticator doesn't

Comment thread lib/srv/discovery/fetchers/eks.go Outdated
Comment on lines 175 to 177
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.

Can we use lazy evaluation for the fetcher.setCallerIdentity call ?

Correct me if I'm wrong but It looks that If this call will fail during setup the whole service will fail to start.

I think that we should avoid this kind of dependency where a one failing call will stop the whole discovery service. Ideally this should be done by lazy evaluation with proper error handling.

Copy link
Copy Markdown
Contributor Author

@tigrato tigrato May 27, 2024

Choose a reason for hiding this comment

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

handled in b7f08fd

in theory the GetCallerIdentity only fails if we don't have any identity associated which is already a blocker for the discovery service

@smallinsky smallinsky self-requested a review May 27, 2024 10:04
tigrato added 3 commits May 28, 2024 11:18
This PR extends the ability of `discovery_service` to self-bootstrap the
required permissions for the `kubernetes_service` to dial and forward
requests to the Kubernetes API on behalf of the users.

When EKS auto-discovery was initially developed, it wasn't possible to
bootstrap the required permissions without having prior access to the
cluster itself. Recently, AWS releases a new API to configure access to
IAM identities. By default, there are just a few predifined permissions
that either don't have the required permissions for
`kubernetes_service` to be operational or are the equivalent of
`cluster-admin` RBAC role.

To bypass it, `discovery_service` temporarily escalates itself to
`cluster-admin` by creating an EKS `AccessEntry` and associates the
policy
`arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy`.

Once access is granted, it creates a Kubernetes RBAC `ClusterRole` and
`ClusterRoleBinding` with the minimal required permissions for
`kubernetes_service` to be operational. These permissions are binded to
`teleport:kube-service:eks`.

Finally, it deletes the previously created `AccessEntry` and creates
another for the target ARN that Kubernetes Service uses.

Fixes #39021

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
@tigrato tigrato force-pushed the tigrato/teleport-discovery-access-entry branch from b7f08fd to 35fb33f Compare May 28, 2024 10:18
@tigrato tigrato enabled auto-merge May 28, 2024 10:18
@tigrato tigrato added this pull request to the merge queue May 28, 2024
Merged via the queue into master with commit 06c7354 May 28, 2024
@tigrato tigrato deleted the tigrato/teleport-discovery-access-entry branch May 28, 2024 12:32
@public-teleport-github-review-bot
Copy link
Copy Markdown

@tigrato See the table below for backport results.

Branch Result
branch/v13 Failed
branch/v14 Failed
branch/v15 Failed

tigrato added a commit that referenced this pull request May 28, 2024
* Bootstrap kubernetes RBACs when running EKS auto discovery

This PR extends the ability of `discovery_service` to self-bootstrap the
required permissions for the `kubernetes_service` to dial and forward
requests to the Kubernetes API on behalf of the users.

When EKS auto-discovery was initially developed, it wasn't possible to
bootstrap the required permissions without having prior access to the
cluster itself. Recently, AWS releases a new API to configure access to
IAM identities. By default, there are just a few predifined permissions
that either don't have the required permissions for
`kubernetes_service` to be operational or are the equivalent of
`cluster-admin` RBAC role.

To bypass it, `discovery_service` temporarily escalates itself to
`cluster-admin` by creating an EKS `AccessEntry` and associates the
policy
`arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy`.

Once access is granted, it creates a Kubernetes RBAC `ClusterRole` and
`ClusterRoleBinding` with the minimal required permissions for
`kubernetes_service` to be operational. These permissions are binded to
`teleport:kube-service:eks`.

Finally, it deletes the previously created `AccessEntry` and creates
another for the target ARN that Kubernetes Service uses.

Fixes #39021

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

* handle review comments

* do not exit on failed GetCallerIdentity call

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
github-merge-queue Bot pushed a commit that referenced this pull request May 28, 2024
…42075)

* Bootstrap kubernetes RBACs when running EKS auto discovery

This PR extends the ability of `discovery_service` to self-bootstrap the
required permissions for the `kubernetes_service` to dial and forward
requests to the Kubernetes API on behalf of the users.

When EKS auto-discovery was initially developed, it wasn't possible to
bootstrap the required permissions without having prior access to the
cluster itself. Recently, AWS releases a new API to configure access to
IAM identities. By default, there are just a few predifined permissions
that either don't have the required permissions for
`kubernetes_service` to be operational or are the equivalent of
`cluster-admin` RBAC role.

To bypass it, `discovery_service` temporarily escalates itself to
`cluster-admin` by creating an EKS `AccessEntry` and associates the
policy
`arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy`.

Once access is granted, it creates a Kubernetes RBAC `ClusterRole` and
`ClusterRoleBinding` with the minimal required permissions for
`kubernetes_service` to be operational. These permissions are binded to
`teleport:kube-service:eks`.

Finally, it deletes the previously created `AccessEntry` and creates
another for the target ARN that Kubernetes Service uses.

Fixes #39021



* handle review comments

* do not exit on failed GetCallerIdentity call

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
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.

EKS auto-discovery leveraging CreateAccessEntry and AssociateAccessPolicy for setup access

3 participants