Skip to content

Commit 47449d5

Browse files
committed
Address PR comments.
1 parent 1ef1f91 commit 47449d5

File tree

6 files changed

+29
-47
lines changed

6 files changed

+29
-47
lines changed

lib/integrations/awsoidc/eks_enroll_clusters.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,10 @@ func installKubeAgent(ctx context.Context, cfg installKubeAgentParams) error {
718718
vals["enterprise"] = true
719719
}
720720

721-
eksTags := maps.Clone(cfg.eksCluster.Tags)
722-
721+
eksTags := make(map[string]string, len(cfg.eksCluster.Tags))
722+
maps.Copy(eksTags, cfg.eksCluster.Tags)
723723
eksTags[types.OriginLabel] = types.OriginCloud
724+
724725
kubeCluster, err := common.NewKubeClusterFromAWSEKS(aws.ToString(cfg.eksCluster.Name), aws.ToString(cfg.eksCluster.Arn), eksTags)
725726
if err != nil {
726727
return trace.Wrap(err)

lib/kube/proxy/cluster_details.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Teleport
3-
* Copyright (C) 2025 Gravitational, Inc.
3+
* Copyright (C) 2023 Gravitational, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Affero General Public License as published by
@@ -27,7 +27,6 @@ import (
2727
"time"
2828

2929
"github.com/aws/aws-sdk-go-v2/aws"
30-
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
3130
"github.com/aws/aws-sdk-go-v2/service/eks"
3231
"github.com/gravitational/trace"
3332
"github.com/jonboulle/clockwork"
@@ -88,8 +87,9 @@ type kubeDetails struct {
8887
// clusterDetailsConfig contains the configuration for creating a proxied cluster.
8988
type clusterDetailsConfig struct {
9089
// cloudClients is the cloud clients to use for dynamic clusters.
90+
cloudClients cloud.Clients
91+
// awsCloudClients provides AWS SDK clients.
9192
awsCloudClients AWSClientGetter
92-
cloudClients cloud.Clients
9393
// kubeCreds is the credentials to use for the cluster.
9494
kubeCreds kubeCreds
9595
// cluster is the cluster to create a proxied cluster for.
@@ -353,18 +353,13 @@ type EKSClient interface {
353353
eks.DescribeClusterAPIClient
354354
}
355355

356-
// STSClient is the subset of the STS Client interface we use.
357-
type STSClient interface {
358-
stscreds.AssumeRoleAPIClient
359-
}
360-
361356
// AWSClientGetter is an interface for getting an EKS client and an STS client.
362357
type AWSClientGetter interface {
363358
awsconfig.Provider
364359
// GetAWSEKSClient returns AWS EKS client for the specified config.
365-
GetAWSEKSClient(aws.Config) (EKSClient, error)
360+
GetAWSEKSClient(aws.Config) EKSClient
366361
// GetAWSSTSPresignClient returns AWS STS presign client for the specified config.
367-
GetAWSSTSPresignClient(aws.Config) (STSPresignClient, error)
362+
GetAWSSTSPresignClient(aws.Config) STSPresignClient
368363
}
369364

370365
// getAWSClientRestConfig creates a dynamicCredsClient that generates returns credentials to EKS clusters.
@@ -379,15 +374,12 @@ func getAWSClientRestConfig(cloudClients AWSClientGetter, clock clockwork.Clock,
379374
}
380375

381376
cfg, err := cloudClients.GetConfig(ctx, region, opts...)
382-
if err != nil {
383-
return nil, time.Time{}, trace.Wrap(err, "cloudClients.GetConfig")
384-
}
385-
386-
regionalClient, err := cloudClients.GetAWSEKSClient(cfg)
387377
if err != nil {
388378
return nil, time.Time{}, trace.Wrap(err)
389379
}
390380

381+
regionalClient := cloudClients.GetAWSEKSClient(cfg)
382+
391383
eksCfg, err := regionalClient.DescribeCluster(ctx, &eks.DescribeClusterInput{
392384
Name: aws.String(cluster.GetAWSConfig().Name),
393385
})
@@ -405,10 +397,7 @@ func getAWSClientRestConfig(cloudClients AWSClientGetter, clock clockwork.Clock,
405397
return nil, time.Time{}, trace.BadParameter("invalid api endpoint for cluster %q", cluster.GetAWSConfig().Name)
406398
}
407399

408-
stsPresignClient, err := cloudClients.GetAWSSTSPresignClient(cfg)
409-
if err != nil {
410-
return nil, time.Time{}, trace.Wrap(err)
411-
}
400+
stsPresignClient := cloudClients.GetAWSSTSPresignClient(cfg)
412401

413402
token, exp, err := kubeutils.GenAWSEKSToken(ctx, stsPresignClient, cluster.GetAWSConfig().Name, clock)
414403
if err != nil {

lib/kube/proxy/kube_creds_test.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package proxy
2121
import (
2222
"context"
2323
"encoding/base64"
24-
"errors"
2524
"net/url"
2625
"strings"
2726
"testing"
@@ -56,12 +55,12 @@ type mockEKSClientGetter struct {
5655
eksClient *mockEKSAPI
5756
}
5857

59-
func (e *mockEKSClientGetter) GetAWSEKSClient(aws.Config) (EKSClient, error) {
60-
return e.eksClient, nil
58+
func (e *mockEKSClientGetter) GetAWSEKSClient(aws.Config) EKSClient {
59+
return e.eksClient
6160
}
6261

63-
func (e *mockEKSClientGetter) GetAWSSTSPresignClient(aws.Config) (kubeutils.STSPresignClient, error) {
64-
return e.stsPresignClient, nil
62+
func (e *mockEKSClientGetter) GetAWSSTSPresignClient(aws.Config) kubeutils.STSPresignClient {
63+
return e.stsPresignClient
6564
}
6665

6766
type mockSTSPresignAPI struct {
@@ -80,11 +79,8 @@ type mockEKSAPI struct {
8079
}
8180

8281
func (m *mockEKSAPI) ListClusters(ctx context.Context, req *eks.ListClustersInput, _ ...func(*eks.Options)) (*eks.ListClustersOutput, error) {
83-
defer func() {
84-
if m.notify != nil {
85-
m.notify <- struct{}{}
86-
}
87-
}()
82+
defer func() { m.notify <- struct{}{} }()
83+
8884
var names []string
8985
for _, cluster := range m.clusters {
9086
names = append(names, aws.ToString(cluster.Name))
@@ -95,19 +91,16 @@ func (m *mockEKSAPI) ListClusters(ctx context.Context, req *eks.ListClustersInpu
9591
}
9692

9793
func (m *mockEKSAPI) DescribeCluster(_ context.Context, req *eks.DescribeClusterInput, _ ...func(*eks.Options)) (*eks.DescribeClusterOutput, error) {
98-
defer func() {
99-
if m.notify != nil {
100-
m.notify <- struct{}{}
101-
}
102-
}()
94+
defer func() { m.notify <- struct{}{} }()
95+
10396
for _, cluster := range m.clusters {
10497
if aws.ToString(cluster.Name) == aws.ToString(req.Name) {
10598
return &eks.DescribeClusterOutput{
10699
Cluster: cluster,
107100
}, nil
108101
}
109102
}
110-
return nil, errors.New("cluster not found")
103+
return nil, trace.NotFound("cluster %q not found", aws.ToString(req.Name))
111104
}
112105

113106
// Test_DynamicKubeCreds tests the dynamic kube credrentials generator for

lib/kube/proxy/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ func (f *awsClientsGetter) GetConfig(ctx context.Context, region string, optFns
117117
return awsconfig.GetConfig(ctx, region, optFns...)
118118
}
119119

120-
func (f *awsClientsGetter) GetAWSEKSClient(cfg aws.Config) (EKSClient, error) {
121-
return eks.NewFromConfig(cfg), nil
120+
func (f *awsClientsGetter) GetAWSEKSClient(cfg aws.Config) EKSClient {
121+
return eks.NewFromConfig(cfg)
122122
}
123123

124-
func (f *awsClientsGetter) GetAWSSTSPresignClient(cfg aws.Config) (STSPresignClient, error) {
124+
func (f *awsClientsGetter) GetAWSSTSPresignClient(cfg aws.Config) STSPresignClient {
125125
stsClient := sts.NewFromConfig(cfg)
126-
return sts.NewPresignClient(stsClient), nil
126+
return sts.NewPresignClient(stsClient)
127127
}
128128

129129
// CheckAndSetDefaults checks and sets default values

lib/srv/discovery/fetchers/aws-sync/eks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (a *awsFetcher) fetchAssociatedPolicies(ctx context.Context, eksClient EKSC
291291
out, err := p.NextPage(ctx)
292292
if err != nil {
293293
errs = append(errs, err)
294-
continue
294+
break
295295
}
296296
for _, policy := range out.AssociatedAccessPolicies {
297297
associatedPolicies = append(associatedPolicies,

lib/srv/discovery/fetchers/eks.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ type eksFetcher struct {
7070

7171
// EKSClient is the subset of the EKS interface we use in fetchers.
7272
type EKSClient interface {
73-
eks.ListClustersAPIClient
7473
eks.DescribeClusterAPIClient
74+
eks.ListClustersAPIClient
7575

76-
DescribeAccessEntry(ctx context.Context, params *eks.DescribeAccessEntryInput, optFns ...func(*eks.Options)) (*eks.DescribeAccessEntryOutput, error)
77-
76+
AssociateAccessPolicy(ctx context.Context, params *eks.AssociateAccessPolicyInput, optFns ...func(*eks.Options)) (*eks.AssociateAccessPolicyOutput, error)
7877
CreateAccessEntry(ctx context.Context, params *eks.CreateAccessEntryInput, optFns ...func(*eks.Options)) (*eks.CreateAccessEntryOutput, error)
79-
UpdateAccessEntry(ctx context.Context, params *eks.UpdateAccessEntryInput, optFns ...func(*eks.Options)) (*eks.UpdateAccessEntryOutput, error)
8078
DeleteAccessEntry(ctx context.Context, params *eks.DeleteAccessEntryInput, optFns ...func(*eks.Options)) (*eks.DeleteAccessEntryOutput, error)
81-
AssociateAccessPolicy(ctx context.Context, params *eks.AssociateAccessPolicyInput, optFns ...func(*eks.Options)) (*eks.AssociateAccessPolicyOutput, error)
79+
DescribeAccessEntry(ctx context.Context, params *eks.DescribeAccessEntryInput, optFns ...func(*eks.Options)) (*eks.DescribeAccessEntryOutput, error)
80+
UpdateAccessEntry(ctx context.Context, params *eks.UpdateAccessEntryInput, optFns ...func(*eks.Options)) (*eks.UpdateAccessEntryOutput, error)
8281
}
8382

8483
// STSClient is the subset of the STS interface we use in fetchers.

0 commit comments

Comments
 (0)