Skip to content

Commit d53ce72

Browse files
authored
Merge pull request #247 from secureCodeBox/minio-aws-eks-irsa
2 parents 8cb9018 + d2848c9 commit d53ce72

7 files changed

Lines changed: 80 additions & 29 deletions

File tree

‎operator/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![operator logo](https://docs.securecodebox.io/img/Logo_Color.svg)
22

3-
The secureCodeBox operator is runniing on kubernetes and the core component of the complete secureCodeBox stack, responsible for operating all scans and ressources.
3+
The secureCodeBox operator is running on kubernetes and the core component of the complete secureCodeBox stack, responsible for managing all scans and resources.
44

55
<!-- end -->
66

@@ -32,6 +32,8 @@ helm install securecodebox-operator secureCodeBox/operator
3232
| minio.enabled | bool | `true` | |
3333
| minio.resources.requests.memory | string | `"256Mi"` | |
3434
| resources | object | `{"limits":{"cpu":"100m","memory":"30Mi"},"requests":{"cpu":"100m","memory":"20Mi"}}` | CPU/memory resource requests/limits (see: https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/, https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/) |
35+
| s3.authType | string | `"access-secret-key"` | Authentication method. Supports access-secret-key (used by most s3 endpoint) and aws-irsa (Used by AWS EKS IAM Role to Kubenetes Service Account Binding. Support for AWS IRSA is considered experimental in the secureCodeBox) |
36+
| s3.awsStsEndpoint | string | `"https://sts.amazonaws.com"` | STS Endpoint used in AWS IRSA Authentication. Change this to the sts endpoint of your aws region. Only used when s3.authType is set to "aws-irsa" |
3537
| s3.bucket | string | `"my-bucket"` | |
3638
| s3.enabled | bool | `false` | |
3739
| s3.endpoint | string | `"fra1.digitaloceanspaces.com"` | |

‎operator/README.md.gotmpl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![operator logo](https://docs.securecodebox.io/img/Logo_Color.svg)
22

3-
The secureCodeBox operator is runniing on kubernetes and the core component of the complete secureCodeBox stack, responsible for operating all scans and ressources.
3+
The secureCodeBox operator is running on kubernetes and the core component of the complete secureCodeBox stack, responsible for managing all scans and resources.
44

55
<!-- end -->
66

‎operator/controllers/execution/scans/scan_controller.go‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"net/url"
2323
"os"
24+
"strings"
2425
"time"
2526

2627
"github.com/go-logr/logr"
@@ -31,7 +32,8 @@ import (
3132
ctrl "sigs.k8s.io/controller-runtime"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334

34-
"github.com/minio/minio-go/v6"
35+
"github.com/minio/minio-go/v7"
36+
"github.com/minio/minio-go/v7/pkg/credentials"
3537
executionv1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
3638
)
3739

@@ -130,11 +132,11 @@ func (r *ScanReconciler) handleFinalizer(scan *executionv1.Scan) error {
130132
if containsString(scan.ObjectMeta.Finalizers, s3StorageFinalizer) {
131133
bucketName := os.Getenv("S3_BUCKET")
132134
r.Log.V(0).Info("Deleting External Files from FileStorage", "ScanUID", scan.UID)
133-
err := r.MinioClient.RemoveObject(bucketName, fmt.Sprintf("scan-%s/%s", scan.UID, scan.Status.RawResultFile))
135+
err := r.MinioClient.RemoveObject(context.Background(), bucketName, fmt.Sprintf("scan-%s/%s", scan.UID, scan.Status.RawResultFile), minio.RemoveObjectOptions{})
134136
if err != nil && err.Error() != errNotFound {
135137
return err
136138
}
137-
err = r.MinioClient.RemoveObject(bucketName, fmt.Sprintf("scan-%s/findings.json", scan.UID))
139+
err = r.MinioClient.RemoveObject(context.Background(), bucketName, fmt.Sprintf("scan-%s/findings.json", scan.UID), minio.RemoveObjectOptions{})
138140

139141
if err != nil && err.Error() != errNotFound {
140142
return err
@@ -153,7 +155,7 @@ func (r *ScanReconciler) PresignedGetURL(scanID types.UID, filename string, dura
153155
bucketName := os.Getenv("S3_BUCKET")
154156

155157
reqParams := make(url.Values)
156-
rawResultDownloadURL, err := r.MinioClient.PresignedGetObject(bucketName, fmt.Sprintf("scan-%s/%s", string(scanID), filename), duration, reqParams)
158+
rawResultDownloadURL, err := r.MinioClient.PresignedGetObject(context.Background(), bucketName, fmt.Sprintf("scan-%s/%s", string(scanID), filename), duration, reqParams)
157159
if err != nil {
158160
r.Log.Error(err, "Could not get presigned url from s3 or compatible storage provider")
159161
return "", err
@@ -165,7 +167,7 @@ func (r *ScanReconciler) PresignedGetURL(scanID types.UID, filename string, dura
165167
func (r *ScanReconciler) PresignedPutURL(scanID types.UID, filename string, duration time.Duration) (string, error) {
166168
bucketName := os.Getenv("S3_BUCKET")
167169

168-
rawResultDownloadURL, err := r.MinioClient.PresignedPutObject(bucketName, fmt.Sprintf("scan-%s/%s", string(scanID), filename), duration)
170+
rawResultDownloadURL, err := r.MinioClient.PresignedPutObject(context.Background(), bucketName, fmt.Sprintf("scan-%s/%s", string(scanID), filename), duration)
169171
if err != nil {
170172
r.Log.Error(err, "Could not get presigned url from s3 or compatible storage provider")
171173
return "", err
@@ -175,8 +177,6 @@ func (r *ScanReconciler) PresignedPutURL(scanID types.UID, filename string, dura
175177

176178
func (r *ScanReconciler) initS3Connection() *minio.Client {
177179
endpoint := os.Getenv("S3_ENDPOINT")
178-
accessKeyID := os.Getenv("S3_ACCESS_KEY")
179-
secretAccessKey := os.Getenv("S3_SECRET_KEY")
180180
if os.Getenv("S3_PORT") != "" {
181181
endpoint = fmt.Sprintf("%s:%s", endpoint, os.Getenv("S3_PORT"))
182182
}
@@ -186,8 +186,24 @@ func (r *ScanReconciler) initS3Connection() *minio.Client {
186186
useSSL = false
187187
}
188188

189+
var creds *credentials.Credentials
190+
191+
if authType, ok := os.LookupEnv("S3_AUTH_TYPE"); ok && strings.ToLower(authType) == "aws-irsa" {
192+
stsEndpoint := ""
193+
if configuredStsEndpoint, ok := os.LookupEnv("S3_AWS_IRSA_STS_ENDPOINT"); ok {
194+
stsEndpoint = configuredStsEndpoint
195+
}
196+
197+
creds = credentials.NewIAM(stsEndpoint)
198+
} else {
199+
creds = credentials.NewEnvMinio()
200+
}
201+
189202
// Initialize minio client object.
190-
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
203+
minioClient, err := minio.New(endpoint, &minio.Options{
204+
Creds: creds,
205+
Secure: useSSL,
206+
})
191207
if err != nil {
192208
r.Log.Error(err, "Could not create minio client to communicate with s3 or compatible storage provider")
193209
panic(err)

‎operator/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.15
44

55
require (
66
github.com/go-logr/logr v0.1.0
7-
github.com/minio/minio-go/v6 v6.0.50
7+
github.com/minio/minio-go/v7 v7.0.6
88
github.com/onsi/ginkgo v1.11.0
99
github.com/onsi/gomega v1.8.1
1010
k8s.io/api v0.17.2

0 commit comments

Comments
 (0)