{"id":"6b09a4b2ff996234422a2674","slug":"aws-iam-least-privilege","title":"IAM i zasada najmniejszych uprawnień na AWS – role, polityki, warunki, SCP/RCP, Access Analyzer i OIDC dla GitHub Actions","summary":"Porządkujemy uprawnienia w koncie AWS pierogarni – od „wszyscy mają AdministratorAccess” do najmniejszych uprawnień. Tożsamości i role zamiast użytkowników, logika oceny polityk, role zadań ECS i Lambdy w CDK, klucze warunków, granice uprawnień i ABAC, barierki organizacji (SCP i RCP), IAM Access Analyzer jako bramka w CI oraz wdrożenia z GitHub Actions przez OIDC – bez długoterminowych kluczy.","servedLang":"pl","availableLangs":["pl","en"],"topics":["aws-iam","secrets-management","aws-s3"],"techs":["typescript","node"],"tags":["aws","iam","least-privilege","scp","rcp","permissions-boundary","abac","access-analyzer","oidc","github-actions","ecs","lambda","aws-cdk"],"level":"intermediate","kind":"tutorial","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":16,"stats":{"views":0,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T15:41:38.622Z","updatedAt":"2026-11-27T15:41:38.674Z","requestedLang":"pl","theme":{"hero":"classic","heroMedia":null,"accent":"amber","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"AWS IAM least privilege w praktyce – role vs użytkownicy IAM, polityki tożsamości i zasobów, SCP, RCP, permissions boundary, kolejność oceny polityk, klucze warunków (aws:PrincipalOrgID, aws:SourceArn, kms:ViaService), role zadań ECS (task role vs execution role), Lambda, OIDC GitHub Actions, IAM Ac","wordCount":3014,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"W koncie AWS pierogarni trzech programistów, pipeline CI i dwie usługi miały jedno wspólne: politykę "},{"type":"text","text":"AdministratorAccess","marks":[{"type":"code"}]},{"type":"text","text":", nadaną „na chwilę, żeby ruszyło”. Ta chwila trwała półtora roku. W tym poradniku zamieniamy ten stan na zasadę najmniejszych uprawnień ("},{"type":"text","text":"least privilege","marks":[{"type":"italic"}]},{"type":"text","text":"): każda tożsamość dostaje dokładnie to, czego potrzebuje, na tak krótko, jak się da – i tak, żeby błąd albo wyciek miał ograniczony zasięg."}]},{"type":"callout","attrs":{"variant":"info","title":"W skrócie"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Role zamiast kluczy.","marks":[{"type":"bold"}]},{"type":"text","text":" Ludzie logują się przez IAM Identity Center, usługi dostają role (ECS, Lambda), a CI – krótkie sesje przez OIDC. Długoterminowy klucz "},{"type":"text","text":"AKIA…","marks":[{"type":"code"}]},{"type":"text","text":" to wyjątek, nie standard."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Jawna odmowa zawsze wygrywa.","marks":[{"type":"bold"}]},{"type":"text","text":" Uprawnienia to przecięcie kilku warstw: polityk tożsamości, polityk zasobów, granic uprawnień, SCP i RCP. Barierki ("},{"type":"text","text":"Deny","marks":[{"type":"code"}]},{"type":"text","text":") na górze chronią przed pomyłkami na dole."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Najmniejsze uprawnienia to proces, nie stan.","marks":[{"type":"bold"}]},{"type":"text","text":" Access Analyzer generuje polityki z aktywności, pokazuje nieużywane uprawnienia i blokuje w CI zmiany, które nadają nowy dostęp."}]}]}]}]},{"type":"callout","attrs":{"variant":"tip","title":"Co zbudujesz"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Politykę roli API (S3 na prefiksie, KMS tylko przez S3, SQS, Parameter Store) z polityką zaufania odporną na "},{"type":"text","text":"confused deputy","marks":[{"type":"italic"}]},{"type":"text","text":", konstrukcje CDK z rolą zadania i rolą wykonania ECS, rolą Lambdy i granicą uprawnień, rolę wdrożeniową dla GitHub Actions z OIDC i workflow bez sekretów AWS, politykę delegowania tworzenia ról, przykład ABAC, SCP i RCP dla organizacji oraz skrypt IAM Access Analyzer do CI. Kod (11 plików) pobierzesz jako ZIP."}]}]},{"type":"paragraph","content":[{"type":"text","text":"Wymagania wstępne:","marks":[{"type":"bold"}]},{"type":"text","text":" konto AWS (najlepiej w AWS Organizations), AWS CLI v2, Node.js 22+ i AWS CDK v2, podstawy JSON. Przydadzą się poradniki o "},{"type":"text","text":"skalowalnym portalu","marks":[{"type":"link","attrs":{"href":"/pl/articles/aws-scalable-web-architecture"}}]},{"type":"text","text":" i "},{"type":"text","text":"bezpieczeństwie bucketów S3","marks":[{"type":"link","attrs":{"href":"/pl/articles/aws-s3-bucket-security"}}]},{"type":"text","text":"."}]},{"type":"stats","attrs":{"items":[{"value":"Deny","label":"wygrywa zawsze","hint":"jawna odmowa w dowolnej polityce"},{"value":"0","label":"długoterminowych kluczy","hint":"w docelowym układzie: SSO, role, OIDC"},{"value":"1 h","label":"sesja wdrożenia z GitHub Actions","hint":"potem poświadczenia wygasają"},{"value":"90 dni","label":"domyślne okno analizy nieużywanego dostępu","hint":"Access Analyzer, konfigurowalne"}]}},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart LR\n  subgraph Ludzie\n    D([Programista]) -->|SSO + MFA| IC[IAM Identity Center]\n  end\n  IC -->|zestaw uprawnień| RD[Rola Developer<br/>w koncie dev]\n  IC -->|zestaw uprawnień| RR[Rola ReadOnly<br/>w koncie prod]\n  GH([GitHub Actions]) -->|token OIDC| RG[Rola github-deploy]\n  ECS([Zadanie ECS]) -->|rola zadania| RT[Rola pierogi-api-task]\n  L([Lambda]) -->|rola wykonania| RL[Rola thumbnailer]\n  RD & RR & RG & RT & RL --> STS[(STS: poświadczenia<br/>tymczasowe)]","caption":"Kto i jak dostaje poświadczenia – docelowy układ"}},{"type":"heading","attrs":{"level":2,"id":"tozsamosci-kto-jest-kim"},"content":[{"type":"text","text":"Tożsamości: kto jest kim"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Tożsamość"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Do czego"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Poświadczenia"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Zasada"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Konto root"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"zamknięcie konta, kilka operacji rozliczeniowych"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"hasło + MFA"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"bez kluczy dostępu; w organizacji – scentralizowane zarządzanie dostępem root (od 2024)"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Użytkownik Identity Center"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"ludzie"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"SSO, krótkie sesje, MFA"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"domyślny sposób logowania ludzi"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Użytkownik IAM"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"wyjątki: stare narzędzia bez obsługi ról"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"długoterminowy klucz"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"unikaj; jeśli musisz – jeden cel, rotacja, warunki IP/VPC"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Rola IAM"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"usługi, CI, dostęp między kontami, federacja"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"tymczasowe (STS)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"podstawowy budulec"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Rola powiązana z usługą"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"usługi AWS działające w twoim koncie"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"zarządzane przez AWS"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"nie edytujesz, ale warto wiedzieć, że istnieją"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Rola nie ma hasła ani klucza – ma "},{"type":"text","text":"politykę zaufania","marks":[{"type":"bold"}]},{"type":"text","text":" (kto może ją przyjąć) i "},{"type":"text","text":"polityki uprawnień","marks":[{"type":"bold"}]},{"type":"text","text":" (co wolno po jej przyjęciu). Poświadczenia z "},{"type":"text","text":"sts:AssumeRole","marks":[{"type":"code"}]},{"type":"text","text":" wygasają same, więc wyciek z logów czy zrzutu pamięci ma ograniczony czas życia."}]},{"type":"heading","attrs":{"level":2,"id":"jak-aws-podejmuje-decyzje"},"content":[{"type":"text","text":"Jak AWS podejmuje decyzję"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart TD\n  A([Żądanie]) --> B{Jawny Deny<br/>w jakiejkolwiek polityce?}\n  B -->|tak| X[Odmowa]\n  B -->|nie| C{SCP i RCP<br/>pozwalają?}\n  C -->|nie| X\n  C -->|tak| D{Polityka zasobu<br/>daje Allow?}\n  D -->|tak*| OK[Zgoda]\n  D -->|nie| E{Granica uprawnień<br/>i polityka sesji pozwalają?}\n  E -->|nie| X\n  E -->|tak| F{Polityka tożsamości<br/>daje Allow?}\n  F -->|tak| OK\n  F -->|nie| X","caption":"Uproszczona logika oceny żądania w jednym koncie"}},{"type":"paragraph","content":[{"type":"text","text":"Domyślnie wszystko jest zabronione ("},{"type":"text","text":"implicit deny","marks":[{"type":"italic"}]},{"type":"text","text":"). Zgoda wymaga "},{"type":"text","text":"Allow","marks":[{"type":"code"}]},{"type":"text","text":", a jedna jawna odmowa przekreśla wszystkie "},{"type":"text","text":"Allow","marks":[{"type":"code"}]},{"type":"text","text":". Gwiazdka przy polityce zasobu: w tym samym koncie "},{"type":"text","text":"Allow","marks":[{"type":"code"}]},{"type":"text","text":" w polityce zasobu bywa wystarczające nawet bez polityki tożsamości (szczegóły zależą od typu podmiotu), a dostęp między kontami wymaga "},{"type":"text","text":"Allow","marks":[{"type":"code"}]},{"type":"text","text":" po obu stronach."}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Typ polityki"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Daje uprawnienia?"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Przykład"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Polityka tożsamości (zarządzana lub inline)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"tak"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"co może rola API"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Polityka zasobu"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"tak"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"polityka bucketu, kolejki, klucza KMS, sekretu"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Granica uprawnień ("},{"type":"text","text":"permissions boundary","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"nie – tylko ogranicza"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"sufit dla ról tworzonych przez zespoły"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Polityka sesji"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"nie – tylko ogranicza"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"zawężenie przy "},{"type":"text","text":"AssumeRole","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"SCP (AWS Organizations)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"nie – ogranicza tożsamości w kontach"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"„nikt nie wyłączy CloudTrail”"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"RCP (AWS Organizations, od 2024)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"nie – ogranicza dostęp do zasobów"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"„do naszych bucketów tylko z naszej organizacji”"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"krok-1-polityka-roli-aplikacji"},"content":[{"type":"text","text":"Krok 1. Polityka roli aplikacji"}]},{"type":"codeGroup","attrs":{"title":"Polityka uprawnień i polityka zaufania roli zadania ECS"},"content":[{"type":"codeBlock","attrs":{"language":"json","filename":"policies/api-task-policy.json"},"content":[{"type":"text","text":"{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"InvoicesReadWrite\",\n      \"Effect\": \"Allow\",\n      \"Action\": [\"s3:GetObject\", \"s3:PutObject\"],\n      \"Resource\": \"arn:aws:s3:::pierogi-invoices-123456789012/invoices/*\"\n    },\n    {\n      \"Sid\": \"InvoicesKeyViaS3Only\",\n      \"Effect\": \"Allow\",\n      \"Action\": [\"kms:Decrypt\", \"kms:GenerateDataKey\"],\n      \"Resource\": \"arn:aws:kms:eu-central-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab\",\n      \"Condition\": { \"StringEquals\": { \"kms:ViaService\": \"s3.eu-central-1.amazonaws.com\" } }\n    },\n    {\n      \"Sid\": \"EnqueueJobs\",\n      \"Effect\": \"Allow\",\n      \"Action\": \"sqs:SendMessage\",\n      \"Resource\": \"arn:aws:sqs:eu-central-1:123456789012:pierogi-jobs\"\n    },\n    {\n      \"Sid\": \"ReadOwnParameters\",\n      \"Effect\": \"Allow\",\n      \"Action\": \"ssm:GetParameter\",\n      \"Resource\": \"arn:aws:ssm:eu-central-1:123456789012:parameter/pierogi/prod/api/*\"\n    }\n  ]\n}"}]},{"type":"codeBlock","attrs":{"language":"json","filename":"policies/ecs-task-trust-policy.json"},"content":[{"type":"text","text":"{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Principal\": { \"Service\": \"ecs-tasks.amazonaws.com\" },\n      \"Action\": \"sts:AssumeRole\",\n      \"Condition\": {\n        \"ArnLike\": { \"aws:SourceArn\": \"arn:aws:ecs:eu-central-1:123456789012:*\" },\n        \"StringEquals\": { \"aws:SourceAccount\": \"123456789012\" }\n      }\n    }\n  ]\n}"}]}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Konkretne akcje i zasoby.","marks":[{"type":"bold"}]},{"type":"text","text":" "},{"type":"text","text":"s3:GetObject","marks":[{"type":"code"}]},{"type":"text","text":" i "},{"type":"text","text":"s3:PutObject","marks":[{"type":"code"}]},{"type":"text","text":" tylko na "},{"type":"text","text":"invoices/*","marks":[{"type":"code"}]},{"type":"text","text":" – bez "},{"type":"text","text":"s3:*","marks":[{"type":"code"}]},{"type":"text","text":", bez "},{"type":"text","text":"DeleteObject","marks":[{"type":"code"}]},{"type":"text","text":", bez listowania całego bucketu."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"kms:ViaService","marks":[{"type":"code"}]},{"type":"text","text":" – rola może użyć klucza wyłącznie przez S3. Nawet z przejętymi poświadczeniami nikt nie odszyfruje nim niczego bezpośrednio przez API KMS."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Parameter Store po ścieżce","marks":[{"type":"bold"}]},{"type":"text","text":" – "},{"type":"text","text":"/pierogi/prod/api/*","marks":[{"type":"code"}]},{"type":"text","text":", a nie wszystkie parametry konta."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Polityka zaufania z ","marks":[{"type":"bold"}]},{"type":"text","text":"aws:SourceAccount","marks":[{"type":"code"}]},{"type":"text","text":" i ","marks":[{"type":"bold"}]},{"type":"text","text":"aws:SourceArn","marks":[{"type":"code"}]},{"type":"text","text":" – chroni przed "},{"type":"text","text":"confused deputy","marks":[{"type":"italic"}]},{"type":"text","text":": usługa ECS przyjmie tę rolę tylko w imieniu zadań z naszego konta i regionu."}]}]}]},{"type":"callout","attrs":{"variant":"warning","title":"Rola zadania to nie rola wykonania"},"content":[{"type":"paragraph","content":[{"type":"text","text":"ECS używa dwóch ról. "},{"type":"text","text":"Rola wykonania","marks":[{"type":"bold"}]},{"type":"text","text":" ("},{"type":"text","text":"execution role","marks":[{"type":"italic"}]},{"type":"text","text":") należy do agenta ECS: pobiera obraz z ECR, pisze logi, odczytuje sekrety wstrzykiwane jako zmienne środowiskowe. "},{"type":"text","text":"Rola zadania","marks":[{"type":"bold"}]},{"type":"text","text":" ("},{"type":"text","text":"task role","marks":[{"type":"italic"}]},{"type":"text","text":") to poświadczenia, które dostaje twój kod przez SDK. Pomylenie ich – albo jedna rola do obu celów – oznacza, że kod aplikacji ma uprawnienia do wszystkich sekretów i repozytoriów obrazów."}]}]},{"type":"heading","attrs":{"level":2,"id":"krok-2-role-w-cdk-wygodne-grant-i-ich-cena"},"content":[{"type":"text","text":"Krok 2. Role w CDK: wygodne "},{"type":"text","text":"grant*","marks":[{"type":"code"}]},{"type":"text","text":" i ich cena"}]},{"type":"codeGroup","attrs":{"title":"Role ECS i Lambdy z granicą uprawnień (AWS CDK)"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/app-roles.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport * as iam from 'aws-cdk-lib/aws-iam';\nimport * as ecs from 'aws-cdk-lib/aws-ecs';\nimport * as lambda from 'aws-cdk-lib/aws-lambda';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\nimport * as sqs from 'aws-cdk-lib/aws-sqs';\nimport * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';\n\nexport interface AppRolesProps {\n  invoices: s3.IBucket;\n  jobs: sqs.IQueue;\n  dbSecret: secretsmanager.ISecret;\n  boundary: iam.IManagedPolicy;\n}\n\nexport class AppRoles extends Construct {\n  constructor(scope: Construct, id: string, props: AppRolesProps) {\n    super(scope, id);\n    // Every role created inside this construct gets the permissions boundary.\n    iam.PermissionsBoundary.of(this).apply(props.boundary);\n\n    const task = new ecs.FargateTaskDefinition(this, 'ApiTask', { cpu: 512, memoryLimitMiB: 1024 });\n    task.addContainer('api', {\n      image: ecs.ContainerImage.fromRegistry('public.ecr.aws/docker/library/node:24-alpine'),\n      logging: ecs.LogDrivers.awsLogs({ streamPrefix: 'api' }),\n      // Injected at start by the ECS agent → GetSecretValue lands on the EXECUTION role.\n      secrets: { DB_PASSWORD: ecs.Secret.fromSecretsManager(props.dbSecret, 'password') },\n    });\n\n    // The TASK role is what your code gets from the SDK.\n    // grantReadWrite() would also add s3:DeleteObject*, s3:PutObjectRetention, s3:List*…\n    // For sensitive data, write the two actions you actually need.\n    task.taskRole.addToPrincipalPolicy(new iam.PolicyStatement({\n      actions: ['s3:GetObject', 's3:PutObject'],\n      resources: [props.invoices.arnForObjects('invoices/*')],\n    }));\n    props.invoices.encryptionKey?.grant(task.taskRole, 'kms:Decrypt', 'kms:GenerateDataKey');\n    props.jobs.grantSendMessages(task.taskRole); // SendMessage + GetQueueAttributes + GetQueueUrl\n\n    // A Lambda gets its own role – never share one \"app role\" across services.\n    const thumbnailer = new lambda.Function(this, 'Thumbnailer', {\n      runtime: lambda.Runtime.NODEJS_24_X,\n      handler: 'index.handler',\n      code: lambda.Code.fromInline('exports.handler = async () => ({ ok: true });'),\n    });\n    props.invoices.grantRead(thumbnailer, 'uploads/*');\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"infra/lib/boundary.ts"},"content":[{"type":"text","text":"import { Construct } from 'constructs';\nimport { Stack } from 'aws-cdk-lib';\nimport * as iam from 'aws-cdk-lib/aws-iam';\n\n/** The ceiling for every role a product team creates: workload services only, one region, no IAM. */\nexport function devBoundary(scope: Construct): iam.ManagedPolicy {\n  const region = Stack.of(scope).region;\n  return new iam.ManagedPolicy(scope, 'DevBoundary', {\n    managedPolicyName: 'pierogi-dev-boundary',\n    statements: [\n      new iam.PolicyStatement({\n        sid: 'WorkloadServicesInOurRegion',\n        actions: [\n          's3:*', 'sqs:*', 'dynamodb:*', 'logs:*', 'xray:*', 'cloudwatch:PutMetricData',\n          'secretsmanager:GetSecretValue', 'kms:Decrypt', 'kms:GenerateDataKey',\n          'ecr:GetAuthorizationToken', 'ecr:BatchGetImage', 'ecr:GetDownloadUrlForLayer',\n        ],\n        resources: ['*'],\n        conditions: { StringEquals: { 'aws:RequestedRegion': region } },\n      }),\n    ],\n  });\n}"}]}]}]},"toc":[{"id":"tozsamosci-kto-jest-kim","text":"Tożsamości: kto jest kim","level":2,"locked":false},{"id":"jak-aws-podejmuje-decyzje","text":"Jak AWS podejmuje decyzję","level":2,"locked":false},{"id":"krok-1-polityka-roli-aplikacji","text":"Krok 1. Polityka roli aplikacji","level":2,"locked":false},{"id":"krok-2-role-w-cdk-wygodne-grant-i-ich-cena","text":"Krok 2. Role w CDK: wygodne grant* i ich cena","level":2,"locked":false},{"id":"warunki-najwazniejsze-klucze","text":"Warunki: najważniejsze klucze","level":2,"locked":true},{"id":"krok-3-github-actions-bez-kluczy-oidc","text":"Krok 3. GitHub Actions bez kluczy: OIDC","level":2,"locked":true},{"id":"krok-4-delegowanie-z-granicami-uprawnien-i-abac","text":"Krok 4. Delegowanie z granicami uprawnień i ABAC","level":2,"locked":true},{"id":"krok-5-barierki-organizacji-scp-i-rcp","text":"Krok 5. Barierki organizacji: SCP i RCP","level":2,"locked":true},{"id":"krok-6-access-analyzer-jako-bramka-w-ci","text":"Krok 6. Access Analyzer jako bramka w CI","level":2,"locked":true},{"id":"higiena-poswiadczen","text":"Higiena poświadczeń","level":2,"locked":true},{"id":"typowe-bledy","text":"Typowe błędy","level":2,"locked":true},{"id":"sprawdz-sie","text":"Sprawdź się","level":2,"locked":true},{"id":"co-dalej","text":"Co dalej","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":59,"visibleBlocks":19,"resources":[{"id":"6b0857bf3c96f2d34d0b42a9","type":"article","provider":"web","url":"https://learn.microsoft.com/en-us/azure/architecture/patterns/federated-identity","embedUrl":null,"title":"Federated Identity Pattern","description":"Use the Federated Identity design pattern to delegate authentication to an external identity provider.","author":"Microsoft Azure Architecture Center","thumbnailUrl":"https://learn.microsoft.com/en-us/media/open-graph-image.png","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["azure","cloud","design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":62,"verifiedAt":"2026-11-26T11:07:49.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857ba3c96f2d34d0b3ea7","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/all-about-cedar-an-open-source-solution-for-fine/id915443155?i=1000739301604","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id915443155?i=1000739301604","title":"All About Cedar, an Open Source Solution for Fine-Tuning Kubernetes Authorization","description":"Kubernetes has relied on role-based access control (RBAC) since 2017, but its simplicity limits what developers can express, said Micah Hausler, principal engineer at AWS, on The New Stack Makers. RBAC only allows actions; it can’t enforce conditions, denials, or attribute-based rules. Seeking a…","author":"The New Stack Podcast","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts112/v4/7e/e5/43/7ee54305-38f2-4a29-5014-45d8ac4831e3/mza_10106980059768264551.jpg/600x600bb.jpg","durationSec":973,"lang":"en","topics":["fine-tuning"],"techs":["general"],"tags":["podcast","cloud","kubernetes","ai"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2025-12-02T15:30:00.000Z","popularity":52,"verifiedAt":"2026-11-26T11:07:16.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:57.868Z","updatedAt":"2026-11-26T16:00:57.868Z"},{"id":"6b0857b53c96f2d34d0b3903","type":"article","provider":"web","url":"https://www.alexanderlolis.com/authorization-in-a-microservices-world","embedUrl":null,"title":"Authorization in a Microservices World","description":"Authorization? How hard can it be? I am pretty sure that others have already solved it. We are not the first ones doing microservices. It should be easy to integrate what's already out there.","author":"alexanderlolis.com","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["microservices"],"techs":["general"],"tags":["software-architecture","hacker-news"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"hn","publishedAt":"2022-04-01T15:11:45.000Z","popularity":69,"verifiedAt":"2026-11-26T11:07:59.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:52.228Z","updatedAt":"2026-11-26T16:00:52.228Z"},{"id":"6b0857bc3c96f2d34d0b4057","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/microservices-security-in-action-with-prabath/id1478997569?i=1000673444208","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id1478997569?i=1000673444208","title":"Microservices Security in Action with Prabath Siriwardena - .NET 201","description":"Microservice architecture is very popular today. The panel talks with microservice security authors about their book and all aspects of securing microservices. Links Microservices Security in Action: Design secure network and API endpoint security for Microservices applications, with examples…","author":"Adventures in .NET","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts211/v4/6a/4e/3b/6a4e3bdb-bbf1-8601-a403-086ce24cb18f/mza_1088513295079016608.jpg/600x600bb.jpg","durationSec":3194,"lang":"en","topics":["microservices"],"techs":["dotnet","java"],"tags":["podcast","kubernetes","security","software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2024-10-15T10:00:00.000Z","popularity":44,"verifiedAt":"2026-11-26T11:07:22.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857bf3c96f2d34d0b42b8","type":"article","provider":"web","url":"https://docs.aws.amazon.com/wellarchitected/latest/framework/welcome.html","embedUrl":null,"title":"AWS Well-Architected Framework - AWS Well-Architected Framework","description":"The AWS Well-Architected Framework helps you understand the pros and cons of decisions you make while building systems on AWS. Using the Framework helps you learn architectural best practices for designing and operating secure, reliable, efficient, cost-effective, and sustainable workloads in the…","author":"AWS Well-Architected Framework","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["cloud"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":60,"verifiedAt":"2026-11-26T11:26:15.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"}],"challenges":[],"attachments":[],"hasCode":true,"repoUrl":null,"series":[],"prev":null,"next":null,"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":104,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Autorytet","articles":90},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Autorytet","articles":61},{"key":"python","title":"Python","level":5,"levelLabel":"Autorytet","articles":59},{"key":"java","title":"Java","level":5,"levelLabel":"Autorytet","articles":46}]}}