Skip to content

Commit

Permalink
Remove broken consumer assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
tolleiv committed Apr 27, 2021
1 parent e4a01e9 commit 081d503
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions aws_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/sts"
log "github.com/sirupsen/logrus"
"regexp"
"strings"
)
Expand All @@ -20,7 +22,7 @@ type AwsConsumerInterface interface {
Rules() []Rule
// AssumeRole performs this for the give rule
AssumeRole(rule *Rule, name string) (*sts.Credentials, error)
// RetrieveRulesFromRoleTags checks wether a string matches the rule format
// RetrieveRulesFromRoleTags checks whether a string matches the rule format
RetrieveRulesFromRoleTags(role string) ([]Rule, error)
}

Expand Down Expand Up @@ -53,6 +55,7 @@ func (a *AwsConsumer) ReadConfiguration() error {
if err := decoder.Decode(a.Config); err != nil {
return fmt.Errorf("Unable to read RULES inputClaims.\n Error: %v", err)
}
log.Debugf("Successfully imported config %v", a.Config)
defer content.Close()
return nil
}
Expand All @@ -78,14 +81,15 @@ func (a *AwsConsumer) AssumeRole(rule *Rule, name string) (*sts.Credentials, err
}

// RetrieveRulesFromRoleTags checks the IAM role for further rules configured through tags
func (a *AwsConsumer) RetrieveRulesFromRoleTags(role string) ([]Rule, error) {
func (a *AwsConsumer) RetrieveRulesFromRoleTags(roleArn string) ([]Rule, error) {
validRole := regexp.MustCompile(`^arn:aws:iam::\d{12}:role/[a-zA-Z0-9-_]+$`)
if !validRole.MatchString(role) {
if !validRole.MatchString(roleArn) {
return nil, fmt.Errorf("invalid role format")
}

log.Debugf("GetRole %s", roleArn[31:])
result, err := a.AWS.GetRole(&iam.GetRoleInput{
RoleName: &role,
RoleName: aws.String(roleArn[31:]),
})
if err != nil {
return nil, err
Expand All @@ -105,7 +109,7 @@ func (a *AwsConsumer) RetrieveRulesFromRoleTags(role string) ([]Rule, error) {
continue
}
rule := Rule{
Role: role,
Role: roleArn,
Duration: a.Config.Duration,
ClaimValues: tagDecoded,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/token_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
RoleAnnotationPrefix: "token_auth/",
}

awsConsumer, err := auth.NewAwsConsumer(config)
awsConsumer, err = auth.NewAwsConsumer(config)
if err != nil {
log.Fatalf("Error initializing: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions token_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"bytes"
"context"
"fmt"
"log"
"strings"

"github.com/MicahParks/keyfunc"
"github.com/buger/jsonparser"
"github.com/dgrijalva/jwt-go"
log "github.com/sirupsen/logrus"
"strings"
)

// TokenValidatorInterface interface of validation objects
Expand All @@ -21,6 +20,7 @@ type TokenValidatorInterface interface {

// NewTokenValidator creates a new TokenValidator for a given system
func NewTokenValidator(jwksURL string) *TokenValidator {
log.Debugf("Using %s for JWK retrival", jwksURL)
jwks, err := keyfunc.Get(jwksURL)
if err != nil {
log.Fatalf("Failed to get the JWKS from the given URL.\nError: %v", err)
Expand Down

0 comments on commit 081d503

Please sign in to comment.