AWS-114 · Lesson 7 of 12 · 18 min
Securing AI systems with IAM and encryption
▶ Video coming soon A video version of this lesson is on the way.
Gwen Halvorsen, the cloud architect leading the AWS move, joined Noor's session for this topic. She had spent the autumn securing Cascade Ridge's accounts: protecting the root user, setting up IAM Identity Center, encrypting data with AWS KMS and turning on detection services. "AI doesn't replace any of that," she told Jonah. "It sits on top of it. An AI application is still an application. It has identities, it reads data, it calls services and it writes logs. Every one of those is something to secure."
What is new, Gwen explained, is that AI applications handle unusually sensitive material, such as entire call transcripts, and can take actions on a user's behalf. This lesson applies the security basics to AI: identity and permissions, encryption, private networking, data discovery, controls for agents, and the shared responsibility model for AI services. The exam guide names these services and features in its security task statement.
The shared responsibility model for AI
The shared responsibility model applies to AI services just as it does to the rest of AWS. For a managed service such as Amazon Bedrock, AWS is responsible for the security of the service itself: the infrastructure, the model hosting environment, and keeping customers' data separate. Amazon Bedrock does not use customers' prompts and responses to train the foundation models it offers, and model providers do not receive them, according to AWS's documentation; check the current terms for any service you use.
The customer is responsible for security in the cloud: who in the organization may call the models, what data is sent to them, how that data is encrypted, how outputs are handled, which guardrails apply, and what is logged. When a customer fine-tunes a model with its own data, the resulting custom model and the training data are the customer's to protect.
Identity and permissions
The first layer is identity. Every person and every program that touches the AI system should have its own identity with the least privilege it needs.
- People sign in through IAM Identity Center with their own identities. Noor has permission to experiment with models in the development account. Jonah can view evaluation results but not change the production configuration.
- Applications use IAM roles, which provide temporary credentials automatically. The summarizer runs with a role that can call one specific model, apply one specific guardrail, and read from one specific bucket. There are no long-term access keys in its code.
- Policies state exactly what each role may do. IAM policies can name the specific foundation models a role may invoke, so a developer cannot quietly switch to a different model, and can require a guardrail on every call.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InvokeApprovedModelOnly",
"Effect": "Allow",
"Action": ["bedrock:InvokeModel"],
"Resource": "arn:aws:bedrock:REGION::foundation-model/APPROVED-MODEL-ID"
},
{
"Sid": "ApplyApprovedGuardrail",
"Effect": "Allow",
"Action": ["bedrock:ApplyGuardrail"],
"Resource": "arn:aws:bedrock:REGION:ACCOUNT-ID:guardrail/GUARDRAIL-ID"
}
]
}In the multi-account setup Gwen built, service control policies in AWS Organizations add an outer limit: for example, denying the use of any foundation model in Regions outside the approved ones. Even an administrator in a member account cannot override that. Lesson 8 shows why this matters for data residency.
# How an allow-list of approved models works, in miniature.
APPROVED = {"summarizer-role": {"approved-text-model-v2"}}
requests = [
("summarizer-role", "approved-text-model-v2"),
("summarizer-role", "experimental-model-x"),
("web-assistant-role", "approved-text-model-v2"),
]
for role, model in requests:
allowed = model in APPROVED.get(role, set())
print(f"{role:18} -> {model:24} {'ALLOW' if allowed else 'DENY (not approved for this role)'}")summarizer-role -> approved-text-model-v2 ALLOW summarizer-role -> experimental-model-x DENY (not approved for this role) web-assistant-role -> approved-text-model-v2 DENY (not approved for this role)
What this code does
It shows how an allow-list of approved models works: each role is listed with the models it may call, and any request for a model not on that role's list is denied. Three test requests show an approved model allowed, an experimental model denied, and an approved model denied for a role that has no approvals. This is how organizations stop teams from using models that haven't passed review.
The default is deny. A role with no entry in the list gets nothing, which is how IAM itself works: anything not explicitly allowed is denied.
Encryption
The second layer is encryption, which the exam guide lists as encryption at rest and in transit.
- In transit. Calls to AWS service endpoints, including Amazon Bedrock, use TLS. Internal traffic, such as from the clinical system to the summarizer, should also use TLS.
- At rest. Data stored for the AI system, such as transcripts in Amazon S3, knowledge base content, fine-tuning datasets, custom models and logs, is encrypted with keys in AWS Key Management Service (AWS KMS). AWS services encrypt much of this by default; using a customer managed key lets Cascade Ridge control the key policy, see every use of the key in AWS CloudTrail, and disable the key if needed.
Hannah chose customer managed keys for the transcripts and for the summarizer's logs, because those held the most sensitive content. Disabling the key would make the data unreadable, which gave her a strong control in an emergency.
Private networking
The third layer is the network. By default, an application calls AWS services through their public endpoints, over the internet but encrypted. AWS PrivateLink lets an application in a VPC reach supported services, including Amazon Bedrock and Amazon SageMaker AI, through interface VPC endpoints, so the traffic stays on the AWS network and never crosses the public internet. Endpoint policies can further limit which actions and resources are allowed through the endpoint.
Gwen placed the summarizer's processing in private subnets with no route to the internet and gave it interface endpoints for Bedrock, S3 and KMS. "If someone ever gets code running in that subnet," she said, "it has nowhere to send our data except the services we chose."
Finding sensitive data with Amazon Macie
You cannot protect sensitive data you do not know you have. Amazon Macie uses machine learning and pattern matching to discover sensitive data, such as names, phone numbers, addresses and payment card numbers, in Amazon S3 buckets, and reports where it is and whether the buckets are exposed. The exam guide names Macie among the services that secure AI systems because AI projects often gather large amounts of data into new places.
Before Noor assembled the 300 transcripts for the summarizer's evaluation, Hannah ran Macie on the bucket. It found client phone numbers and two card numbers that callers had read aloud to pay a bill. The evaluation set was rebuilt with those details masked, and the finding became a requirement for the production design: card numbers spoken on calls are masked before any transcript is stored.
Controls for agents
When AI systems act through tools, their identities and permissions need special care. The exam guide names two features of Amazon Bedrock AgentCore, AWS's set of services for running AI agents.
- AgentCore Identity manages identities and credentials for agents, so an agent can act for a specific user, or on its own behalf, with credentials it obtains securely when needed, instead of secrets stored in its code.
- Policy in AgentCore lets you define rules, written in the Cedar policy language, that decide which tool calls an agent may make and under what conditions. It checks each call before it reaches the tool and denies anything not explicitly permitted.
For the booking agent idea from lesson 6, Noor sketched the policy in plain words: the agent may search for open slots and hold a slot for ten minutes; it may book only for the client who is signed in; it may never cancel a booking it did not make; and any surgery booking requires staff approval. The point is that limits are enforced outside the model. Even if the model were manipulated into trying something else, the policy would deny it.
Protecting knowledge bases and training data
Generative AI systems often draw on a knowledge base: a collection of documents that is split into chunks, converted to vectors and stored so the system can retrieve relevant passages for each question. The website assistant's knowledge base held clinic hours, parking instructions, booking policies and the list of services. A knowledge base is data like any other, and it needs the same protection, plus one extra thought: anything in it might be quoted to a user.
Noor and Hannah agreed two rules. First, a knowledge base for a public assistant contains only material that is already public, so even a perfect attack could reveal nothing secret. Client records never go near it. Second, if an internal assistant ever needs access to restricted documents, the retrieval step must respect the user's own permissions, so the system cannot hand someone a passage they would not be allowed to open themselves. The same thinking applies to fine-tuning data: a model trained on sensitive records can sometimes reproduce parts of them, so sensitive fields are removed before training, not after.
Threat detection and vulnerability management
The exam guide also lists threat detection, vulnerability management and infrastructure protection among the security considerations for AI systems. These are the same services that protect the rest of the environment. Amazon GuardDuty watches account activity, network traffic and other signals for threats, such as credentials being used from an unusual location or an instance contacting a known malicious address; it also offers protection for some AI workloads. Amazon Inspector scans EC2 instances, container images and Lambda functions for known software vulnerabilities and unintended network exposure, which matters because AI applications are built from code libraries that need patching like any others. AWS WAF can filter abusive traffic to a public assistant, such as floods of requests from a single source.
Gwen had already turned these on across all accounts during the autumn. For the AI workloads she added one alarm: an unusual rise in calls to Bedrock from any role, which could signal a stolen credential being used to run up costs or extract data.
Guardrails as a security control
Amazon Bedrock Guardrails, covered in lesson 4, is also a security feature. Sensitive information filters prevent personal data from leaking into responses, and the prompt attack filter helps detect attempts to override the system's instructions. Requiring a guardrail on every model call, through application code and IAM policy, makes sure no path skips it.
| Concern | AWS service or feature |
|---|---|
| Who may call which model | IAM roles and policies; service control policies |
| Agents acting with the right credentials | Amazon Bedrock AgentCore Identity |
| Which tool calls an agent may make | Policy in Amazon Bedrock AgentCore |
| Encryption at rest with controlled keys | AWS KMS customer managed keys |
| Traffic that never crosses the internet | AWS PrivateLink interface endpoints |
| Finding sensitive data in S3 | Amazon Macie |
| Filtering harmful content and personal data in prompts and responses | Amazon Bedrock Guardrails |
| Recording who did what | AWS CloudTrail (lesson 11) |
Common mistakes
MistakeGiving an AI application an administrator role so it "just works".
InsteadGrant only the specific model, guardrail and data access the application needs.
MistakeStoring an API key or access key in the application code.
InsteadUse IAM roles for applications and AgentCore Identity for agents.
MistakeAssuming the model's instructions will stop an agent from taking unsafe actions.
InsteadEnforce limits outside the model with IAM and Policy in AgentCore, denying by default.
MistakeCollecting data for an AI project without checking what it contains.
InsteadScan it with Amazon Macie and mask or remove sensitive data before use.
Worked problem
Close the gaps
A prototype summarizer runs on a developer's laptop, uses an access key stored in a configuration file, sends transcripts to a model over the public internet, saves outputs in an unencrypted bucket and can call any model in any Region. List one control for each problem.
Show solution
- Move the code to an AWS environment and use an IAM role with temporary credentials instead of a stored key.
- Call the model through an interface VPC endpoint with AWS PrivateLink.
- Encrypt the bucket with a KMS key, ideally a customer managed key, and block public access.
- Limit the role to the approved model, and use a service control policy to deny other Regions.
Answer: IAM role instead of keys; PrivateLink endpoints; KMS encryption; least-privilege model access backed by a service control policy.
Summary and key terms
- AI applications need the same security basics as any application, applied to unusually sensitive data and to actions taken on users' behalf.
- Under shared responsibility, AWS secures the AI services themselves and the customer secures its identities, data, configuration and use.
- Least-privilege IAM roles and policies can limit which models and guardrails each role uses, with service control policies as an outer limit.
- AWS KMS encrypts data at rest and TLS protects data in transit.
- AWS PrivateLink keeps traffic to services such as Bedrock off the internet.
- Amazon Macie finds sensitive data in S3.
- AgentCore Identity and Policy in AgentCore control what agents can do, and Bedrock Guardrails filters prompts and responses.
- IAM role
- An identity with temporary credentials, used by applications instead of stored keys.
- Customer managed key
- A KMS key whose policy and use the customer controls.
- AWS PrivateLink
- Private connectivity from a VPC to supported AWS services through interface endpoints.
- Amazon Macie
- A service that discovers sensitive data in Amazon S3.
- AgentCore Identity
- Identity and credential management for AI agents.
- Policy in AgentCore
- Rules, written in Cedar, that allow or deny an agent's tool calls.
Practice problems
Work each problem on paper first, then reveal the answer to check.
How can a team stop developers using unapproved foundation models?
Show answer
Grant access only to approved model ARNs in IAM policies, and use service control policies as an outer limit.
Which service finds card numbers stored in S3?
Show answer
Amazon Macie.
What keeps calls to Bedrock off the public internet?
Show answer
An interface VPC endpoint using AWS PrivateLink.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.