Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce alternatives to %v and %+v #1639

Merged
merged 33 commits into from
Jul 15, 2021
Merged

Conversation

theunrepentantgeek
Copy link
Member

@theunrepentantgeek theunrepentantgeek commented Jul 9, 2021

What this PR does / why we need it:

The %v and %+v format specifiers blindly dump all of the contents of any struct into the string - which can result in disclosure of secrets and other PII into log files where it is uncontrolled; this is a potential security and GDPR issue we need to prevent.

This PR adds a check to enforce that the format specifiers %v and %+v are not used.

Closes #1585

How does this PR make you feel:
gif

@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2021

Codecov Report

Merging #1639 (da1d489) into master (02973a1) will decrease coverage by 0.04%.
The diff coverage is 19.49%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1639      +/-   ##
==========================================
- Coverage   67.08%   67.04%   -0.05%     
==========================================
  Files         205      205              
  Lines       14840    14864      +24     
==========================================
+ Hits         9956     9966      +10     
- Misses       4126     4141      +15     
+ Partials      758      757       -1     
Impacted Files Coverage Δ
hack/generator/cmd/gen_kustomize.go 0.00% <0.00%> (ø)
hack/generator/cmd/gen_types.go 0.00% <0.00%> (ø)
hack/generator/cmd/root.go 0.00% <0.00%> (ø)
...l/armconversion/convert_to_arm_function_builder.go 68.58% <0.00%> (ø)
...ack/generator/pkg/astmodel/armconversion/shared.go 69.14% <0.00%> (-8.24%) ⬇️
.../generator/pkg/astmodel/code_generation_context.go 46.87% <0.00%> (ø)
...erator/pkg/astmodel/conversion_function_builder.go 69.10% <0.00%> (-0.45%) ⬇️
hack/generator/pkg/astmodel/file_definition.go 91.53% <0.00%> (ø)
hack/generator/pkg/astmodel/package_definition.go 30.00% <0.00%> (ø)
hack/generator/pkg/astmodel/package_import.go 89.47% <0.00%> (ø)
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02973a1...da1d489. Read the comment docs.

@theunrepentantgeek
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@theunrepentantgeek
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -33,7 +33,7 @@ type MySQLServerSpec struct {
// If AdminSecret is specified but a secret with the given name is not found in the same namespace
// as the MySQLServer, then reconciliation will block until the secret is created.
// If this is not specified, a username and password will be automatically generated.
AdminSecret string `json:"adminSecret,omitempty"`
AdminSecret string `json:"adminSecret,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the old ASO build lets me merge this angers me... maybe will make a fix to that.

return v
default:
klog.Error(fmt.Sprintf("unexpected value for kubebuilder comment - %s", value.Kind()))
return "%%UNKNOWN%%"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's appropriate to panic here rather than emit incorrect code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@@ -16,7 +16,7 @@ func TestRetryTimeout(t *testing.T) {
})
stop := time.Now().Sub(start)
if stop < 5*time.Second {
t.Errorf("retry ended too soon: %v", stop)
t.Errorf("retry ended too soon: %s", stop)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that there's any issue with this change, but wondering if we want to just exclude _test files from the check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a %v in a test that dumps, say, the API key that we use for testing, wouldn't that be an issue? The whole PR is about being a bit paranoid about disclosures, so I'm happier checking the _test files too.

@@ -11,6 +11,7 @@ import (

azuresql "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v3.0/sql"
_ "github.com/denisenkom/go-mssqldb"
"github.com/pkg/errors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without an amendment to the makefile (that builds old ASO), these can regress. I don't see that in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Taskfile targets don't run for these packages because they're not in hack

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a TODO for following up with changes to the Makefile to match.

Or do we want to migrate ASO to the same Task approach?

@theunrepentantgeek
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@theunrepentantgeek
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@theunrepentantgeek theunrepentantgeek merged commit 1e9cc4f into master Jul 15, 2021
@theunrepentantgeek theunrepentantgeek deleted the feature/lint-disclosures branch July 15, 2021 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add linter to catch use of %v and %+v
3 participants