Skip to content

Commit a5dc7d2

Browse files
convert LDAP/JWT Identity from query to form body (#1688)
HTTP calls get logged through proxies, avoid sensitive data getting logged by using request body instead of query params.
1 parent fe4dc65 commit a5dc7d2

5 files changed

+25
-32
lines changed

pkg/credentials/iam_aws_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ func initEcsTaskTestServer(expireOn string) *httptest.Server {
137137

138138
func initStsTestServer(expireOn string) *httptest.Server {
139139
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
140+
if err := r.ParseForm(); err != nil {
141+
http.Error(w, err.Error(), http.StatusBadRequest)
142+
return
143+
}
140144
required := []string{"RoleArn", "RoleSessionName", "WebIdentityToken", "Version"}
141145
for _, field := range required {
142-
if _, ok := r.URL.Query()[field]; !ok {
146+
if _, ok := r.Form[field]; !ok {
143147
http.Error(w, fmt.Sprintf("%s missing", field), http.StatusBadRequest)
144148
return
145149
}

pkg/credentials/sts_client_grants.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
3-
* Copyright 2019 MinIO, Inc.
3+
* Copyright 2019-2022 MinIO, Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import (
2525
"io/ioutil"
2626
"net/http"
2727
"net/url"
28+
"strings"
2829
"time"
2930
)
3031

@@ -122,12 +123,14 @@ func getClientGrantsCredentials(clnt *http.Client, endpoint string,
122123
if err != nil {
123124
return AssumeRoleWithClientGrantsResponse{}, err
124125
}
125-
u.RawQuery = v.Encode()
126126

127-
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
127+
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
128128
if err != nil {
129129
return AssumeRoleWithClientGrantsResponse{}, err
130130
}
131+
132+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
133+
131134
resp, err := clnt.Do(req)
132135
if err != nil {
133136
return AssumeRoleWithClientGrantsResponse{}, err

pkg/credentials/sts_custom_identity.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ func (c *CustomTokenIdentity) Retrieve() (value Value, err error) {
8989

9090
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
9191
if err != nil {
92-
return value, stripPassword(err)
92+
return value, err
9393
}
9494

9595
resp, err := c.Client.Do(req)
9696
if err != nil {
97-
return value, stripPassword(err)
97+
return value, err
9898
}
9999

100100
defer resp.Body.Close()

pkg/credentials/sts_ldap_identity.go

+7-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
3-
* Copyright 2019-2021 MinIO, Inc.
3+
* Copyright 2019-2022 MinIO, Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import (
2424
"io/ioutil"
2525
"net/http"
2626
"net/url"
27+
"strings"
2728
"time"
2829
)
2930

@@ -105,22 +106,6 @@ func LDAPIdentityExpiryOpt(d time.Duration) LDAPIdentityOpt {
105106
}
106107
}
107108

108-
func stripPassword(err error) error {
109-
urlErr, ok := err.(*url.Error)
110-
if ok {
111-
u, _ := url.Parse(urlErr.URL)
112-
if u == nil {
113-
return urlErr
114-
}
115-
values := u.Query()
116-
values.Set("LDAPPassword", "xxxxx")
117-
u.RawQuery = values.Encode()
118-
urlErr.URL = u.String()
119-
return urlErr
120-
}
121-
return err
122-
}
123-
124109
// NewLDAPIdentityWithSessionPolicy returns new credentials object that uses
125110
// LDAP Identity with a specified session policy. The `policy` parameter must be
126111
// a JSON string specifying the policy document.
@@ -156,16 +141,16 @@ func (k *LDAPIdentity) Retrieve() (value Value, err error) {
156141
v.Set("DurationSeconds", fmt.Sprintf("%d", int(k.RequestedExpiry.Seconds())))
157142
}
158143

159-
u.RawQuery = v.Encode()
160-
161-
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
144+
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
162145
if err != nil {
163-
return value, stripPassword(err)
146+
return value, err
164147
}
165148

149+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
150+
166151
resp, err := k.Client.Do(req)
167152
if err != nil {
168-
return value, stripPassword(err)
153+
return value, err
169154
}
170155

171156
defer resp.Body.Close()

pkg/credentials/sts_web_identity.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
3-
* Copyright 2019 MinIO, Inc.
3+
* Copyright 2019-2022 MinIO, Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import (
2626
"net/http"
2727
"net/url"
2828
"strconv"
29+
"strings"
2930
"time"
3031
)
3132

@@ -139,13 +140,13 @@ func getWebIdentityCredentials(clnt *http.Client, endpoint, roleARN, roleSession
139140
return AssumeRoleWithWebIdentityResponse{}, err
140141
}
141142

142-
u.RawQuery = v.Encode()
143-
144-
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
143+
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
145144
if err != nil {
146145
return AssumeRoleWithWebIdentityResponse{}, err
147146
}
148147

148+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
149+
149150
resp, err := clnt.Do(req)
150151
if err != nil {
151152
return AssumeRoleWithWebIdentityResponse{}, err

0 commit comments

Comments
 (0)