-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Bootstrap kubernetes RBACs when running EKS auto discovery #41693
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 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 fixtures | ||
|
|
||
| // KubeClusterRoleTemplate is a template for a Kubernetes ClusterRole | ||
| // that Teleport uses to access Kubernetes resources. | ||
| const KubeClusterRoleTemplate = ` | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: teleport | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - users | ||
| - groups | ||
| - serviceaccounts | ||
| verbs: | ||
| - impersonate | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| verbs: | ||
| - get | ||
| - apiGroups: | ||
| - "authorization.k8s.io" | ||
| resources: | ||
| - selfsubjectaccessreviews | ||
| - selfsubjectrulesreviews | ||
| verbs: | ||
| - create | ||
| ` | ||
|
|
||
| // KubeClusterRoleBindingTemplate is a template for a Kubernetes ClusterRoleBinding | ||
| // that Teleport uses to access Kubernetes resources. | ||
| const KubeClusterRoleBindingTemplate = ` | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: teleport | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: teleport | ||
| subjects: | ||
| - kind: Group | ||
| name: group_name | ||
| apiGroup: rbac.authorization.k8s.io` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 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 utils | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "time" | ||
|
|
||
| "github.com/aws/aws-sdk-go/service/sts" | ||
| "github.com/aws/aws-sdk-go/service/sts/stsiface" | ||
| "github.com/gravitational/trace" | ||
| "github.com/jonboulle/clockwork" | ||
| ) | ||
|
|
||
| // GenAWSEKSToken creates an AWS token to access EKS clusters. | ||
| // Logic from https://github.com/aws/aws-cli/blob/6c0d168f0b44136fc6175c57c090d4b115437ad1/awscli/customizations/eks/get_token.py#L211-L229 | ||
| func GenAWSEKSToken(stsClient stsiface.STSAPI, clusterID string, clock clockwork.Clock) (string, time.Time, error) { | ||
| const ( | ||
| // The sts GetCallerIdentity request is valid for 15 minutes regardless of this parameters value after it has been | ||
| // signed. | ||
| requestPresignParam = 60 | ||
| // The actual token expiration (presigned STS urls are valid for 15 minutes after timestamp in x-amz-date). | ||
| presignedURLExpiration = 15 * time.Minute | ||
| v1Prefix = "k8s-aws-v1." | ||
| clusterIDHeader = "x-k8s-aws-id" | ||
| ) | ||
|
|
||
| // generate an sts:GetCallerIdentity request and add our custom cluster ID header | ||
| request, _ := stsClient.GetCallerIdentityRequest(&sts.GetCallerIdentityInput{}) | ||
| request.HTTPRequest.Header.Add(clusterIDHeader, clusterID) | ||
|
|
||
| // Sign the request. The expires parameter (sets the x-amz-expires header) is | ||
| // currently ignored by STS, and the token expires 15 minutes after the x-amz-date | ||
| // timestamp regardless. We set it to 60 seconds for backwards compatibility (the | ||
| // parameter is a required argument to Presign(), and authenticators 0.3.0 and older are expecting a value between | ||
| // 0 and 60 on the server side). | ||
| // https://github.com/aws/aws-sdk-go/issues/2167 | ||
| presignedURLString, err := request.Presign(requestPresignParam) | ||
| if err != nil { | ||
| return "", time.Time{}, trace.Wrap(err) | ||
| } | ||
|
|
||
| // Set token expiration to 1 minute before the presigned URL expires for some cushion | ||
| tokenExpiration := clock.Now().Add(presignedURLExpiration - 1*time.Minute) | ||
| return v1Prefix + base64.RawURLEncoding.EncodeToString([]byte(presignedURLString)), tokenExpiration, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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('=')There was a problem hiding this comment.
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