Skip to content

Commit bdfa6dc

Browse files
authored
Support Usage API talk to MinIO over TLS with Insecure (#241)
* Support Usage API talk to MinIO over TLS with Insecure Right now if MinIO is running with TLS, and the certificate is not trusted by console, we fail usage requests. We need to leverage the support for insecure connections so we can read Health Checks and Usage information. * Remove unusd import
1 parent 6eb5731 commit bdfa6dc

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

restapi/admin_tenants.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func getTenantScheme(mi *operator.Tenant) string {
178178
return scheme
179179
}
180180

181-
func getTenantAdminClient(ctx context.Context, client K8sClient, namespace, tenantName, serviceName, scheme string) (*madmin.AdminClient, error) {
181+
func getTenantAdminClient(ctx context.Context, client K8sClient, namespace, tenantName, serviceName, scheme string, insecure bool) (*madmin.AdminClient, error) {
182182
// get admin credentials from secret
183183
creds, err := client.getSecret(ctx, namespace, fmt.Sprintf("%s-secret", tenantName), metav1.GetOptions{})
184184
if err != nil {
@@ -194,11 +194,7 @@ func getTenantAdminClient(ctx context.Context, client K8sClient, namespace, tena
194194
log.Println("tenant's secret doesn't contain secretkey")
195195
return nil, errorGeneric
196196
}
197-
service, err := client.getService(ctx, namespace, serviceName, metav1.GetOptions{})
198-
if err != nil {
199-
return nil, err
200-
}
201-
mAdmin, pErr := NewAdminClient(scheme+"://"+net.JoinHostPort(service.Spec.ClusterIP, strconv.Itoa(operator.MinIOPort)), string(accessKey), string(secretkey))
197+
mAdmin, pErr := NewAdminClientWithInsecure(scheme+"://"+net.JoinHostPort(serviceName, strconv.Itoa(operator.MinIOPort)), string(accessKey), string(secretkey), insecure)
202198
if pErr != nil {
203199
return nil, pErr.Cause
204200
}
@@ -858,23 +854,19 @@ func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenan
858854
log.Println("error getting minioTenant:", err)
859855
return nil, err
860856
}
857+
minTenant.EnsureDefaults()
861858
tenantScheme := getTenantScheme(minTenant)
862859

863-
svcName := minTenant.Spec.ServiceName
864-
if svcName == "" {
865-
svcName = minTenant.Name
866-
// TODO:
867-
// 1 get tenant services
868-
// 2 filter out cluster ip svc
869-
}
860+
svcName := fmt.Sprintf("%s.%s.svc.cluster.local", minTenant.MinIOCIServiceName(), minTenant.Namespace)
870861

871862
mAdmin, err := getTenantAdminClient(
872863
ctx,
873864
k8sClient,
874865
params.Namespace,
875866
params.Tenant,
876867
svcName,
877-
tenantScheme)
868+
tenantScheme,
869+
true)
878870
if err != nil {
879871
log.Println("error getting tenant's admin client:", err)
880872
return nil, err

restapi/admin_tenants_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
9191
tenantName string
9292
serviceName string
9393
scheme string
94+
insecure bool
9495
}
9596
tests := []struct {
9697
name string
@@ -236,7 +237,7 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
236237
k8sclientGetSecretMock = tt.mockGetSecret
237238
k8sclientGetServiceMock = tt.mockGetService
238239
t.Run(tt.name, func(t *testing.T) {
239-
got, err := getTenantAdminClient(tt.args.ctx, tt.args.client, tt.args.namespace, tt.args.tenantName, tt.args.serviceName, tt.args.scheme)
240+
got, err := getTenantAdminClient(tt.args.ctx, tt.args.client, tt.args.namespace, tt.args.tenantName, tt.args.serviceName, tt.args.scheme, tt.args.insecure)
240241
if err != nil {
241242
if tt.wantErr {
242243
return

restapi/client-admin.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func NewAdminClientWithInsecure(url, accessKey, secretKey string, insecure bool)
5454
if err != nil {
5555
return nil, err.Trace(url)
5656
}
57-
s3Client.SetCustomTransport(STSClient.Transport)
57+
stsClient := PrepareSTSClient(insecure)
58+
s3Client.SetCustomTransport(stsClient.Transport)
5859
return s3Client, nil
5960
}
6061

@@ -266,7 +267,8 @@ func newAdminFromClaims(claims *models.Principal) (*madmin.AdminClient, error) {
266267
if err != nil {
267268
return nil, err
268269
}
269-
adminClient.SetCustomTransport(STSClient.Transport)
270+
stsClient := PrepareSTSClient(false)
271+
adminClient.SetCustomTransport(stsClient.Transport)
270272
return adminClient, nil
271273
}
272274

restapi/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
164164

165165
// STSClient contains http.client configuration need it by STSAssumeRole
166166
var (
167-
STSClient = PrepareSTSClient()
168167
MinioEndpoint = getMinIOServer()
169168
)
170169

@@ -204,8 +203,9 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
204203
Location: location,
205204
DurationSeconds: xjwt.GetConsoleSTSAndJWTDurationInSeconds(),
206205
}
206+
stsClient := PrepareSTSClient(false)
207207
stsAssumeRole := &credentials.STSAssumeRole{
208-
Client: STSClient,
208+
Client: stsClient,
209209
STSEndpoint: MinioEndpoint,
210210
Options: opts,
211211
}
@@ -234,10 +234,11 @@ func getConsoleCredentialsFromSession(claims *models.Principal) *credentials.Cre
234234
// from the provided jwt
235235
func newMinioClient(claims *models.Principal) (*minio.Client, error) {
236236
creds := getConsoleCredentialsFromSession(claims)
237+
stsClient := PrepareSTSClient(false)
237238
minioClient, err := minio.New(getMinIOEndpoint(), &minio.Options{
238239
Creds: creds,
239240
Secure: getMinIOEndpointIsSecure(),
240-
Transport: STSClient.Transport,
241+
Transport: stsClient.Transport,
241242
})
242243
if err != nil {
243244
return nil, err

restapi/tls.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,24 @@ var (
3030
certDontExists = "File certificate doesn't exists: %s"
3131
)
3232

33-
func prepareSTSClientTransport() *http.Transport {
33+
func prepareSTSClientTransport(insecure bool) *http.Transport {
3434
// This takes github.com/minio/minio/pkg/madmin/transport.go as an example
3535
//
3636
// DefaultTransport - this default transport is similar to
3737
// http.DefaultTransport but with additional param DisableCompression
3838
// is set to true to avoid decompressing content with 'gzip' encoding.
39+
40+
// Keep TLS config.
41+
tlsConfig := &tls.Config{
42+
// Can't use SSLv3 because of POODLE and BEAST
43+
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
44+
// Can't use TLSv1.1 because of RC4 cipher usage
45+
MinVersion: tls.VersionTLS12,
46+
}
47+
if insecure {
48+
tlsConfig.InsecureSkipVerify = true
49+
}
50+
3951
DefaultTransport := &http.Transport{
4052
Proxy: http.ProxyFromEnvironment,
4153
DialContext: (&net.Dialer{
@@ -49,6 +61,7 @@ func prepareSTSClientTransport() *http.Transport {
4961
TLSHandshakeTimeout: 10 * time.Second,
5062
ExpectContinueTimeout: 1 * time.Second,
5163
DisableCompression: true,
64+
TLSClientConfig: tlsConfig,
5265
}
5366
// If Minio instance is running with TLS enabled and it's using a self-signed certificate
5467
// or a certificate issued by a custom certificate authority we prepare a new custom *http.Transport
@@ -86,10 +99,11 @@ func prepareSTSClientTransport() *http.Transport {
8699

87100
// PrepareSTSClient returns an http.Client with custom configurations need it by *credentials.STSAssumeRole
88101
// custom configurations include the use of CA certificates
89-
func PrepareSTSClient() *http.Client {
90-
transport := prepareSTSClientTransport()
102+
func PrepareSTSClient(insecure bool) *http.Client {
103+
transport := prepareSTSClientTransport(insecure)
91104
// Return http client with default configuration
92-
return &http.Client{
105+
c := &http.Client{
93106
Transport: transport,
94107
}
108+
return c
95109
}

0 commit comments

Comments
 (0)