|
| 1 | +# GitHub Deployer Role Module |
| 2 | + |
| 3 | +Creates an IAM role that GitHub Actions can assume through OIDC and attaches selected LambdaCron permission sets. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```hcl |
| 8 | +module "github_deployer_role" { |
| 9 | + source = "./modules/github-deployer-role" |
| 10 | +
|
| 11 | + role_name = "lambdacron-deployer" |
| 12 | + github_oidc_provider_arn = "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com" |
| 13 | +
|
| 14 | + github_subjects = [ |
| 15 | + "repo:my-org/cloud-cron-consumer:ref:refs/heads/main", |
| 16 | + "repo:my-org/cloud-cron-consumer:environment:prod", |
| 17 | + ] |
| 18 | +
|
| 19 | + github_job_workflow_refs = [ |
| 20 | + "my-org/cloud-cron-consumer/.github/workflows/deploy.yml@refs/heads/main", |
| 21 | + ] |
| 22 | +
|
| 23 | + permission_sets = [ |
| 24 | + "root", |
| 25 | + "print-notification", |
| 26 | + "email-notification", |
| 27 | + "lambda-image-build", |
| 28 | + ] |
| 29 | +
|
| 30 | + allowed_resource_name_prefixes = [ |
| 31 | + "lambdacron", |
| 32 | + ] |
| 33 | +
|
| 34 | + tags = { |
| 35 | + environment = "prod" |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Permission Sets |
| 41 | + |
| 42 | +- `scheduled-lambda`: Lambda + IAM execution-role/policy wiring + EventBridge schedule management + ECR image lookup/repository policy permissions required for image-based function create/update. |
| 43 | +- `notification-plumbing`: SNS subscription + SQS queue + Lambda event source mapping. |
| 44 | +- `print-notification`: Reuses `notification-plumbing` and adds notification Lambda/IAM deployment permissions. |
| 45 | +- `email-notification`: Reuses `notification-plumbing` and adds notification Lambda/IAM deployment permissions. |
| 46 | +- `sms-notification`: Reuses `notification-plumbing` and adds notification Lambda/IAM deployment permissions. |
| 47 | +- `lambda-image-build`: Private ECR repository management, private repository policy management, and image push permissions. |
| 48 | +- `lambda-image-republish`: Reuses `lambda-image-build` and adds public ECR auth + read permissions. |
| 49 | +- `lambda-image-public`: Public ECR repository management + image push permissions. |
| 50 | +- `root`: Reuses `scheduled-lambda` and adds shared SNS topic management. |
| 51 | + |
| 52 | +## Inputs |
| 53 | + |
| 54 | +- `role_name` (string): IAM role name. |
| 55 | +- `role_description` (string): IAM role description. |
| 56 | +- `max_session_duration` (number): Max assume-role session duration (seconds). |
| 57 | +- `github_oidc_provider_arn` (string): GitHub OIDC provider ARN. |
| 58 | +- `github_audience` (string): OIDC token audience, default `sts.amazonaws.com`. |
| 59 | +- `github_subjects` (list(string)): Allowed OIDC subject patterns. |
| 60 | +- `github_job_workflow_refs` (list(string)): Optional allowed OIDC `job_workflow_ref` patterns for workflow-level restriction. |
| 61 | +- `permission_sets` (set(string)): Permission sets to attach. |
| 62 | +- `additional_policy_arns` (list(string)): Extra managed policies to attach. |
| 63 | +- `allowed_resource_name_prefixes` (set(string)): Allowed name prefixes for deployer-managed resources; defaults to `["lambdacron"]`. |
| 64 | +- `tags` (map(string)): Resource tags. |
| 65 | + |
| 66 | +## Scoping Behavior |
| 67 | + |
| 68 | +- Permission-set policies are scoped to the current AWS account and to resources whose names start with values in `allowed_resource_name_prefixes`. |
| 69 | +- `iam:PassRole` is restricted to scoped IAM role ARNs and requires `iam:PassedToService = lambda.amazonaws.com`. |
| 70 | +- A small set of actions remains wildcard-scoped where AWS APIs do not support resource-level scoping (for example some create/authentication APIs such as `sns:CreateTopic`, `sqs:CreateQueue`, `ecr:GetAuthorizationToken`, and event source mapping APIs). |
| 71 | + |
| 72 | +## Outputs |
| 73 | + |
| 74 | +- `role_arn`: IAM role ARN. |
| 75 | +- `role_name`: IAM role name. |
| 76 | +- `permission_set_policy_arns`: Map of selected permission-set names to created policy ARNs. |
| 77 | +- `selected_permission_sets`: Sorted selected permission-set names. |
| 78 | +- `available_permission_sets`: Map of all available permission-set names and descriptions. |
| 79 | +- `assume_role_policy_json`: Rendered trust policy JSON. |
0 commit comments