Skip to content
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

Support additional certificate #478

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile.kubetest2
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ RUN cp kubernetes-version.txt /info/
RUN mv kubernetes/*/bin/* /bin/
RUN rm -rf /workdir
COPY --from=builder /usr/local/go/bin/* /bin/
RUN mkdir -p /etc/ssl/certs/
COPY certs.pem /etc/ssl/certs/certs.pem
Comment on lines +59 to +60
Copy link
Member

Choose a reason for hiding this comment

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

We should either use an ARG for this or just mount the certs in with a volume at runtime

Empty file added certs.pem
Empty file.
2 changes: 1 addition & 1 deletion kubetest2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ require (
github.com/aws/smithy-go v1.20.1
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/octago/sflags v0.2.0
github.com/pkg/errors v0.9.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.21.0
Expand Down Expand Up @@ -191,6 +190,7 @@ require (
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
Expand Down
43 changes: 39 additions & 4 deletions kubetest2/internal/awssdk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,53 @@ package awssdk

import (
"context"
"crypto/tls"
"crypto/x509"
"io/ioutil"
"k8s.io/klog"
"net/http"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"k8s.io/klog/v2"
)

// NewConfig returns an AWS SDK config
// It will panic if the cnfig cannot be created
func NewConfig() aws.Config {
c, err := config.LoadDefaultConfig(context.TODO())
// It will panic if the config cannot be created
func NewConfig(optFns ...func(*config.LoadOptions) error) aws.Config {
c, err := config.LoadDefaultConfig(
context.TODO(),
optFns...,
)
if err != nil {
klog.Fatalf("failed to create AWS SDK config: %v", err)
}
return c
}

// WithCertsPath loads certificates from a file path
func WithCertsPath(certsPath string) func(*config.LoadOptions) error {
return func(lo *config.LoadOptions) error {
if certsPath != "" {
klog.Infof("Loading certificates from file: %s", certsPath)
certData, err := ioutil.ReadFile(certsPath)
if err != nil {
klog.Fatalf("Failed to read certificates from file: %v", err)
return err
}
klog.Infof("Certificates loaded from file")
lo.HTTPClient = newHTTPClientWithCerts(certData)
}
return nil
}
}

func newHTTPClientWithCerts(certData []byte) *http.Client {
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(certData)
transport := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: pool,
},
}
return &http.Client{Transport: transport}
}
19 changes: 18 additions & 1 deletion kubetest2/internal/deployers/eksapi/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/aws/aws-k8s-tester/kubetest2/internal/metrics"
"github.com/aws/aws-k8s-tester/kubetest2/internal/util"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
"github.com/octago/sflags/gen/gpflag"
Expand Down Expand Up @@ -74,6 +76,7 @@ type deployerOptions struct {
UnmanagedNodes bool `flag:"unmanaged-nodes" desc:"Use an AutoScalingGroup instead of an EKS-managed nodegroup. Requires --ami"`
UpClusterHeaders []string `flag:"up-cluster-header" desc:"Additional header to add to eks:CreateCluster requests. Specified in the same format as curl's -H flag."`
UserDataFormat string `flag:"user-data-format" desc:"Format of the node instance user data"`
CertsPath string `flag:"certs-path" desc:"Optional, path to the certs that would be applied to aws clients"`
Issacwww marked this conversation as resolved.
Show resolved Hide resolved
}

// NewDeployer implements deployer.New for EKS using the EKS (and other AWS) API(s) directly (no cloudformation)
Expand Down Expand Up @@ -102,9 +105,23 @@ func (d *deployer) Version() string {
return internal.Version
}

func initAWSConfig(d *deployer) aws.Config {
opts := []func(*config.LoadOptions) error{
config.WithRegion(d.Region),
}

if d.CertsPath != "" {
klog.Infof("certificate file provided: %s", d.CertsPath)
opts = append(opts, awssdk.WithCertsPath(d.CertsPath))
}

return awssdk.NewConfig(opts...)
}


func (d *deployer) Init() error {
d.initTime = time.Now()
awsConfig := awssdk.NewConfig()
awsConfig := initAWSConfig(d)
d.awsClients = newAWSClients(awsConfig, d.EKSEndpointURL)
resourceID := ResourcePrefix + "-" + d.commonOptions.RunID()
if d.deployerOptions.EmitMetrics {
Expand Down
Loading