-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat(secretstores.vault): Add new authentication methods #18434
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| package auth | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| vault "github.com/hashicorp/vault/api" | ||
| "github.com/hashicorp/vault/api/auth/approle" | ||
|
|
||
| "github.com/influxdata/telegraf/config" | ||
| ) | ||
|
|
||
| type AppRole struct { | ||
| RoleID string `toml:"role_id"` | ||
| ResponseWrapped bool `toml:"response_wrapped"` | ||
| Secret config.Secret `toml:"secret"` | ||
| } | ||
|
|
||
| // Init validates the auth method options and sets any necessary defaults | ||
| func (a *AppRole) Init() error { | ||
| if a.RoleID == "" { | ||
| return errors.New("approle role_id missing") | ||
| } | ||
| if a.Secret.Empty() { | ||
| return errors.New("approle secret missing") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Authenticate uses the provided configuration to authenticate to Vault | ||
| func (a *AppRole) Authenticate(v *vault.Client) (*vault.Secret, error) { | ||
| secret, err := a.Secret.Get() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("getting secret failed: %w", err) | ||
| } | ||
| secretID := &approle.SecretID{FromString: secret.String()} | ||
| defer secret.Destroy() | ||
|
|
||
| var opts []approle.LoginOption | ||
| if a.ResponseWrapped { | ||
| opts = append(opts, approle.WithWrappingToken()) | ||
| } | ||
|
|
||
| appRoleAuth, err := approle.NewAppRoleAuth(a.RoleID, secretID, opts...) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to initialize AppRole auth method: %w", err) | ||
| } | ||
|
|
||
| authInfo, err := v.Auth().Login(context.Background(), appRoleAuth) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to login to AppRole auth method: %w", err) | ||
| } | ||
| if authInfo == nil { | ||
| return nil, errors.New("no auth info was returned after login") | ||
| } | ||
|
|
||
| return authInfo, nil | ||
| } |
This file contains hidden or 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,11 @@ | ||
| package auth | ||
|
|
||
| import vault "github.com/hashicorp/vault/api" | ||
|
|
||
| type VaultAuth interface { | ||
| // Init validates the auth method options and sets any necessary defaults | ||
| Init() error | ||
|
|
||
| // Authenticate uses the provided configuration to authenticate to Vault | ||
| Authenticate(*vault.Client) (*vault.Secret, error) | ||
| } |
This file contains hidden or 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,116 @@ | ||
| package auth | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| vault "github.com/hashicorp/vault/api" | ||
| "github.com/hashicorp/vault/api/auth/aws" | ||
| ) | ||
|
|
||
| type AwsIAM struct { | ||
| RoleName string `toml:"role_name"` | ||
| Region string `toml:"region"` | ||
| ServerIDHeader string `toml:"server_id_header"` | ||
| } | ||
|
|
||
| // Init validates the auth method options and sets any necessary defaults | ||
| func (a *AwsIAM) Init() error { | ||
| if a.RoleName == "" { | ||
| return errors.New("aws iam role_name missing") | ||
| } | ||
|
|
||
| if a.Region == "" { | ||
| a.Region = "us-east-1" | ||
|
mstrandboge marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Authenticate uses the provided configuration to authenticate to Vault | ||
| func (a *AwsIAM) Authenticate(v *vault.Client) (*vault.Secret, error) { | ||
| opts := []aws.LoginOption{ | ||
| aws.WithIAMAuth(), | ||
| aws.WithRole(a.RoleName), | ||
| aws.WithRegion(a.Region), | ||
| } | ||
| if a.ServerIDHeader != "" { | ||
| opts = append(opts, aws.WithIAMServerIDHeader(a.ServerIDHeader)) | ||
| } | ||
|
|
||
| awsAuth, err := aws.NewAWSAuth(opts...) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to initialize AWS IAM auth method: %w", err) | ||
| } | ||
|
|
||
| authInfo, err := v.Auth().Login(context.Background(), awsAuth) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to login to AWS IAM auth method: %w", err) | ||
| } | ||
| if authInfo == nil { | ||
| return nil, errors.New("no auth info was returned after login") | ||
| } | ||
|
|
||
| return authInfo, nil | ||
| } | ||
|
|
||
| type AwsEC2 struct { | ||
| RoleName string `toml:"role_name"` | ||
| Region string `toml:"region"` | ||
| SignatureType string `toml:"signature_type"` | ||
| } | ||
|
|
||
| // Init validates the auth method options and sets any necessary defaults | ||
| func (a *AwsEC2) Init() error { | ||
| if a.RoleName == "" { | ||
| return errors.New("aws ec2 role_name missing") | ||
| } | ||
|
|
||
| switch a.SignatureType { | ||
| case "": | ||
| a.SignatureType = "pkcs7" | ||
| case "pkcs7", "identity", "rsa2048": | ||
| default: | ||
| return fmt.Errorf("unknown signature type: %q", a.SignatureType) | ||
| } | ||
|
|
||
| if a.Region == "" { | ||
| a.Region = "us-east-1" | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Authenticate uses the provided configuration to authenticate to Vault | ||
| func (a *AwsEC2) Authenticate(v *vault.Client) (*vault.Secret, error) { | ||
| opts := []aws.LoginOption{ | ||
| aws.WithEC2Auth(), | ||
| aws.WithRole(a.RoleName), | ||
| aws.WithRegion(a.Region), | ||
| } | ||
|
|
||
| switch a.SignatureType { | ||
| case "pkcs7": | ||
| opts = append(opts, aws.WithPKCS7Signature()) | ||
| case "identity": | ||
| opts = append(opts, aws.WithIdentitySignature()) | ||
| case "rsa2048": | ||
| opts = append(opts, aws.WithRSA2048Signature()) | ||
| } | ||
|
|
||
| awsAuth, err := aws.NewAWSAuth(opts...) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to initialize AWS EC2 auth method: %w", err) | ||
| } | ||
|
|
||
| authInfo, err := v.Auth().Login(context.Background(), awsAuth) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to login to AWS EC2 auth method: %w", err) | ||
| } | ||
| if authInfo == nil { | ||
| return nil, errors.New("no auth info was returned after login") | ||
| } | ||
|
|
||
| return authInfo, nil | ||
| } | ||
Oops, something went wrong.
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.
As @skartikey outlined already, this library is long deprecated and to be honest I don't want to pull that in. My suggestion is to remove the
awsauthentication method for now and open an issue in their repo asking them to update to the v2 SDK. We can then add backawsonce they bumped to v2.