Securing Generative AI on AWS: IAM Users, Roles, Policies, and Compliance Best Practices.

Securing Generative AI on AWS: IAM Users, Roles, Policies, and Compliance Best Practices.

How to design least-privilege access for Amazon Bedrock and AI-powered applications without compromising security.

DevOps Engineer | AWS | Terraform | Docker | Kubernetes | CI/CD

Introduction: AI Innovation Needs Strong Access Controls

Artificial Intelligence is transforming how organizations build applications, automate workflows, analyze information, and interact with customers.
With AWS services such as Amazon Bedrock, Amazon SageMaker AI, and Amazon Q, organizations can develop powerful AI solutions without building every component from scratch.
However, adopting AI introduces an important security question:
Who should be allowed to access AI services, which operations should they perform, and how can organizations ensure that sensitive business data remains protected?
Imagine a developer working on an AI-powered application using Amazon Bedrock.
The developer needs permission to invoke a foundation model, the application needs access to selected data, and security administrators need visibility into how these resources are being used.
Should everyone receive administrator access?
Absolutely not.
This is where AWS Identity and Access Management (IAM) becomes essential.
IAM helps organizations control access to AWS resources through identities, roles, policies, and conditions.
In this article, we'll explore how IAM works, how it supports secure AI workloads, and how to design access controls aligned with enterprise security and compliance requirements.



1. Understanding AWS IAM: The Foundation of Cloud Security

AWS IAM enables administrators to define:
  • Who can access AWS resources.
  • What actions they can perform.
  • Which resources they can access.
  • Under what conditions access is permitted.
Four important IAM concepts are:
Component
Purpose
IAM User
Identity within an AWS account, potentially with long-term credentials
IAM Group
Collection of IAM users sharing permissions
IAM Role
Assumable identity providing temporary credentials
IAM Policy
JSON document defining permissions

IAM Users

An IAM user represents an identity within an AWS account.
For example, an organization might have IAM users for legacy applications or specific integration requirements.
However, AWS recommends that workforce users access AWS through federation, preferably using IAM Identity Center, rather than relying on long-term IAM user credentials.

IAM Groups

IAM groups simplify permission management for IAM users.
For example:
  • Developers Group
  • Operations Group
  • Security Auditors Group
Policies can be attached to these groups to grant their members appropriate permissions.
Important: IAM groups cannot contain IAM roles or other groups, and a group cannot be assumed as a role.

IAM Roles

IAM roles are designed for temporary, delegated access.
They are commonly used by:
  • EC2 instances
  • AWS Lambda functions
  • Amazon ECS tasks
  • Amazon EKS workloads
  • Federated workforce identities
  • Amazon Bedrock service workflows
Instead of embedding AWS access keys in application code, workloads can use IAM roles to obtain temporary credentials.

IAM Policies

IAM policies define allowed or denied actions.
For example, a policy could allow an application to invoke one approved Amazon Bedrock model while preventing access to unrelated AWS resources.
Key concept: An IAM role defines an identity and who may assume it; a permissions policy defines what that identity is authorized to do.



2. IAM Policies: How AWS Evaluates Permissions

A typical IAM policy contains these elements:
Element
Meaning
Effect
Allow or Deny
Action
AWS API operations
Resource
Resources the statement applies to
Condition
Optional restrictions
Principal
Identity specified in applicable resource-based policies, including role trust policies
AWS follows an important authorization principle:
Access is denied by default unless an applicable policy allows it. An applicable explicit Deny overrides an Allow.
Effective permissions can also be restricted by service control policies (SCPs), permissions boundaries, session policies, resource policies, and other applicable controls.
This layered evaluation helps organizations enforce security guardrails even when individual permissions policies are overly broad.



3. Real-World Scenario: Secure Access to Amazon Bedrock

Imagine an organization building an internal AI assistant to help employees retrieve information and answer questions.
The architecture includes:
  • Developers who configure and maintain the application.
  • An application hosted on Amazon EC2 or AWS Lambda.
  • Amazon Bedrock for generative AI inference.
  • Amazon S3 for approved business documents.
  • A security team responsible for governance and auditing.
The business has four requirements:
  1. Developers should not receive unrestricted administrator permissions.
  1. The application should invoke only approved AI models.
  1. Access to business documents must be limited to authorized workflows.
  1. Security teams must be able to review access activity and investigate suspicious operations.

Recommended Access Architecture

ORGANIZATION
|
IAM Identity Center
|
Federated Developers
|
Developer IAM Role
|
Approved AWS Actions

AI APPLICATION
|
EC2 / AWS Lambda
|
Workload IAM Role
|
+----------+----------+
| |
Amazon Bedrock Amazon S3
Approved Model Approved Data
|
AI Response

