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

Add ability to sign requests for all AWS services #380

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions sigv4/sigv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ var sigv4HeaderDenylist = []string{
}

type sigV4RoundTripper struct {
region string
next http.RoundTripper
pool sync.Pool
region string
next http.RoundTripper
pool sync.Pool
service string

signer *signer.Signer
}
Expand Down Expand Up @@ -88,11 +89,15 @@ func NewSigV4RoundTripper(cfg *SigV4Config, next http.RoundTripper) (http.RoundT
if cfg.RoleARN != "" {
signerCreds = stscreds.NewCredentials(sess, cfg.RoleARN)
}
if cfg.Service == "" {
cfg.Service = "aps"
}

rt := &sigV4RoundTripper{
region: cfg.Region,
next: next,
signer: signer.NewSigner(signerCreds),
region: cfg.Region,
next: next,
signer: signer.NewSigner(signerCreds),
service: cfg.Service,
}
rt.pool.New = rt.newBuf
return rt, nil
Expand Down Expand Up @@ -136,7 +141,7 @@ func (rt *sigV4RoundTripper) RoundTrip(req *http.Request) (*http.Response, error
signReq.Header.Del(header)
}

headers, err := rt.signer.Sign(signReq, seeker, "aps", rt.region, time.Now().UTC())
headers, err := rt.signer.Sign(signReq, seeker, rt.service, rt.region, time.Now().UTC())
if err != nil {
return nil, fmt.Errorf("failed to sign request: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions sigv4/sigv4_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SigV4Config struct {
Profile string `yaml:"profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
UseFIPSSTSEndpoint bool `yaml:"use_fips_sts_endpoint,omitempty"`
Service string `yaml:"service,omitempty"`
}

func (c *SigV4Config) Validate() error {
Expand Down
7 changes: 7 additions & 0 deletions sigv4/sigv4_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func TestGoodSigV4Configs(t *testing.T) {
}
}

func TestGoodSigV4ServiceConfigs(t *testing.T) {
filesToTest := []string{"testdata/sigv4_good_service.yaml", "testdata/sigv4_good_service.yaml"}
for _, filename := range filesToTest {
testGoodConfig(t, filename)
}
}

func TestBadSigV4Config(t *testing.T) {
filename := "testdata/sigv4_bad.yaml"
_, err := loadSigv4Config(filename)
Expand Down
4 changes: 4 additions & 0 deletions sigv4/testdata/sigv4_good_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
region: us-east-2
profile: profile
role_arn: blah:role/arn
service: exectute-api