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

adding private DNS name as EC2 metadata #25418

Merged
Merged
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
1 change: 1 addition & 0 deletions builtin/credential/aws/path_config_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
"inferred_aws_region",
"inferred_entity_id",
"inferred_entity_type",
"inferred_hostname",
},
}

Expand Down
4 changes: 4 additions & 0 deletions builtin/credential/aws/path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ func (b *backend) pathLoginUpdateIam(ctx context.Context, req *logical.Request,

inferredEntityType := ""
inferredEntityID := ""
inferredHostname := ""
if roleEntry.InferredEntityType == ec2EntityType {
instance, err := b.validateInstance(ctx, req.Storage, entity.SessionInfo, roleEntry.InferredAWSRegion, callerID.Account)
if err != nil {
Expand All @@ -1482,6 +1483,7 @@ func (b *backend) pathLoginUpdateIam(ctx context.Context, req *logical.Request,

inferredEntityType = ec2EntityType
inferredEntityID = entity.SessionInfo
inferredHostname = *instance.PrivateDnsName
}

auth := &logical.Auth{
Expand All @@ -1496,6 +1498,7 @@ func (b *backend) pathLoginUpdateIam(ctx context.Context, req *logical.Request,
"inferred_entity_id": inferredEntityID,
"inferred_aws_region": roleEntry.InferredAWSRegion,
"account_id": entity.AccountNumber,
"inferred_hostname": inferredHostname,
},
DisplayName: entity.FriendlyName,
Alias: &logical.Alias{
Expand All @@ -1517,6 +1520,7 @@ func (b *backend) pathLoginUpdateIam(ctx context.Context, req *logical.Request,
"inferred_entity_id": inferredEntityID,
"inferred_aws_region": roleEntry.InferredAWSRegion,
"account_id": entity.AccountNumber,
"inferred_hostname": inferredHostname,
}); err != nil {
b.Logger().Warn(fmt.Sprintf("unable to set alias metadata due to %s", err))
}
Expand Down
2 changes: 2 additions & 0 deletions builtin/credential/aws/path_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func TestBackend_pathLogin_IAMHeaders(t *testing.T) {
"inferred_aws_region",
"inferred_entity_id",
"inferred_entity_type",
"inferred_hostname",
},
"ec2_alias": "role_id",
"ec2_metadata": []string{
Expand Down Expand Up @@ -614,6 +615,7 @@ func TestBackend_pathLogin_IAMRoleResolution(t *testing.T) {
"inferred_aws_region",
"inferred_entity_id",
"inferred_entity_type",
"inferred_hostname",
},
"ec2_alias": "role_id",
"ec2_metadata": []string{
Expand Down
4 changes: 4 additions & 0 deletions changelog/25418.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

```release-note:improvement
auth/aws: Add inferred_hostname metadata for IAM AWS authentication method.
```
Loading