View a markdown version of this page

Getting started: Set up your first credential provider - AWS Identity and Access Management

Getting started: Set up your first credential provider

Note

This is prerelease documentation for a service in preview release. It is subject to change.

AWS IAM Credential Broker gets OAuth tokens from external services for your agents on AWS, caches them, and refreshes them. Your code asks the broker for a token instead of storing secrets or implementing OAuth flows.

In this tutorial, you create a provider for Okta so that an agent running on AWS Lambda can call an Okta-protected API as itself. This is M2M (machine-to-machine access), also called the OAuth client credentials grant. No user sign-in is involved. The console is the primary path, and several steps also show the AWS CLI.

Note

This tutorial uses Okta as the example. Any identity provider or SaaS authorization server that supports OAuth 2.0 works, for example Microsoft Entra ID, Salesforce, or Google. For any other OIDC provider, choose the Custom configuration. Only the connection values change; the steps are the same.

Time to complete: about 15 minutes.

Before you begin

You need the following:

  • An AWS account and an IAM role that you can use to set up Credential Broker, with permission for the following actions:

    • credentialbroker:CreateCredentialProviderPool, GetCredentialProviderPool, CreateCredentialProvider, and GetCredentialProvider.

    • secretsmanager:CreateSecret, so that Credential Broker can store the client secret for you. If you use a secret that you already store in Secrets Manager, you need secretsmanager:GetSecretValue and secretsmanager:DescribeSecret on that secret instead.

    • iam:PutRolePolicy on your agent's role, for Step 3.

    • (Optional) credentialbroker:TagResource, to tag the provider, and kms:CreateGrant and kms:DescribeKey, to encrypt with a customer managed key.

  • An Okta org where you can create an app integration.

  • An Okta authorization server. In the Okta Admin Console, choose Security, then API, and create an authorization server, or use an existing one. Note the server's Issuer URL. You enter it in the domain field when you create the credential provider.

  • An Okta API Services app that can request tokens on its own behalf. In the Okta Admin Console, choose Applications, then Create App Integration. Choose API Services, name the app, and save it. In the app's settings, turn off Require Demonstrating Proof of Possession (DPoP) header in token requests. Credential Broker doesn't currently support DPoP. Copy the client ID and client secret, and grant the app the scopes that your agent needs.

  • Your Okta domain, for example example.okta.com, without https://.

  • AWS CLI version 2, installed and configured with credentials for your account. The examples use us-east-1.

Step 1: Create the credential provider pool

Credential Broker uses a credential provider pool as its top-level resource. You create one pool per account. The pool holds the encryption configuration for cached tokens, and you create every credential provider inside it. To encrypt cached tokens with your own key, you can provide a customer managed key on the pool.

Console
To set up Credential Broker
  1. Sign in to the AWS Management Console, and then open the IAM console.

  2. In the left navigation pane, choose Credential Broker.

  3. On the Get started page, choose Add your first credential provider.

The first time you add a provider, the console sets up Credential Broker and creates a credential provider pool for your account.

AWS CLI

Create the credential provider pool. You need one per account.

aws credential-broker create-credential-provider-pool \ --region us-east-1 \ --name apps-pool

The response includes the pool ID, the pool ARN, and a status of CREATING. Note the pool ID. You use it in every later command.

A create operation returns immediately with CREATING. Check the pool's status with the following command, and continue when the status is READY. If the status is FAILED, the pool did not finish.

aws credential-broker get-credential-provider-pool \ --region us-east-1 \ --pool-id <poolId>

Step 2: Create the credential provider

A credential provider obtains credentials from one external identity provider or authorization server. Name the provider, enter the connection values from your Okta app, and choose M2M (machine-to-machine access). The app or agent then gets a token that represents itself, not a user.

Console
To create the credential provider
  1. For Name, enter a name that identifies the provider, such as okta-reports-app. This name also appears when you choose the provider in other applications.

  2. For Credential type, choose OAuth token.

  3. For Token provider, choose Okta.

  4. For Okta domain, enter your Okta organization domain without https://, for example example.okta.com.

  5. For Client ID, enter the client ID that Okta assigned to your app.

  6. For Client secret, choose one of the following:

    • Enter a new client secret, and then paste the secret. Credential Broker stores it in Secrets Manager for you.

    • Use an existing secret, and then select a secret that you already store in Secrets Manager.

  7. Under Access types, choose Machine access. The app or agent gets a token that represents itself, not a user (client credentials grant).

Note

If you are unsure where to find a value in Okta, choose Find with Q for step-by-step help.

(Optional) To change encryption, the client authentication method, or tags, expand Additional settings:

  • Encryption – The default is an AWS owned key. To use your own AWS KMS key, choose Customize encryption.

  • Client authentication method – The default is Client secret basic. Change it only if your Okta app requires a different method.

  • Tags – Add tags to organize and track the provider.

To create the provider and confirm it's ready
  1. Choose Create credential provider.

  2. On the provider's details page, confirm that Status is Ready.

  3. Copy the provider's ARN and the ARN of its client secret. You use both in the next step.

AWS CLI

