Skip to content

Commit

Permalink
convert LDAP/JWT Identity from query to form body
Browse files Browse the repository at this point in the history
HTTP calls get logged through proxies, avoid
sensitive data getting logged by using request
body instead of query params.
  • Loading branch information
harshavardhana committed Aug 26, 2022
1 parent fe4dc65 commit b078c49
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
6 changes: 5 additions & 1 deletion pkg/credentials/iam_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ func initEcsTaskTestServer(expireOn string) *httptest.Server {

func initStsTestServer(expireOn string) *httptest.Server {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
required := []string{"RoleArn", "RoleSessionName", "WebIdentityToken", "Version"}
for _, field := range required {
if _, ok := r.URL.Query()[field]; !ok {
if _, ok := r.Form[field]; !ok {
http.Error(w, fmt.Sprintf("%s missing", field), http.StatusBadRequest)
return
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/credentials/sts_client_grants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2019 MinIO, Inc.
* Copyright 2019-2022 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)

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

req, err := http.NewRequest(http.MethodPost, u.String(), nil)
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
if err != nil {
return AssumeRoleWithClientGrantsResponse{}, err
}

req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

resp, err := clnt.Do(req)
if err != nil {
return AssumeRoleWithClientGrantsResponse{}, err
Expand Down
9 changes: 5 additions & 4 deletions pkg/credentials/sts_ldap_identity.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2019-2021 MinIO, Inc.
* Copyright 2019-2022 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)

Expand Down Expand Up @@ -156,13 +157,13 @@ func (k *LDAPIdentity) Retrieve() (value Value, err error) {
v.Set("DurationSeconds", fmt.Sprintf("%d", int(k.RequestedExpiry.Seconds())))
}

u.RawQuery = v.Encode()

req, err := http.NewRequest(http.MethodPost, u.String(), nil)
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
if err != nil {
return value, stripPassword(err)
}

req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

resp, err := k.Client.Do(req)
if err != nil {
return value, stripPassword(err)
Expand Down
9 changes: 5 additions & 4 deletions pkg/credentials/sts_web_identity.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2019 MinIO, Inc.
* Copyright 2019-2022 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -139,13 +140,13 @@ func getWebIdentityCredentials(clnt *http.Client, endpoint, roleARN, roleSession
return AssumeRoleWithWebIdentityResponse{}, err
}

u.RawQuery = v.Encode()

req, err := http.NewRequest(http.MethodPost, u.String(), nil)
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
if err != nil {
return AssumeRoleWithWebIdentityResponse{}, err
}

req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

resp, err := clnt.Do(req)
if err != nil {
return AssumeRoleWithWebIdentityResponse{}, err
Expand Down

0 comments on commit b078c49

Please sign in to comment.