SECURITY & AUDIT
|
CloudTrail / Config
|
IAM Access Analyzer
|
Security Monitoring
This design separates human access, application permissions, data permissions, and security oversight.
It also reduces the risk associated with long-term credentials.



4. Implementing Least-Privilege Access for Amazon Bedrock

Suppose our application needs to invoke only one approved foundation model.
A common mistake is attaching a broad policy such as  AdministratorAccess  or  AmazonBedrockFullAccess  without evaluating whether those permissions are necessary.
A better approach is to create a customer-managed IAM policy that grants only the required API actions.

Example: Restrict Model Invocation

The following example uses an illustrative foundation-model ARN. Replace it with the ARN of an approved model supported in your AWS Region.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowApprovedModelInvocation",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel"
],
"Resource": [
"arn:aws:bedrock:us-east-1::foundation-model/APPROVED_MODEL_ID"
]
}
]
}

How this policy works

Effect: Allow
Permits the specified operation.
Action: bedrock:InvokeModel
Allows the principal to invoke a supported Amazon Bedrock model through the relevant inference APIs.
Resource
Restricts the permission to the specified foundation-model ARN.
For streaming responses, additional permissions such as  bedrock:InvokeModelWithResponseStream  may be required.
Some models also use inference profiles or additional inference resources. In those cases, the policy must include the appropriate resource ARNs and permissions.
This example demonstrates the principle of least privilege rather than a complete production deployment policy.
Security benefit: The application receives narrowly scoped model invocation permissions instead of broad administrative access.



5. IAM Roles: Why Temporary Credentials Matter for AI Applications

Consider an application running on an EC2 instance.
A developer might initially configure AWS access keys as environment variables or store them inside the application.
This introduces several risks:
  • Credentials may accidentally be committed to GitHub.
  • Secrets may appear in logs or build artifacts.
  • Long-term keys require additional lifecycle management.
  • Compromised credentials may remain usable until revoked.

Recommended Solution: Use an IAM Role

Create an IAM role with the required Amazon Bedrock permissions and associate it with the EC2 instance through an instance profile.
The application can then use the AWS SDK's default credential provider chain to obtain temporary credentials.
import boto3
import json

client = boto3.client(
"bedrock-runtime",
region_name="us-east-1"
)

response = client.invoke_model(
modelId="APPROVED_MODEL_ID",
contentType="application/json",
accept="application/json",
body=json.dumps({
"YOUR_MODEL_SPECIFIC_REQUEST": "VALUE"
})
)
Note: The request body is illustrative. The actual JSON structure depends on the selected model's inference API.
No hardcoded access keys are required when the runtime has an appropriately configured IAM role.
AWS automatically provides temporary credentials through the supported workload credential mechanism.



6. IAM Roles for Amazon Bedrock Agents

Amazon Bedrock Agents introduce another important security consideration.
An AI agent may need to interact with multiple AWS services to complete a business workflow.
For example, an agent might:
  1. Receive a user's request.
  1. Retrieve relevant information from an approved knowledge base.
  1. Invoke a foundation model.
  1. Call an authorized action group.
  1. Return a response.
An Amazon Bedrock Agent can use a service role that allows the service to perform its configured operations.
This role requires two separate policy components.

A. Trust Policy

A trust policy determines which service or identity can assume the role.
For a Bedrock Agent service role, the trusted service principal is:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "bedrock.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
This is a simplified example. For production, use the AWS-documented service-role trust policy with appropriate  aws:SourceAccount  and  aws:SourceArn  conditions to reduce confused-deputy risks.

B. Permissions Policy

The permissions policy determines what Amazon Bedrock may do after assuming the role.
Depending on the agent's configuration, permissions may include:
  • Invoking approved foundation models.
  • Accessing specific S3 objects containing action-group schemas.
  • Retrieving information from authorized knowledge bases.
  • Performing other explicitly approved service operations.
Important distinction: Permissions for a user or application to invoke a Bedrock Agent are different from the permissions assigned to the agent's own service execution role.
For example, an application calling an agent may need  bedrock:InvokeAgent , whereas the agent's service role needs permissions for the resources it uses internally.
These permissions should not be combined into one unrestricted role.



7. IAM and Compliance: Building Security Into AI Workloads

Security and compliance are related, but they are not identical.
IAM helps implement technical controls that support compliance objectives. However, simply configuring IAM does not automatically make an organization compliant with standards such as ISO 27001, SOC 2, PCI DSS, or GDPR.
Compliance depends on the organization's applicable requirements, operational processes, evidence, and independent assessments where required.

Security and compliance controls