Create the provider with one command. The grant type CLIENT_CREDENTIALS is M2M (machine-to-machine access). Replace the placeholder values with your own.

aws credential-broker create-credential-provider \ --region us-east-1 \ --pool-id <poolId> \ --name okta-reports-app \ --grant-type CLIENT_CREDENTIALS \ --provider-config-input 'oktaConfig={oktaDomain=example.okta.com,clientAuthenticationConfig={clientId=<client-id>,clientAuthenticationMethod=CLIENT_SECRET_BASIC,clientSecret={clientSecret=<client-secret>}}}'

Credential Broker stores the client secret in Secrets Manager for you. The default client authentication method is CLIENT_SECRET_BASIC. Use CLIENT_SECRET_POST only if your Okta app requires it. To tag the provider, add --tags Environment=dev,Owner=reports-team to the command.

A create operation returns immediately with a status of CREATING. Check the provider's status with the following command, and continue when the status is READY. If the status is FAILED, the provider did not finish.

aws credential-broker get-credential-provider \ --region us-east-1 \ --pool-id <poolId> \ --provider-id <providerId>

Note the credentialProviderArn and clientSecretArn. You use both in the next step. The provider ARN has the following form.

arn:aws:credentialbroker:<region>:<account>:credentialproviderpool/<poolId>/credentialprovider/<providerId>

Step 3: Allow your agent to use the provider

Add the following policy to the IAM role that your agent runs as. The policy has two statements:

  • The first allows credentialbroker:GetOAuthToken on the provider.

  • The second grants your agent's role access to the client secret through Credential Broker only. Credential Broker reads the secret with your agent's credentials, using a forward access session. The aws:CalledVia condition means that your agent can't read the secret directly.

Replace the resource ARNs with your provider's ARN and your client secret's ARN.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "CredentialBrokerGetToken", "Effect": "Allow", "Action": "credentialbroker:GetOAuthToken", "Resource": "arn:aws:credentialbroker:us-east-1:123456789012:credentialproviderpool/pool-abc123/credentialprovider/provider-def456" }, { "Sid": "ReadTheSecretOnlyThroughCredentialBroker", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ], "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:<client-secret-name>", "Condition": { "ForAnyValue:StringEquals": { "aws:CalledVia": [ "credentialbroker.amazonaws.com" ] } } } ] }
Console
To attach the policy to the execution role
  1. In the IAM console, choose Roles, and then choose the execution role that your agent runs as.

  2. Choose Add permissions, and then choose Create inline policy.

  3. Choose JSON, paste the policy, and save it as credential-broker-okta-access.

AWS CLI

Save the policy as policy.json, and then attach it to the role.

aws iam put-role-policy \ --role-name my-lambda-role \ --policy-name credential-broker-okta-access \ --policy-document file://policy.json

Step 4: Get a token

Ask the broker for a token with the GetOAuthToken operation, and then use the token to call the Okta-protected API.

Lambda function (Python)

In your Lambda function, request a token and use it in an Authorization: Bearer header.

import boto3, requests broker = boto3.client("credential-broker") def handler(event, context): token = broker.get_oauth_token( credentialProviderArn="arn:aws:credentialbroker:us-east-1:123456789012:credentialproviderpool/pool-abc123/credentialprovider/provider-def456", scopes=["reports.read"], )["accessToken"] response = requests.get( "https://api.example.com/reports", headers={"Authorization": f"Bearer {token}"}, ) return response.status_code

Invoke the function twice. The second call returns the cached token. When the token nears expiry, the broker gets a new one automatically, and your code does not change.

AWS CLI

Request a token, using credentials for a role that has the policy from Step 3.

aws credential-broker get-o-auth-token \ --region us-east-1 \ --credential-provider-arn <providerArn> \ --scopes reports.read

The response includes an accessToken. Run the command again: the broker returns the cached token instead of asking Okta for a new one. Use the token in the Authorization: Bearer header when you call the Okta-protected API.

Step 5: Check the audit trail

Credential Broker records each token request in AWS CloudTrail. Each event shows the IAM role that requested the token.

To review token requests in CloudTrail
  1. Open the CloudTrail console, and then choose Event history.

  2. Filter by Event source credentialbroker.amazonaws.com.

  3. Choose a GetOAuthToken event to see which IAM role requested the token.

You can also look up recent GetOAuthToken events with the AWS CLI.

aws cloudtrail lookup-events \ --lookup-attributes AttributeKey=EventName,AttributeValue=GetOAuthToken \ --max-results 5

Try it without a third-party account

If you do not have an Okta org yet, you can test the same steps with an Amazon Cognito user pool.

To try the setup with Amazon Cognito
  1. In Amazon Cognito, create a user pool. Add a resource server with a custom scope, and an app client with a client secret that allows the client credentials grant.

  2. In the provider steps, choose Amazon Cognito instead of Okta, and enter your user pool's details and the app client's ID and secret.

  3. Complete the remaining steps as written, using your custom scope.

Note

This variant is for trying out the setup. Credential Broker is designed for credentials issued by services outside AWS, such as Okta, Microsoft Entra, and Salesforce. In production, agents on AWS usually reach Amazon Cognito-protected APIs directly, without a broker.

Next steps