Skip to content

Commit

Permalink
Fix crash in v0.27.0 when s3_signing is configured (#3256)
Browse files Browse the repository at this point in the history
This was caused by new logger not getting properly initialized in NewClient
call.

Fixes #3255

Signed-off-by: Anders Eknert <anders@eknert.com>
  • Loading branch information
anderseknert committed Mar 12, 2021
1 parent c5b0b08 commit 83a7079
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/rest/rest_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ func (ap *awsSigningAuthPlugin) NewClient(c Config) (*http.Client, error) {
}
}

if ap.logger == nil {
ap.logger = c.logger
}
if ap.AWSService == "" {
ap.AWSService = awsSigv4SigningDefaultService
}
Expand Down
32 changes: 32 additions & 0 deletions plugins/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,38 @@ func TestOauth2ClientCredentialsJwtAuthentication(t *testing.T) {
}
}

// https://github.com/open-policy-agent/opa/issues/3255
func TestS3SigningInstantiationInitializesLogger(t *testing.T) {
config := fmt.Sprintf(`{
"name": "foo",
"url": "https://bundles.example.com",
"credentials": {
"s3_signing": {
"environment_credentials": {}
}
}
}`)

authPlugin := &awsSigningAuthPlugin{
AWSEnvironmentCredentials: &awsEnvironmentCredentialService{},
}
client, err := New([]byte(config), map[string]*keys.Config{}, AuthPluginLookup(func(name string) HTTPAuthPlugin {
return authPlugin
}))
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

plugin := client.authPluginLookup("s3_signing")
if _, err = plugin.NewClient(client.config); err != nil {
t.Fatalf("Unexpected error: %v", err)
}

if authPlugin.logger == nil {
t.Errorf("Expected logger to be initialized")
}
}

func newTestClient(t *testing.T, ts *testServer, certPath string, keypath string) *Client {
config := fmt.Sprintf(`{
"name": "foo",
Expand Down

0 comments on commit 83a7079

Please sign in to comment.