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

Conversation

ikraemer-dd
Copy link
Contributor

@ikraemer-dd ikraemer-dd commented Feb 14, 2024

This PR adds a new metadata field when using IAM AWS authentication method from an EC2.

Solves #25413

I tested that it behaves as expected.

Server side configuration:

vault auth enable aws
tee cert-policy.hcl <<EOF
path "pki*" {
  capabilities = [ "create", "read", "update", "list"]
}
EOF
vault policy write cert-issuer cert-policy.hcl
vault write auth/aws/role/dev-role-iam auth_type=iam \
     token_type=service inferred_entity_type=ec2_instance inferred_aws_region=us-east-1 \
     bound_iam_instance_profile_arn="arn:aws:iam::$ACCOUNT_ID:instance-profile/$INSTANCE_PROFILE"
     policies=cert-issuer max_ttl=500h
vault write auth/aws/config/identity iam_metadata=inferred_hostname
vault secrets enable -path=pki pki
// ... configure PKI ...
vault write pki/roles/example-dot-com \
     issuer_ref="$(vault read -field=default pki/config/issuers)" \
     allowed_domains='{{identity.entity.aliases.<accessor>.metadata.inferred_hostname}}' \
     allowed_domains_template=true \
     allow_bare_domains=true \
     allow_glob_domains=true \
     allow_localhost=false \
     enforce_hostnames=false \
     generate_lease=false \
     no_store=true \
     max_ttl="720h"

Client side tests:
This is successful:

vault login -method=aws role="dev-role-iam"
HOSTNAME=$(curl -s http://169.254.169.254/latest/meta-data/local-hostname)
vault write -format=json "pki/issue/example-dot-com" \
  common_name="$HOSTNAME" > generated_example.cert.json

This fails, as expected:

vault write -format=json "pki/issue/example-dot-com" common_name="test"

with the error

Error writing data to pki/issue/example-dot-com: Error making API request.

URL: PUT http://x.x.x.x:8200/v1/pki/issue/example-dot-com
Code: 400. Errors:

* common name test not allowed by this role

@ikraemer-dd ikraemer-dd requested a review from a team as a code owner February 14, 2024 17:00
@hashicorp-cla
Copy link

hashicorp-cla commented Feb 14, 2024

CLA assistant check
All committers have signed the CLA.

@ikraemer-dd ikraemer-dd marked this pull request as draft February 14, 2024 17:00
@ikraemer-dd ikraemer-dd marked this pull request as ready for review February 14, 2024 17:48
Copy link
Contributor

@kpcraig kpcraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! thanks for the contribution!

@ikraemer-dd ikraemer-dd requested a review from a team as a code owner May 1, 2024 16:26
@kpcraig kpcraig merged commit b4a2e40 into hashicorp:main May 1, 2024
66 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants