Getting started: Set up your first credential provider
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.
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, andGetCredentialProvider. -
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 needsecretsmanager:GetSecretValueandsecretsmanager:DescribeSecreton that secret instead. -
iam:PutRolePolicyon your agent's role, for Step 3. -
(Optional)
credentialbroker:TagResource, to tag the provider, andkms:CreateGrantandkms: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, withouthttps://. -
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.
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.
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:GetOAuthTokenon 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:CalledViacondition 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" ] } } } ] }
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.
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
-
Open the CloudTrail console, and then choose Event history.
-
Filter by Event source
credentialbroker.amazonaws.com. -
Choose a
GetOAuthTokenevent 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
-
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.
-
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.
-
Complete the remaining steps as written, using your custom scope.
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
-
To act for a signed-in user, set up user authorization so that your application can call a service as a specific user. See Obtain a token on behalf of a user with the authorization code grant.
-
To exchange a user's existing token for one that a downstream service accepts, see Obtain a token with the token exchange grant.
-
To control which agents can use each provider, see Control access to AWS IAM Credential Broker.