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

feat: add support for skip tls verify in minio #4649

Merged
merged 2 commits into from
Nov 22, 2023
Merged
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
1 change: 1 addition & 0 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func main() {
cfg.StorageToken,
cfg.StorageBucket,
cfg.StorageSSL,
cfg.StorageSkipVerify,
)
if err = minioClient.Connect(); err != nil {
ui.ExitOnError("Connecting to minio", err)
Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/init/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (r *InitRunner) Run(ctx context.Context, execution testkube.Execution) (res
// add copy files in case object storage is set
if r.Params.Endpoint != "" && !r.Params.CloudMode {
output.PrintLogf("%s Fetching uploads from object store %s...", ui.IconFile, r.Params.Endpoint)
minioClient := minio.NewClient(r.Params.Endpoint, r.Params.AccessKeyID, r.Params.SecretAccessKey, r.Params.Region, r.Params.Token, r.Params.Bucket, r.Params.Ssl)
minioClient := minio.NewClient(r.Params.Endpoint, r.Params.AccessKeyID, r.Params.SecretAccessKey, r.Params.Region, r.Params.Token, r.Params.Bucket, r.Params.Ssl, r.Params.SkipVerify)
fp := content.NewCopyFilesPlacer(minioClient)
fp.PlaceFiles(ctx, execution.TestName, execution.BucketName)
} else if r.Params.CloudMode {
Expand Down
1 change: 1 addition & 0 deletions internal/app/api/v1/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ func (s *TestkubeAPI) getArtifactStorage(bucket string) (storage.ArtifactsStorag
s.storageParams.Token,
bucket,
s.storageParams.SSL,
s.storageParams.SkipVerify,
)
if err := minioClient.Connect(); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type TestkubeAPI struct {

type storageParams struct {
SSL bool
SkipVerify bool
Endpoint string
AccessKeyId string
SecretAccessKey string
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Config struct {
StorageRegion string `envconfig:"STORAGE_REGION" default:""`
StorageToken string `envconfig:"STORAGE_TOKEN" default:""`
StorageSSL bool `envconfig:"STORAGE_SSL" default:"false"`
StorageSkipVerify bool `envconfig:"STORAGE_SKIP_VERIFY" default:"false"`
ScrapperEnabled bool `envconfig:"SCRAPPERENABLED" default:"false"`
LogsBucket string `envconfig:"LOGS_BUCKET" default:""`
LogsStorage string `envconfig:"LOGS_STORAGE" default:""`
Expand Down
1 change: 1 addition & 0 deletions pkg/envs/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Params struct {
Token string // RUNNER_TOKEN
Bucket string // RUNNER_BUCKET
Ssl bool // RUNNER_SSL
SkipVerify bool `envconfig:"RUNNER_SKIP_VERIFY" default:"false"` // RUNNER_SKIP_VERIFY
ScrapperEnabled bool // RUNNER_SCRAPPERENABLED
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
Expand Down
4 changes: 4 additions & 0 deletions pkg/executor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ var RunnerEnvVars = []corev1.EnvVar{
Name: "RUNNER_SSL",
Value: getOr("STORAGE_SSL", "false"),
},
{
Name: "RUNNER_SKIP_VERIFY",
Value: getOr("STORAGE_SKIP_VERIFY", "false"),
},
{
Name: "RUNNER_SCRAPPERENABLED",
Value: getOr("SCRAPPERENABLED", "false"),
Expand Down
1 change: 1 addition & 0 deletions pkg/executor/containerexecutor/containerexecutor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func TestNewExecutorJobSpecWithArgs(t *testing.T) {
{Name: "RUNNER_TOKEN", Value: ""},
{Name: "RUNNER_BUCKET", Value: ""},
{Name: "RUNNER_SSL", Value: "false"},
{Name: "RUNNER_SKIP_VERIFY", Value: "false"},
{Name: "RUNNER_SCRAPPERENABLED", Value: "false"},
{Name: "RUNNER_DATADIR", Value: "/data"},
{Name: "RUNNER_CDEVENTS_TARGET", Value: ""},
Expand Down
1 change: 1 addition & 0 deletions pkg/executor/scraper/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ func getMinIOLoader(params envs.Params) (*scraper.MinIOUploader, error) {
params.Token,
params.Bucket,
params.Ssl,
params.SkipVerify,
)
}
8 changes: 4 additions & 4 deletions pkg/executor/scraper/minio_scraper_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestMinIOScraper_Archive_Integration(t *testing.T) {

extractor := scraper.NewArchiveFilesystemExtractor(filesystem.NewOSFileSystem())

loader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-asdf", false)
loader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-asdf", false, false)
if err != nil {
t.Fatalf("error creating minio loader: %v", err)
}
Expand All @@ -77,7 +77,7 @@ func TestMinIOScraper_Archive_Integration(t *testing.T) {
t.Fatalf("error scraping: %v", err)
}

c := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-asdf", false)
c := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-asdf", false, false)
assert.NoError(t, c.Connect())
artifacts, err := c.ListFiles(context.Background(), "test-bucket-asdf")
if err != nil {
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestMinIOScraper_Recursive_Integration(t *testing.T) {
extractor := scraper.NewRecursiveFilesystemExtractor(filesystem.NewOSFileSystem())

bucketName := "test-bucket-asdf1"
loader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", bucketName, false)
loader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", bucketName, false, false)
if err != nil {
t.Fatalf("error creating minio loader: %v", err)
}
Expand All @@ -145,7 +145,7 @@ func TestMinIOScraper_Recursive_Integration(t *testing.T) {
t.Fatalf("error scraping: %v", err)
}

c := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", bucketName, false)
c := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", bucketName, false, false)
assert.NoError(t, c.Connect())
artifacts, err := c.ListFiles(context.Background(), bucketName)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/executor/scraper/minio_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (

type MinIOUploader struct {
Endpoint, AccessKeyID, SecretAccessKey, Region, Token, Bucket string
Ssl bool
Ssl, SkipVerify bool
client *minio.Client
}

func NewMinIOUploader(endpoint, accessKeyID, secretAccessKey, region, token, bucket string, ssl bool) (*MinIOUploader, error) {
func NewMinIOUploader(endpoint, accessKeyID, secretAccessKey, region, token, bucket string, ssl, skipVerify bool) (*MinIOUploader, error) {
l := &MinIOUploader{
Endpoint: endpoint,
AccessKeyID: accessKeyID,
Expand All @@ -29,9 +29,10 @@ func NewMinIOUploader(endpoint, accessKeyID, secretAccessKey, region, token, buc
Token: token,
Bucket: bucket,
Ssl: ssl,
SkipVerify: skipVerify,
}

client := minio.NewClient(l.Endpoint, l.AccessKeyID, l.SecretAccessKey, l.Region, l.Token, l.Bucket, l.Ssl)
client := minio.NewClient(l.Endpoint, l.AccessKeyID, l.SecretAccessKey, l.Region, l.Token, l.Bucket, l.Ssl, l.SkipVerify)
err := client.Connect()
if err != nil {
return nil, errors.Errorf("error occured creating minio client: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/executor/scraper/minio_uploader_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestMinIOUploader_Upload_Tarball_Integration(t *testing.T) {
t.Parallel()

// Create a new MinIO uploader with the appropriate configuration
uploader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-fsgds", false)
uploader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-fsgds", false, false)
if err != nil {
t.Fatalf("failed to create MinIO loader: %v", err)
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestMinIOUploader_Upload_Tarball_Integration(t *testing.T) {
t.Fatalf("failed to save file to MinIO: %v", err)
}

m := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-fsgds", false)
m := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-fsgds", false, false)
if err := m.Connect(); err != nil {
t.Fatalf("error conecting to minio: %v", err)
}
Expand All @@ -69,7 +69,7 @@ func TestMinIOUploader_Upload_Raw_Integration(t *testing.T) {
t.Parallel()

// Create a new MinIO loader with the appropriate configuration
uploader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-hgfhfg", false)
uploader, err := scraper.NewMinIOUploader("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-hgfhfg", false, false)
if err != nil {
t.Fatalf("failed to create MinIO loader: %v", err)
}
Expand All @@ -93,7 +93,7 @@ func TestMinIOUploader_Upload_Raw_Integration(t *testing.T) {
t.Fatalf("failed to save file to MinIO: %v", err)
}

m := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-hgfhfg", false)
m := minio.NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-hgfhfg", false, false)
if err := m.Connect(); err != nil {
t.Fatalf("error conecting to minio: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/minio/artifacts_storage_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestArtifactClient(t *testing.T) {
t.Fatalf("unable to create direct minio client: %v", err)
}
// Prepare MinIO client
minioClient := NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-fsdf", false)
minioClient := NewClient("localhost:9000", "minio99", "minio123", "us-east-1", "", "test-bucket-fsdf", false, false)
if err := minioClient.Connect(); err != nil {
t.Fatalf("unable to connect to minio: %v", err)
}
Expand Down
18 changes: 15 additions & 3 deletions pkg/storage/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package minio
import (
"bytes"
"context"
"crypto/tls"
"fmt"
"hash/fnv"
"io"
Expand Down Expand Up @@ -37,6 +38,7 @@ type Client struct {
accessKeyID string
secretAccessKey string
ssl bool
skipVerify bool
region string
token string
bucket string
Expand All @@ -45,13 +47,14 @@ type Client struct {
}

// NewClient returns new MinIO client
func NewClient(endpoint, accessKeyID, secretAccessKey, region, token, bucket string, ssl bool) *Client {
func NewClient(endpoint, accessKeyID, secretAccessKey, region, token, bucket string, ssl, skipVerify bool) *Client {
c := &Client{
region: region,
accessKeyID: accessKeyID,
secretAccessKey: secretAccessKey,
token: token,
ssl: ssl,
skipVerify: skipVerify,
bucket: bucket,
Endpoint: endpoint,
Log: log.DefaultLogger,
Expand All @@ -73,9 +76,18 @@ func (c *Client) Connect() error {
if c.accessKeyID != "" && c.secretAccessKey != "" {
creds = credentials.NewStaticV4(c.accessKeyID, c.secretAccessKey, c.token)
}
transport, err := minio.DefaultTransport(c.ssl)
if err != nil {
c.Log.Errorw("error creating minio transport", "error", err)
return err
}
tlsConfig := &tls.Config{}
tlsConfig.InsecureSkipVerify = c.skipVerify
transport.TLSClientConfig = tlsConfig
opts := &minio.Options{
Creds: creds,
Secure: c.ssl,
Creds: creds,
Secure: c.ssl,
Transport: transport,
}
if c.region != "" {
opts.Region = c.region
Expand Down
Loading