-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth/aws: Make identity alias configurable (#5247)
* auth/aws: Make identity alias configurable This is inspired by #4178, though not quite exactly what is requested there. Rather than just use RoleSessionName as the Identity alias, the full ARN is uses as the Alias. This mitigates against concerns that an AWS role with an insufficiently secured trust policy could allow an attacker to generate arbitrary RoleSessionNames in AssumeRole calls to impersonate anybody in the Identity store that had an alias set up. By using the full ARN, the owner of the identity store has to explicitly trust specific AWS roles in specific AWS accounts to generate an appropriate RoleSessionName to map back to an identity. Fixes #4178 * Respond to PR feedback * Remove CreateOperation Response to PR feedback
- Loading branch information
1 parent
9add4f0
commit d12547c
Showing
6 changed files
with
310 additions
and
8 deletions.
There are no files selected for viewing
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,98 @@ | ||
package awsauth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/vault/helper/strutil" | ||
"github.com/hashicorp/vault/logical" | ||
"github.com/hashicorp/vault/logical/framework" | ||
) | ||
|
||
func pathConfigIdentity(b *backend) *framework.Path { | ||
return &framework.Path{ | ||
Pattern: "config/identity$", | ||
Fields: map[string]*framework.FieldSchema{ | ||
"iam_alias": &framework.FieldSchema{ | ||
Type: framework.TypeString, | ||
Default: identityAliasIAMUniqueID, | ||
Description: fmt.Sprintf("Configure how the AWS auth method generates entity aliases when using IAM auth. Valid values are %q and %q", identityAliasIAMUniqueID, identityAliasIAMFullArn), | ||
}, | ||
}, | ||
|
||
Callbacks: map[logical.Operation]framework.OperationFunc{ | ||
logical.ReadOperation: pathConfigIdentityRead, | ||
logical.UpdateOperation: pathConfigIdentityUpdate, | ||
}, | ||
|
||
HelpSynopsis: pathConfigIdentityHelpSyn, | ||
HelpDescription: pathConfigIdentityHelpDesc, | ||
} | ||
} | ||
|
||
func pathConfigIdentityRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) { | ||
entry, err := req.Storage.Get(ctx, "config/identity") | ||
if err != nil { | ||
return nil, err | ||
} | ||
if entry == nil { | ||
return nil, nil | ||
} | ||
var result identityConfig | ||
if err := entry.DecodeJSON(&result); err != nil { | ||
return nil, err | ||
} | ||
return &logical.Response{ | ||
Data: map[string]interface{}{ | ||
"iam_alias": result.IAMAlias, | ||
}, | ||
}, nil | ||
} | ||
|
||
func pathConfigIdentityUpdate(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) { | ||
var configEntry identityConfig | ||
|
||
iamAliasRaw, ok := data.GetOk("iam_alias") | ||
if ok { | ||
iamAlias := iamAliasRaw.(string) | ||
allowedIAMAliasValues := []string{identityAliasIAMUniqueID, identityAliasIAMFullArn} | ||
if !strutil.StrListContains(allowedIAMAliasValues, iamAlias) { | ||
return logical.ErrorResponse(fmt.Sprintf("iam_alias of %q not in set of allowed values: %v", iamAlias, allowedIAMAliasValues)), nil | ||
} | ||
configEntry.IAMAlias = iamAlias | ||
entry, err := logical.StorageEntryJSON("config/identity", configEntry) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := req.Storage.Put(ctx, entry); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return nil, nil | ||
} | ||
|
||
type identityConfig struct { | ||
IAMAlias string `json:"iam_alias"` | ||
} | ||
|
||
const identityAliasIAMUniqueID = "unique_id" | ||
const identityAliasIAMFullArn = "full_arn" | ||
|
||
const pathConfigIdentityHelpSyn = ` | ||
Configure the way the AWS auth method interacts with the identity store | ||
` | ||
|
||
const pathConfigIdentityHelpDesc = ` | ||
The AWS auth backend defaults to aliasing an IAM principal's unique ID to the | ||
identity store. This path allows users to change how Vault configures the | ||
mapping to Identity aliases for more flexibility. | ||
You can set the iam_alias parameter to one of the following values: | ||
* 'unique_id': This retains Vault's default behavior | ||
* 'full_arn': This maps the full authenticated ARN to the identity alias, e.g., | ||
"arn:aws:sts::<account_id>:assumed-role/<role_name>/<role_session_name> | ||
This is useful where you have an identity provder that sets role_session_name | ||
to a known value of a person, such as a username or email address, and allows | ||
you to map those roles back to entries in your identity store. | ||
` |
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,90 @@ | ||
package awsauth | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/logical" | ||
) | ||
|
||
func TestBackend_pathConfigIdentity(t *testing.T) { | ||
config := logical.TestBackendConfig() | ||
storage := &logical.InmemStorage{} | ||
config.StorageView = storage | ||
|
||
b, err := Backend(config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = b.Setup(context.Background(), config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
resp, err := b.HandleRequest(context.Background(), &logical.Request{ | ||
Operation: logical.ReadOperation, | ||
Path: "config/identity", | ||
Storage: storage, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp != nil { | ||
if resp.IsError() { | ||
t.Fatalf("failed to read identity config entry") | ||
} else if resp.Data["iam_alias"] != nil && resp.Data["iam_alias"] != "" { | ||
t.Fatalf("returned alias is non-empty: %q", resp.Data["alias"]) | ||
} | ||
} | ||
|
||
data := map[string]interface{}{ | ||
"iam_alias": "invalid", | ||
} | ||
|
||
resp, err = b.HandleRequest(context.Background(), &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "config/identity", | ||
Data: data, | ||
Storage: storage, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp == nil { | ||
t.Fatalf("nil response from invalid config/identity request") | ||
} | ||
if !resp.IsError() { | ||
t.Fatalf("received non-error response from invalid config/identity request: %#v", resp) | ||
} | ||
|
||
data["iam_alias"] = identityAliasIAMFullArn | ||
resp, err = b.HandleRequest(context.Background(), &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "config/identity", | ||
Data: data, | ||
Storage: storage, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp != nil && resp.IsError() { | ||
t.Fatalf("received error response from valid config/identity request: %#v", resp) | ||
} | ||
|
||
resp, err = b.HandleRequest(context.Background(), &logical.Request{ | ||
Operation: logical.ReadOperation, | ||
Path: "config/identity", | ||
Storage: storage, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp == nil { | ||
t.Fatalf("nil response received from config/identity when data expected") | ||
} else if resp.IsError() { | ||
t.Fatalf("error response received from reading config/identity: %#v", resp) | ||
} else if resp.Data["iam_alias"] != identityAliasIAMFullArn { | ||
t.Fatalf("bad: expected response with iam_alias value of %q; got %#v", identityAliasIAMFullArn, resp) | ||
} | ||
} |
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