-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[extension/sigv4authextension] Initial implementation #8263
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b45d19c
squash commit: initial implementation of the sigv4 authenticator exte…
erichsueh3 317b1c5
README, CHANGELOG, deprecation notice changes
erichsueh3 1892ce4
initial changes based on feedback
erichsueh3 3cf05da
check config values in inferServiceAndRegion and simplified call in R…
erichsueh3 a6a92ba
change getCredsFromConfig() to getCredsProviderFromConfig() and made …
erichsueh3 283e791
missing cred test without role for config, remove role test for confi…
erichsueh3 69d9a10
added RoleSessionName config field, made documentation changes
erichsueh3 717d6ba
design doc updates
erichsueh3 53d132a
fix merge conflict and add sigv4 ext to unreleased section of CHANGELOG
erichsueh3 eb14d35
Merge branch 'main' of https://github.com/open-o11y/opentelemetry-col…
erichsueh3 27b3f9b
added AssumeRole config option struct + doc changes
erichsueh3 d8ef292
removed random identifier to be use SDK default identifier using nano…
erichsueh3 b7328c2
fix service/region detection warning
erichsueh3 8f147e3
go fmt
erichsueh3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Authenticator - Sigv4 | ||
|
||
This extension provides Sigv4 authentication for making requests to AWS services. For more information on the Sigv4 process, please look [here](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html). | ||
|
||
## Configuration | ||
|
||
The configuration fields are as follows: | ||
|
||
* `role_arn`: **Optional**. The Amazon Resource Name (ARN) of a role to assume | ||
* `region`: **Optional**. The AWS region for AWS Sigv4 | ||
* Note that an attempt will be made to obtain a valid region from the endpoint of the service you are exporting to | ||
* [List of AWS regions](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html) | ||
* `service`: **Optional**. The AWS service for AWS Sigv4 | ||
* Note that an attempt will be made to obtain a valid service from the endpoint of the service you are exporting to | ||
* `role_session_name`: **Optional**. The name of a role session. If not provided, one will be constructed with a semi-random identifier. | ||
|
||
|
||
```yaml | ||
extensions: | ||
sigv4auth: | ||
role_arn: "arn:aws:iam::123456789012:role/aws-service-role/access" | ||
|
||
receivers: | ||
hostmetrics: | ||
scrapers: | ||
memory: | ||
|
||
exporters: | ||
prometheusremotewrite: | ||
endpoint: "https://aps-workspaces.us-west-2.amazonaws.com/workspaces/ws-XXX/api/v1/remote_write" | ||
auth: | ||
authenticator: sigv4auth | ||
|
||
service: | ||
extensions: [sigv4auth] | ||
pipelines: | ||
metrics: | ||
receivers: [hostmetrics] | ||
processors: [] | ||
exporters: [prometheusremotewrite] | ||
``` | ||
|
||
## Notes | ||
|
||
* The collector must have valid AWS credentials as used by the [AWS SDK for Go](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sigv4authextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension" | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"go.opentelemetry.io/collector/config" | ||
) | ||
|
||
var ( | ||
errBadCreds = errors.New("bad AWS credentials") | ||
) | ||
|
||
// Config stores the configuration for the Sigv4 Authenticator | ||
type Config struct { | ||
config.ExtensionSettings `mapstructure:",squash"` | ||
Region string `mapstructure:"region,omitempty"` | ||
Service string `mapstructure:"service,omitempty"` | ||
RoleARN string `mapstructure:"role_arn,omitempty"` | ||
RoleSessionName string `mapstructure:"role_session_name,omitempty"` | ||
credsProvider *aws.CredentialsProvider | ||
} | ||
|
||
// compile time check that the Config struct satisfies the config.Extension interface | ||
var _ config.Extension = (*Config)(nil) | ||
|
||
// Validate checks that the configuration is valid. | ||
// We aim to catch most errors here to ensure that we | ||
// fail early and to avoid revalidating static data. | ||
func (cfg *Config) Validate() error { | ||
credsProvider, err := getCredsProviderFromConfig(cfg) | ||
if credsProvider == nil || err != nil { | ||
return errBadCreds | ||
} | ||
cfg.credsProvider = credsProvider | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sigv4authextension | ||
|
||
import ( | ||
"context" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/service/servicetest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
awsCredsProvider := mockCredentials() | ||
awsCreds, _ := (*awsCredsProvider).Retrieve(context.Background()) | ||
|
||
t.Setenv("AWS_ACCESS_KEY_ID", awsCreds.AccessKeyID) | ||
erichsueh3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Setenv("AWS_SECRET_ACCESS_KEY", awsCreds.SecretAccessKey) | ||
|
||
factories, err := componenttest.NopFactories() | ||
assert.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Extensions[typeStr] = factory | ||
cfg, err := servicetest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
expected := factory.CreateDefaultConfig().(*Config) | ||
expected.Region = "region" | ||
expected.Service = "service" | ||
expected.RoleSessionName = "role_session_name" | ||
|
||
ext := cfg.Extensions[config.NewComponentID(typeStr)] | ||
// Ensure creds are the same for load config test; tested in extension_test.go | ||
expected.credsProvider = ext.(*Config).credsProvider | ||
assert.Equal(t, expected, ext) | ||
|
||
assert.Equal(t, 1, len(cfg.Service.Extensions)) | ||
assert.Equal(t, config.NewComponentID(typeStr), cfg.Service.Extensions[0]) | ||
} | ||
|
||
func TestLoadConfigError(t *testing.T) { | ||
factories, err := componenttest.NopFactories() | ||
assert.NoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
expectedErr error | ||
}{ | ||
{ | ||
"missing_credentials", | ||
errBadCreds, | ||
}, | ||
} | ||
for _, testcase := range tests { | ||
t.Run(testcase.name, func(t *testing.T) { | ||
factory := NewFactory() | ||
factories.Extensions[typeStr] = factory | ||
cfg, _ := servicetest.LoadConfig(path.Join(".", "testdata", "config_bad.yaml"), factories) | ||
extension := cfg.Extensions[config.NewComponentIDWithName(typeStr, testcase.name)] | ||
verr := extension.Validate() | ||
require.ErrorIs(t, verr, testcase.expectedErr) | ||
}) | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this up to be right after role_arn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wondering if it should be
since session_name doesn't make sense without arn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, pairing the ARN and session name like that sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes and now include an
AssumeRole
struct with anARN
and aSessionName