Appearance
Cloud Identity and Security
546. What is IAM, and what is the difference between authentication and authorization?
The short answer
IAM, identity and access management, is the system that decides who can do what to which resource in your cloud. Authentication answers "who are you?", by checking a password, a key, a certificate or a token. Authorization answers "what are you allowed to do?", by checking the permissions attached to that identity against the action and the resource. Every single cloud API call goes through both steps.
Picture an office building. Showing your ID card at the front desk is authentication: the guard now knows who you are. Your card opening the third floor but not the server room is authorization: what you may do, now that you are known.
The building blocks, in every cloud:
| Term | Meaning | Example |
|---|---|---|
| Identity, or principal | Anything that can make a request | A person, an app, a pipeline |
| User | An identity for a person | priya@shop.example |
| Group | A set of users, given permissions together | payments-engineers |
| Role | A named set of permissions | "Storage Blob Data Reader" |
| Policy | A document saying which actions are allowed or denied | "May read objects in bucket X" |
| Service identity | An identity for software, not a person | A managed identity, an IAM role |
How the clouds split the work:
- Azure keeps identities in Entra ID, the directory of users, groups and apps for the whole company. Permissions on cloud resources come from Azure RBAC, role-based access control, which assigns roles to those identities.
- AWS IAM holds both identities and permissions inside each account. For people, most companies use IAM Identity Center for single sign-on across accounts (question 554).
- Google Cloud uses Google accounts or Cloud Identity for identities, and IAM role bindings for permissions.
Two failures, two different errors. In HTTP terms, a failed authentication returns 401 Unauthorized, meaning "I do not know who you are". A failed authorization returns 403 Forbidden, meaning "I know who you are, and the answer is no". Reading which one you got tells you where to look.
547. How are cloud permission policies written and evaluated?
The short answer
A policy lists statements, and each statement says whether an action on a resource is allowed or denied, sometimes only under conditions. When a request arrives, the cloud gathers every policy that applies. In AWS, everything starts denied, an allow anywhere permits the action, and an explicit deny anywhere overrides every allow. Azure RBAC is additive: your permissions are the sum of all role assignments that apply at that scope and above.
An AWS policy, for the checkout service, reading and writing receipts in one bucket. The comments are only here for reading; real policies are plain JSON:
jsonc
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow", // (1)
"Action": ["s3:GetObject", "s3:PutObject"], // (2)
"Resource": "arn:aws:s3:::shop-receipts/*", // (3)
"Condition": { // (4)
"Bool": { "aws:SecureTransport": "true" }
}
},
{
"Effect": "Deny", // (5)
"Action": "s3:DeleteObject",
"Resource": "arn:aws:s3:::shop-receipts/*"
}
]
}Effectis eitherAlloworDeny.Actionnames the exact API operations, here reading and uploading objects.Resourcenames what it applies to, using an ARN, an Amazon Resource Name, the unique ID of every AWS resource./*means every object in that bucket.Conditionadds rules about the request itself, here "only over HTTPS".- An explicit deny. Even if some other policy allows deleting receipts, this statement wins.
Where AWS policies can live:
| Kind | Attached to | Example |
|---|---|---|
| Identity-based | A user, group or role | "The checkout role may read this bucket" |
| Resource-based | The resource itself | A bucket policy: "this other account may write here" |
| Guardrail | An organisation or account | A service control policy: "nobody may leave the EU regions" (question 556) |
| Permission boundary | One user or role | "This role can never get more than these permissions" |
Azure RBAC works differently. A role assignment has three parts:
- Who: a user, group or managed identity.
- What: a role definition, such as
Storage Blob Data Contributor. - Where: a scope, such as a subscription, a resource group, or one resource.
Assignments inherit downwards. A role on a resource group applies to every resource inside it. Permissions add up, so the person can do everything any of their assignments allows. Blocking actions is done mainly with Azure Policy, which judges the resources themselves, such as "no public IP addresses", rather than the person (question 556).
Control plane versus data plane. In Azure, Contributor lets you manage a storage account, but reading the blobs inside needs a data role such as Storage Blob Data Reader. Many "but I am an owner and it says forbidden" moments come from this split.
548. What is the difference between users and roles, and how do temporary credentials work?
The short answer
A user is a lasting identity, usually for one person, with long-lived credentials such as a password or access keys. A role is a set of permissions that trusted identities can take on for a while: assuming it hands back temporary credentials that expire, often after an hour. Prefer roles everywhere, for people and for software, because a stolen temporary credential stops working soon, and nobody has to remember to rotate it.
How assuming a role works in AWS:
- The role
deploy-prodhas a trust policy saying who may assume it, for example "the pipeline's identity" or "people in the platform team". - The caller asks the Security Token Service, STS, to assume the role.
- STS checks the trust policy, and returns three things: an access key ID, a secret key and a session token, all valid for a limited time.
- The caller uses these to make requests, with exactly the role's permissions.
- When they expire, the caller assumes the role again if it still needs access.
Two policies, two questions:
| Policy | Question it answers |
|---|---|
| Trust policy | Who may become this role? |
| Permission policy | What can the role do once someone has become it? |
In Azure, people sign in to Entra ID and get short-lived tokens automatically. Software uses managed identities, which also get tokens that expire (question 550). For powerful roles, Privileged Identity Management makes a person's admin role "eligible" instead of permanent: they activate it for a few hours, with a reason, and sometimes an approval.
Why temporary is safer. Long-lived keys leak in commits, laptops and logs, and then work for an attacker for months (question 558). A token that expires in an hour limits the damage window to that hour.
549. How do you apply least privilege in a cloud environment?
The short answer
Give every identity only the permissions it needs for its real job, on only the resources it touches, for only as long as it needs them. In practice, each app and each environment gets its own identity. Use narrow built-in roles or custom roles instead of owner or admin, and assign them at the smallest scope. Admin rights are granted just in time, for a task. And permissions that the access logs show are never used are removed regularly.
Least privilege, step by step:
- One identity per workload. The checkout service and the email service get different identities, so one compromised service cannot use the other's access.
- Separate environments. The staging identity cannot touch production. Separate accounts or subscriptions make this a hard wall (question 527).
- Narrow roles.
Storage Blob Data Readeron one storage account, notContributoron the subscription. - Smallest scope. Assign on the resource or resource group, not on the whole subscription.
- Just in time for humans. Admin rights are activated for a task, then expire.
- Prune with data. Cloud tools show which permissions were never used, such as AWS IAM Access Analyzer's unused-access findings. Remove those.
The common mistakes:
| Mistake | Why it hurts |
|---|---|
* in actions or resources | One bug or leak can do anything |
| Everyone in the team is an owner | Every laptop compromise becomes an admin compromise |
| One shared identity for all apps | No way to tell who did what, or to limit damage |
| Permissions only ever added | Over time, everyone can do everything |
Start with access, then narrow. A common practical path has three steps. Give the app a broader built-in role in a development account. Watch in the logs which actions it actually uses. Then write a narrow role from that list for production.
The same idea for pipelines and Kubernetes is in questions 271 and 415.
550. How do managed identities or instance roles let an app reach cloud services without storing secrets?
The short answer
The cloud gives the machine, container or function its own identity, and a local metadata service, only reachable from inside, hands out short-lived tokens for it. The app's SDK fetches a token automatically and uses it to call storage, databases or the secret store. There is no password or key in the code, the configuration or the image, nothing to rotate, and nothing to leak. Azure calls these managed identities, AWS uses IAM roles attached to instances or tasks, and Google uses service accounts.
The metadata service is a special address, 169.254.169.254, that every cloud machine can reach but nothing outside can. It answers questions about the machine, and hands out tokens for its identity.
In code, the app does not even see this. For the checkout service on Azure, uploading a receipt:
ts
import { DefaultAzureCredential } from '@azure/identity'
import { BlobServiceClient } from '@azure/storage-blob'
const credential = new DefaultAzureCredential() // (1)
const blobs = new BlobServiceClient(
'https://stshop.blob.core.windows.net', credential) // (2)
export async function saveReceipt(orderId: string, pdf: Buffer) {
const file = blobs.getContainerClient('receipts')
.getBlockBlobClient(`${orderId}.pdf`)
await file.uploadData(pdf) // (3)
}DefaultAzureCredentialtries several sources in order. In the cloud it finds the managed identity. On a developer's laptop it uses their ownaz loginsign-in instead. The same code works in both places.- The client gets the credential, not a connection string with a key in it.
- Each call carries a token that the SDK fetched, cached and will refresh before it expires.
For this to work, the identity needs a role on the storage account, here Storage Blob Data Contributor on stshop only (question 549).
Two kinds of Azure managed identity:
| System-assigned | User-assigned | |
|---|---|---|
| Lifetime | Tied to one resource; deleted with it | Its own resource; lives on |
| Shared by several resources | No | Yes |
| Good for | One app, one machine | A group of instances, or keeping roles across rebuilds |
One attack to know: SSRF. In a server-side request forgery, an attacker tricks your app into fetching a URL they choose, such as the metadata address, to steal the token. AWS's IMDSv2 requires a special session token from a PUT request first, which most forgery tricks cannot send. Require IMDSv2 on every AWS machine. Azure's metadata service requires a Metadata: true header for the same reason.
In Kubernetes, each pod should get its own identity rather than the node's, through workload identity (question 615).
551. What is a key management service, and how does envelope encryption work?
The short answer
A key management service, such as AWS KMS, Azure Key Vault or Google Cloud KMS, stores master keys inside hardware that never lets the raw key out. It encrypts and decrypts with those keys on request, and it checks permissions and logs every use. Envelope encryption uses this efficiently: each piece of data is encrypted locally with its own fresh data key, and only that small data key is sent to the KMS to be encrypted with the master key. The encrypted data key is stored next to the data, like a letter sealed in an envelope.
Why not encrypt everything with the master key directly? Two reasons. Sending gigabytes to the KMS would be slow, and the KMS only accepts small amounts, a few kilobytes. And if the master key ever had to leave the KMS to do the work, it could be stolen.
Step by step, writing:
- The app asks the KMS for a new data key.
- The KMS returns the data key twice: in plain form, and encrypted with the master key.
- The app encrypts the file locally, fast, with the plain data key, using a strong method such as AES-256.
- The app throws the plain data key away and stores the encrypted file with the encrypted data key.
Reading:
- The app sends the encrypted data key to the KMS.
- The KMS checks the app is allowed to use the master key, logs the request, and returns the plain data key.
- The app decrypts the file locally.
What this gives you:
- The master key never leaves the hardware, called an HSM, hardware security module.
- Every use is checked and logged, so you can see who decrypted what, and when.
- Revoking access is instant. Remove the permission on the master key, and nobody can unseal any data key, so all the data becomes unreadable for them at once.
- Rotating the master key is cheap. Only the small data keys need re-encrypting, not the data itself, and KMS services keep old key versions to read old data.
Customer-managed keys. By default, the cloud encrypts storage with keys it manages for you. Some rules require customer-managed keys, where the master key lives in your own key vault, so you control its access, rotation and deletion. Be careful: deleting that key makes the data unreadable for ever, which is why key vaults have soft delete and purge protection.
The same pattern encrypts Kubernetes Secrets at rest (question 379).
552. What is the difference between encryption at rest and encryption in transit?
The short answer
Encryption at rest protects stored data, on disks, in databases, in backups and in object storage, so a stolen disk or snapshot is unreadable without the key. Encryption in transit protects data while it moves over a network, usually with TLS, so nobody listening on the path can read or change it. You need both, because they defend against different attacks. Neither protects against an attacker who has your app's own permissions, which is why access control comes first.
| At rest | In transit | |
|---|---|---|
| Protects | Stored data | Data moving between machines |
| Against | Stolen disks, copied snapshots, lost backups | Eavesdropping and tampering on the network |
| Usual method | AES-256 with KMS-managed keys | TLS, version 1.2 or 1.3 |
| In the cloud | Usually on by default for storage and databases | Must be enforced: HTTPS only, TLS to the database |
What to enforce for in transit:
- HTTPS only on load balancers, with HTTP redirecting to HTTPS.
- A minimum TLS version of 1.2 on storage accounts, databases and APIs.
- TLS to the database, verified, not only "encryption allowed".
- Inside the cluster, a service mesh can add mutual TLS between services (question 514).
What neither protects against. If an attacker steals the app's identity, the cloud happily decrypts data for them, because they look exactly like the app. Encryption is one layer. Least privilege, network isolation and monitoring are the others (question 549).
A third kind, briefly: encryption in use. Confidential computing keeps data encrypted even in memory while it is being processed, inside special hardware areas of the processor. It is used for very sensitive workloads, and is still uncommon.
553. How do you manage application secrets in the cloud?
The short answer
Keep secrets in a managed secret store, such as Azure Key Vault, AWS Secrets Manager or Google Secret Manager, never in code, images or plain configuration files. The app reads them at runtime using its managed identity, so the only credential it needs is one it never sees. Better still, avoid secrets altogether where the service supports identity-based access. Rotate the secrets that remain, automatically where possible, and log and alert on every read.
The order of preference:
- No secret at all. Use managed identities for storage, databases, queues and the secret store itself (question 550).
- A secret in a managed store, read at runtime by the app's identity.
- Never: in source code, in a Dockerfile, in an image, in a plain environment file committed to Git (questions 144 and 145).
What the store gives you:
| Feature | Why it matters |
|---|---|
| Access control per secret or vault | Only the checkout service can read the payment key |
| Audit log of every read | You know who read what, and when |
| Versions | Roll back to the previous value after a bad change |
| Rotation | Change secrets regularly, sometimes automatically |
| Soft delete | Recover a secret deleted by mistake |
Rotation without downtime. For a database password:
- Create a new password, and let the database accept both the old and the new.
- Store the new one as the latest version in the secret store.
- Apps pick up the new version, on their next refresh or restart.
- When nothing uses the old one, remove it from the database.
AWS Secrets Manager can run this cycle on a schedule for supported databases.
Cache, but not for ever. Fetching a secret on every request is slow and costly. Read it at start-up or cache it for minutes, and refresh it periodically so a rotation is picked up.
In Kubernetes, the External Secrets Operator or the Secrets Store CSI Driver brings store secrets into pods (question 492).
554. How do single sign-on and identity federation work in the cloud?
The short answer
Federation means one trusted identity provider, such as Entra ID, Okta or Google Workspace, proves who a person is, and other systems accept that proof instead of keeping their own passwords. Single sign-on is the result for people: one login, with multi-factor authentication, gives access to the cloud consoles, Git, the CI system and other tools. When someone leaves, disabling one account removes all their access at once. The same trust idea, with tokens instead of people, lets pipelines reach the cloud without keys.
How a login flows, simplified:
- Priya opens the AWS access portal.
- The portal sends her to the company's identity provider, say Entra ID.
- Entra ID checks her password and her second factor, such as a phone app.
- Entra ID sends back a signed statement: "this is Priya, in groups
payments-engineersandplatform-oncall". - AWS checks the signature, trusts the statement, and lets her assume the roles those groups are allowed.
The two common standards:
| SAML 2.0 | OpenID Connect, OIDC | |
|---|---|---|
| Format | XML signed statements | JSON tokens, called JWTs |
| Common for | Enterprise apps, older systems | Modern apps, mobile, CI pipelines |
A JWT, JSON web token, is a small signed piece of JSON carrying claims, such as who the user is and when the token expires.
Why it matters:
- One place to remove access when people leave or change teams.
- Multi-factor authentication enforced once, for everything.
- Groups drive permissions, so access follows the team, not hand-made individual grants.
- No cloud user passwords to forget, share or leak.
For software, the same trust works with workload tokens: GitHub Actions presents an OIDC token and gets cloud credentials (question 269), and Kubernetes pods do the same with workload identity (question 615).
555. How do audit logs and threat detection work in the cloud?
The short answer
Every cloud records who did what to which resource, and when, in audit logs: AWS CloudTrail, the Azure activity log with Entra sign-in logs, and Google Cloud audit logs. Send them to a central, protected place, keep them for as long as your rules require, and alert on dangerous events. On top of that, threat detection services such as Amazon GuardDuty and Microsoft Defender for Cloud analyse logs and network activity for signs of attack, and posture tools flag risky settings before they are used against you.
What the audit logs record:
| Log | Records | Example |
|---|---|---|
| Control plane, management events | Changes to resources | "Ravi deleted the firewall rule at 14:02" |
| Data plane, data events | Access to data, often off by default | "The checkout role read receipts/8812.pdf" |
| Sign-in logs | Logins and failures | "Priya signed in from a new country" |
Make them useful:
- Turn on what you need. Data events, such as every object read, cost more and are often off by default. Enable them for sensitive stores.
- Centralise. Send every account's logs to one security account or one workspace, which normal admins cannot change.
- Protect them. Write-once storage, or a separate account, so an attacker cannot delete their own tracks.
- Keep them for as long as rules require, often a year or more. Built-in history in the consoles is only around 90 days.
- Alert on what matters, not on everything.
Events worth an alert:
- The root account, or a global admin, signing in.
- Audit logging being turned off.
- A storage bucket or database becoming public.
- New access keys created for a powerful user.
- A firewall rule opening SSH or RDP to the internet.
- Sign-ins from impossible locations, two countries in ten minutes.
The detection layer:
- Threat detection watches activity: Amazon GuardDuty, Microsoft Defender for Cloud, Google Security Command Center. They spot things like a machine talking to a known crypto-mining server, or keys used from an unusual place.
- Posture management, called CSPM, cloud security posture management, checks your settings against best practices: "this storage account allows public access", "this database has no backup".
556. How do organisation guardrails like service control policies and Azure Policy work?
The short answer
Guardrails are rules set at the top of the organisation that every account or subscription below must follow, whatever permissions people have inside. AWS service control policies limit the maximum permissions anyone in an account can ever use, even the account's own admins. Azure Policy checks resources as they are created or changed, and can deny them, flag them, or fix them, for example "no public IP addresses" or "only these regions". They turn security rules from documents people must remember into rules the platform enforces.
Two different ideas:
| AWS service control policy | Azure Policy | |
|---|---|---|
| Judges | Who may call which actions | What resources may look like |
| Applies to | Every identity in the accounts below | Every resource in the scopes below |
| Grants permissions | Never, it only limits | No |
| Example | "No one may disable CloudTrail" | "Storage accounts must disable public access" |
A service control policy works like a ceiling. Real permissions are the overlap of what the identity's own policies allow and what the guardrail allows. A developer with full admin rights in a sandbox account still cannot create resources outside the allowed regions if the guardrail forbids it.
Azure Policy effects, from soft to strong:
- Audit: allow, but mark the resource as non-compliant in a report.
- Deny: refuse to create or change the resource.
- Modify: change the request, such as adding a missing tag.
- Deploy if not exists: create something missing, such as diagnostic settings that send logs to the central workspace.
Typical guardrails:
- Allowed regions only, for data residency rules.
- No public storage, no public IP addresses outside the network team's subscriptions.
- Audit logging can never be disabled.
- Required tags, such as
ownerandenv(question 528). - Only approved machine sizes, to stop expensive surprises.
Start with audit, then deny. Roll out a new guardrail in audit mode, fix what it finds, then switch to deny, so you do not break running teams overnight. The same habit applies inside Kubernetes with policy engines (question 500).
Landing zones. A landing zone is a pre-built, guarded starting point for new teams: the account or subscription structure, networks, logging, identity and guardrails, all created from code. A new team gets a subscription that is already safe, instead of starting from an empty one.
557. A storage bucket with customer data was found open to the public; how do you respond, and how do you prevent it?
The short answer
First stop the exposure: block public access on the bucket immediately. Then find out what happened: how long it was public, which files were in it, and whether anyone downloaded them, using access logs if they were enabled. Bring in the security and legal teams, because exposed customer data may need to be reported to regulators and customers within strict deadlines. Then prevent a repeat with account-wide public-access blocks, guardrails that deny public storage, private endpoints, and alerts on any public change.
Respond, in order:
- Contain. Turn on block public access for the bucket, or disable anonymous access on the Azure storage account. Do it now, before investigating.
- Preserve evidence. Do not delete the bucket or the logs. You need them to answer what happened.
- Find the window. The audit log shows when the bucket's policy or setting changed, and who changed it (question 555).
- Find what was taken. Data access logs, if enabled, show which objects were read and from which addresses. If they were not enabled, you may have to assume everything was exposed.
- Escalate. Security, legal and privacy teams decide on notification. Many data protection laws, such as the GDPR in the EU, require reporting serious breaches to the regulator within 72 hours.
- Fix the cause, then write a blameless review: what allowed this, and what guardrail would have stopped it.
Prevent it:
| Layer | Control |
|---|---|
| Account | Block public access for every bucket in every account; S3 new buckets block public access by default since 2023 |
| Organisation | Guardrail that denies turning public access on (question 556) |
| Network | Private endpoints, with public network access disabled (question 537) |
| Detection | Alert within minutes when anything becomes public |
| Design | Share files with short-lived signed URLs, not public buckets |
Signed URLs are the safe way to share one file: a link that grants access to one object, for a short time, signed with the app's credentials. Azure calls them SAS tokens, shared access signatures. Prefer ones signed with an identity, such as a user delegation SAS, over ones signed with the storage account key, because the account key can sign anything.
558. A cloud access key was accidentally committed to a public Git repository; what do you do?
The short answer
Treat the key as stolen the moment it was pushed, because bots scan public repositories within minutes. Disable or delete the key first, then create a new one where it is still needed. Next, check the audit logs for everything the key did since it was exposed, and undo any damage, such as new users, new keys or crypto-mining machines. Only then clean the Git history. Finally, remove the need for the key, by moving to short-lived identity federation, and add secret scanning so the next one is blocked at the push.
In order, and fast:
- Revoke. Deactivate or delete the key in the cloud console. Deleting it from the repository does nothing: the key is already copied. AWS and GitHub scan public repositories for keys, and AWS may also restrict a leaked key automatically, but do not rely on that.
- Replace. If something legitimately used the key, give it a new credential, ideally a role instead (question 268).
- Investigate. Search the audit log for every call made with that key ID since the push. Attackers typically create new users or keys to keep access, and start large machines for crypto mining in many regions.
- Clean up everything they created: users, keys, roles, machines, functions. Check the bill for strange spending, and contact the cloud provider's support, who can help with fraudulent charges.
- Clean the history. Rewrite Git history to remove the key, and ask the hosting service to clear cached views. This matters less than step 1, because the key is dead already.
- Review. Why did a long-lived key exist, and why was it on a laptop?
Prevent it:
| Control | What it does |
|---|---|
| No long-lived keys | Federation for pipelines, SSO for people, managed identities for apps |
| Push protection | GitHub secret scanning can block a push that contains a key |
| Pre-commit scanning | Tools such as gitleaks catch secrets on the developer's machine |
| Guardrails | Deny creating access keys for users, except approved cases |
| Spending alerts | A budget alert catches crypto mining within hours |
The lesson interviewers want to hear: the order. Revoke first, investigate second, clean history last. And the real fix is to stop having keys at all (questions 268 and 270).