Security objective
AWS implementation
Least privilege
Customer-managed IAM policies
Strong authentication
IAM Identity Center and MFA
Temporary credentials
IAM roles and AWS STS
Separation of duties
Separate developer, deployment, and audit roles
Access reviews
IAM Access Analyzer and periodic reviews
Audit logging
AWS CloudTrail
Configuration monitoring
AWS Config
Organization-wide restrictions
AWS Organizations SCPs
Data protection
KMS, encryption, and resource policies
Threat detection
Amazon GuardDuty

Principle 1: Least Privilege

Grant only the permissions required for a specific task.
An application that only invokes an approved model should not automatically receive permissions to delete S3 buckets, create IAM users, or modify networking resources.

Principle 2: Separation of Duties

Avoid assigning the same unrestricted permissions to developers, production applications, and security auditors.
For example:
  • Developers deploy approved application changes.
  • Application roles invoke permitted AI models.
  • Security auditors review configuration and access activity.
  • Platform administrators manage infrastructure through controlled processes.

Principle 3: Continuous Monitoring

Use AWS CloudTrail and other monitoring services to review relevant activity.
For Amazon Bedrock, consider model invocation logging where supported and appropriate. Standard CloudTrail event coverage should not be assumed to capture complete model prompts and responses.
Because prompts and responses may contain sensitive information, logging destinations, retention periods, encryption, and access controls should follow organizational data-governance policies.

Principle 4: Prevent Privilege Escalation

Pay special attention to the  iam:PassRole  permission.
A developer who cannot directly invoke a restricted model might still create a service workflow that invokes it through a more privileged role if role passing is not appropriately restricted.
Limit  iam:PassRole  to approved role ARNs and, where supported, use conditions such as  iam:PassedToService .

Principle 5: Review Permissions Regularly

Permissions that were appropriate six months ago may no longer be necessary.
Use IAM Access Analyzer, access activity information, and security reviews to identify unused or excessive permissions.



8. Common IAM Security Mistakes in AI Projects

These are some mistakes organizations should avoid.
Mistake 1: Using the root account for daily development
The root user has extensive account-level privileges and should be reserved for tasks that specifically require root access.
Mistake 2: Assigning AdministratorAccess to every developer
This violates least-privilege principles and increases the potential impact of compromised credentials.
Mistake 3: Hardcoding AWS credentials in AI application code
Use IAM roles and temporary credentials instead.
Mistake 4: Allowing unrestricted model access
Restrict invocation to approved models and inference resources where possible.
Mistake 5: Ignoring AI data permissions
A narrowly scoped model invocation policy does not automatically protect sensitive information stored in S3, databases, or knowledge bases.
Mistake 6: Giving an AI agent excessive tool permissions
An AI agent should not have unrestricted access to delete resources, modify IAM policies, or execute privileged operations simply because it can automate workflows.
Use narrowly scoped tools, application-level authorization, and approval steps for sensitive actions.



9. Practical Security Checklist Before Deploying an AI Application

Before moving an Amazon Bedrock application into production, ask:
  • Are human users accessing AWS through approved federated identities?
  • Are MFA requirements enforced?
  • Does the application use temporary credentials?
  • Are IAM permissions restricted to required actions and resources?
  • Are Bedrock model permissions limited to approved models?
  • Are S3 and knowledge-base permissions appropriately scoped?
  • Are service-role trust relationships restricted?
  • Is  iam:PassRole  appropriately controlled?
  • Are audit logging and security monitoring configured?
  • Have IAM policies been reviewed with IAM Access Analyzer?
  • Are sensitive AI inputs, outputs, and logs protected?
  • Are retention, residency, and compliance requirements documented?
This checklist is a useful starting point, but it should be adapted to the organization's security and regulatory requirements.



10. Final Thoughts: Secure AI Starts With Identity

As organizations adopt Generative AI and agentic workflows, IAM becomes more important than ever.
AI applications can interact with business data, invoke cloud services, and perform automated actions. Without properly designed access controls, these capabilities can introduce significant security risks.
A strong AWS security design should follow three principles:
1. Authenticate every identity.
Know whether the request comes from a developer, application, service, or automated agent.
2. Authorize only what is necessary.
Grant narrowly scoped permissions based on responsibilities and approved business requirements.
3. Monitor and review access continuously.
Maintain visibility into who accessed resources, what actions were performed, and whether permissions remain appropriate.
The goal is not simply to make AI applications work. It is to make them secure, auditable, maintainable, and aligned with business requirements.

Community Discussion

As AI agents become capable of executing actions across multiple AWS services, how should organizations balance automation with security?
Would you prefer strict least-privilege IAM roles for every agent, centralized access controls, or additional human approval for sensitive actions?
I'd love to hear how other AWS builders are approaching IAM security and governance for AI workloads.

References

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article