Federate access to AWS with Nomad Workload Identity
This page describes how to integrate Nomad with AWS IAM as an OpenID Connect (OIDC) provider and use Workload Identity to federate access to AWS resources and services. In this workflow, Nomad is the OpenID Connect Provider (OP or OIDC provider) and generates JSON Web Tokens (JWTs) which serve as workload identities. AWS IAM is the Relying Party (RP) and validates these workload identity tokens with Nomad before it permits federated access to resources and services.
Prerequisites
To integrate Nomad and AWS IAM identity, you need a running Nomad cluster that meets the following prerequisites:
- Nomad v1.7.x or later
- TLS enabled
The instructions on this page also assume the following:
- Your AWS account has the necessary permissions to create IAM roles, policies, hosted zones, and certificates.
- You are using Terraform to manage your AWS infrastructure and you have configured it to communicate with AWS.
Workflow
The process to integrate Nomad as an OIDC provider with AWS consists of the following steps:
- Create the required AWS resources:
- Update the Nomad server configuration.
- Create a jobspec file that accesses AWS and then run it to verify your configuration.
Create and configure AWS resources
To use Nomad as an identity provider, you need to have a trusted SSL certificate for the domain used by the cluster. The following example uses AWS Certificate Manager (ACM).
Create a hosted zone
Use the aws_route53_zone
resource.
This configuration requires the following information:
<DOMAIN_NAME>
: The domain name of your Nomad cluster without the protocol or port.var.domain_name
is used throughout the examples on this page to reference<DOMAIN_NAME>
.
Generate SSL certificates
Use the aws_acm_certificate
and aws_acm_certificate_validation
resources to create a request and provide validation for an SSL
certficiate.
This configuration requires the following information:
<HOSTED_ZONE_ID>
: The ID of the hosted zone. This will beaws_route53_zone.example.zone_id
if you are using the examples from this page.
Create an Application Load Balancer
Use the aws_lb
resource.
This configuration requires the following information:
<SECURITY_GROUP_ID>
: A list of security groups IDs that you want to apply to the load balancer.<SUBNET_IDS>
: A list of subnet IDs that you want to attach to the load balancer.<S3_BUCKET_ID>
: The ID of an S3 bucket to store the load balancer access logs in.
Create a load balancer listener
Use the aws_lb_listener
resource.
This configuration requires the following information:
<LB_ARN>
: The AWS resource name of the load balancer. This will beaws_lb.test.arn
if you are using the examples from this page.<CERT_ARN>
: The AWS resource name of the load balancer's certificate. This will beaws_acm_certificate_validation.example.certificate_arn
if you are using the examples from this page.<LB_TARGET_GROUP_ARN>
: The AWS resource name of the target group for the load balancer to route traffic to. This group includes your Nomad server instances.
Create a DNS Alias
Use the aws_route53_record
resource.
This configuration requires the following information:
<HOSTED_ZONE_ID>
: The ID of the hosted zone. This will beaws_route53_zone.example.zone_id
if you are using the examples from this page.<LB_ALIAS_DNS_NAME>
: The DNS name of the load balancer. This will beaws_lb.test.dns_name
if you are using the examples from this page.<LB_ALIAS_ZONE_ID>
: The zone ID of the load balancer. This will beaws_lb.test.zone_id
if you are using the examples from this page.
Create an OIDC Identity Provider
Use the aws_iam_openid_connect_provider
resource.
This configuration requires the following information:
<CERT_DOMAIN_NAME>
: The domain name of the load balancer certificate. This will beaws_acm_certificate.example.domain_name
if you are using the examples from this page.
Create an IAM policy for OIDC Federated Users
Use the aws_iam_role
resource
to create an appropriate IAM role for workloads acting as federated users. This will be
specific to your use case. The following example allows workloads access to S3 buckets.
This configuration requires the following information:
<DOMAIN_NAME>
: The domain name of your Nomad cluster without the protocol or port.<AWS_ACCOUNT_ID>
: The ID of the AWS account where the IAM role from the previous step was created.
Update the Nomad server configuration
After you configure AWS, modify the Nomad server configuration file. Add the
oidc_issuer
attribute and set the value
to the domain name for the Nomad cluster. This enables the HTTP endpoint in Nomad that allows third parties to discover Nomad's OIDC
configuration.
This configuration requires the following information:
<DOMAIN_NAME>
: The domain name of your Nomad cluster without the protocol or port.
Restart the Nomad server agent to apply the configuration changes.
Create and run a sample jobspec file
Create and run a jobspec file to validate your configuration. The following file is named s3-upload.nomad.hcl
, add the following configuration to it, and
save the file.
This configuration requires the following information:
<S3_BUCKET_NAME>
: The name of the S3 bucket where the test file will be saved.<AWS_ACCOUNT_ID>
: The ID of the AWS account where the IAM role from the previous step was created.<IAM_ROLE_NAME>
: The name of the IAM role from previous steps. This will bes3_all_access_role
if you are using the examples from this page.
Submit the job to Nomad.
Verify that the job completed successfully.
Verify that the file was also uploaded to the S3 bucket.