Skip to content

Commit 57d74d6

Browse files
authored
internal/awsutil: Add suppressing logging sensitive API parameters (#398)
Adds suppressing logging sensitive API parameters marked with the `sensitive` trait. This prevents the API type's `String` method returning a string representation of the API type with sensitive fields printed such as keys and passwords. Related to aws/aws-sdk-go#2310 Fixes #251
1 parent c3e1aed commit 57d74d6

File tree

261 files changed

+562
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+562
-503
lines changed

CHANGELOG_PENDING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ Deprecations
1010
* Removes support for deprecated Go versions ([#393](https://github.com/aws/aws-sdk-go-v2/pull/393))
1111
* Removes support for Go version specific files from the SDK. Also removes irrelevant build tags, and updates the README.md file.
1212
* Raises the minimum supported version to Go 1.11 for the SDK. Older versions may work, but are not actively supported
13-
13+
1414
SDK Features
1515
---
1616

1717
SDK Enhancements
1818
---
19+
* `internal/awsutil`: Add suppressing logging sensitive API parameters ([#398](https://github.com/aws/aws-sdk-go-v2/pull/398))
20+
* Adds suppressing logging sensitive API parameters marked with the `sensitive` trait. This prevents the API type's `String` method returning a string representation of the API type with sensitive fields printed such as keys and passwords.
21+
* Related to [aws/aws-sdk-go#2310](https://github.com/aws/aws-sdk-go/pull/2310)
22+
* Fixes [#251](https://github.com/aws/aws-sdk-go-v2/issues/251)
1923
* `aws/request` : Retryer is now a named field on Request. ([#393](https://github.com/aws/aws-sdk-go-v2/pull/393))
2024

2125
SDK Bugs
2226
---
23-
* `private/model/api`: Fixes broken test for code generation. ([#393](https://github.com/aws/aws-sdk-go-v2/pull/393))

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ SDK_EXAMPLES_PKGS=./example/...
1919
SDK_MODELS_PKGS=./models/...
2020
SDK_ALL_PKGS=${SDK_COMPA_PKGS} ${SDK_EXAMPLES_PKGS} ${SDK_MODELS_PKGS}
2121

22-
SDK_V1_USAGE=$(shell go list -f '''{{ if not .Standard }}{{ range $$_, $$name := .Imports }} * {{ $$.ImportPath }} -> {{ $$name }}{{ print "\n" }}{{ end }}{{ end }}''' ./... | sort -u | grep '''/aws-sdk-go/''')
2322

2423
all: generate unit
2524

@@ -144,7 +143,9 @@ vet:
144143

145144
sdkv1check:
146145
@echo "Checking for usage of AWS SDK for Go v1"
147-
@if [ ! -z "${SDK_V1_USAGE}" ]; then echo "Using of V1 SDK packages"; echo "${SDK_V1_USAGE}"; exit 1; fi
146+
@sdkv1usage=`go list -test -f '''{{ if not .Standard }}{{ range $$_, $$name := .Imports }} * {{ $$.ImportPath }} -> {{ $$name }}{{ print "\n" }}{{ end }}{{ range $$_, $$name := .TestImports }} *: {{ $$.ImportPath }} -> {{ $$name }}{{ print "\n" }}{{ end }}{{ end}}''' ./... | sort -u | grep '''/aws-sdk-go/'''`; \
147+
echo "$$sdkv1usage"; \
148+
if [ "$$sdkv1usage" != "" ]; then exit 1; fi
148149

149150
################
150151
# Dependencies #

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ require (
44
github.com/davecgh/go-spew v1.1.1 // indirect
55
github.com/go-sql-driver/mysql v1.4.0
66
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
7-
github.com/pkg/errors v0.8.0
87
github.com/pmezard/go-difflib v1.0.0 // indirect
98
github.com/stretchr/testify v1.2.2 // indirect
109
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc
1110
google.golang.org/appengine v1.2.0 // indirect
1211
)
12+
13+
go 1.11

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
55
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
66
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
77
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
8-
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
9-
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
108
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
119
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1210
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=

internal/awsutil/string_value.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,27 @@ func stringValue(v reflect.Value, indent int, buf *bytes.Buffer) {
2323
case reflect.Struct:
2424
buf.WriteString("{\n")
2525

26-
names := []string{}
2726
for i := 0; i < v.Type().NumField(); i++ {
28-
name := v.Type().Field(i).Name
29-
f := v.Field(i)
30-
if name[0:1] == strings.ToLower(name[0:1]) {
27+
ft := v.Type().Field(i)
28+
fv := v.Field(i)
29+
30+
if ft.Name[0:1] == strings.ToLower(ft.Name[0:1]) {
3131
continue // ignore unexported fields
3232
}
33-
if (f.Kind() == reflect.Ptr || f.Kind() == reflect.Slice) && f.IsNil() {
33+
if (fv.Kind() == reflect.Ptr || fv.Kind() == reflect.Slice) && fv.IsNil() {
3434
continue // ignore unset fields
3535
}
36-
names = append(names, name)
37-
}
3836

39-
for i, n := range names {
40-
val := v.FieldByName(n)
4137
buf.WriteString(strings.Repeat(" ", indent+2))
42-
buf.WriteString(n + ": ")
43-
stringValue(val, indent+2, buf)
38+
buf.WriteString(ft.Name + ": ")
4439

45-
if i < len(names)-1 {
46-
buf.WriteString(",\n")
40+
if tag := ft.Tag.Get("sensitive"); tag == "true" {
41+
buf.WriteString("<sensitive>")
42+
} else {
43+
stringValue(fv, indent+2, buf)
4744
}
45+
46+
buf.WriteString(",\n")
4847
}
4948

5049
buf.WriteString("\n" + strings.Repeat(" ", indent) + "}")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package awsutil_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/internal/awsutil"
8+
)
9+
10+
type testStruct struct {
11+
Field1 string
12+
Field2 *string
13+
Field3 []byte `sensitive:"true"`
14+
Value []string
15+
}
16+
17+
func TestStringValue(t *testing.T) {
18+
cases := map[string]struct {
19+
Value interface{}
20+
Expect string
21+
}{
22+
"general": {
23+
Value: testStruct{
24+
Field1: "abc123",
25+
Field2: aws.String("abc123"),
26+
Field3: []byte("don't show me"),
27+
Value: []string{
28+
"first",
29+
"second",
30+
},
31+
},
32+
Expect: `{
33+
Field1: "abc123",
34+
Field2: "abc123",
35+
Field3: <sensitive>,
36+
Value: ["first","second"],
37+
38+
}`,
39+
},
40+
}
41+
42+
for d, c := range cases {
43+
t.Run(d, func(t *testing.T) {
44+
actual := awsutil.StringValue(c.Value)
45+
if e, a := c.Expect, actual; e != a {
46+
t.Errorf("expect:\n%v\nactual:\n%v\n", e, a)
47+
}
48+
})
49+
}
50+
}

private/model/api/shape.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ type Shape struct {
116116
// Flags that the shape cannot be rename. Prevents the shape from being
117117
// renamed further by the Input/Output.
118118
AliasedShapeName bool
119+
120+
// Sensitive types should not be logged by SDK type loggers.
121+
Sensitive bool `json:"sensitive"`
119122
}
120123

121124
// ErrorCodeName will return the error shape's name formated for
@@ -509,6 +512,10 @@ func (ref *ShapeRef) GoTags(toplevel bool, isRequired bool) string {
509512
tags = append(tags, ShapeTag{"idempotencyToken", "true"})
510513
}
511514

515+
if ref.Shape.Sensitive {
516+
tags = append(tags, ShapeTag{"sensitive", "true"})
517+
}
518+
512519
if ref.Ignore {
513520
tags = append(tags, ShapeTag{"ignore", "true"})
514521
}

service/acm/api_op_ExportCertificate.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acm/api_op_ImportCertificate.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/alexaforbusiness/api_op_CreateContact.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)