-
Notifications
You must be signed in to change notification settings - Fork 9
add new user - more commits with modules #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6730401
initial commit, need check together with terraform-zero-modules/iam_u…
sshi100 c55e477
fix with review
sshi100 362b626
enhancement with map structure
sshi100 ffe2a67
enhancement with user group for AWS access
sshi100 aa95690
fix with template
sshi100 040b7c7
Merge remote-tracking branch 'origin/main' into 223-security-add-new-…
sshi100 19b6e6d
enhancements with shared state and k8s rules etc.
sshi100 210b0ca
refined modules-environemnt-root parameters etc. after review
sshi100 5c75996
Tweaked documentation a bit
bmonkman c3cbbd9
remove unnecessary templating and use variables
sshi100 e40810b
replace space with tab
sshi100 64df991
typo fix
sshi100 660a6fe
recover templating for terraform block
sshi100 ce1da1b
typo comment fix
sshi100 e06db8c
use remote modules and fixes
sshi100 0ca6c45
added tearndown steps for shared env
sshi100 75e2f49
refer to newer versions of modules
sshi100 f731f2b
add shared-remote-state generation
sshi100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # define AWS policy documents for developer | ||
| data "aws_iam_policy_document" "developer_access" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point we will want to revisit these policies, add stuff like enforcing MFA, etc. but this should be fine for now. |
||
| # EKS | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["eks:ListClusters"] | ||
| resources = ["*"] | ||
| } | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["eks:DescribeCluster"] | ||
| resources = ["arn:aws:eks:${local.region}:${local.account_id}:cluster/${local.project}-stage*"] | ||
| } | ||
|
|
||
| # ECR | ||
| statement { | ||
| effect = "Allow" | ||
| actions = [ | ||
| "ecr:DescribeImages", | ||
| "ecr:DescribeRepositories" | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
|
|
||
| # S3 | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["s3:ListBucket"] | ||
| resources = ["arn:aws:s3:::*${local.domain_name}"] | ||
| } | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["s3:GetObject"] | ||
| resources = ["arn:aws:s3:::*${local.domain_name}/*"] | ||
| } | ||
| } | ||
|
|
||
| # define AWS policy documents for operator | ||
| data "aws_iam_policy_document" "operator_access" { | ||
| # IAM | ||
| statement { | ||
| effect = "Allow" | ||
| actions = [ | ||
| "iam:ListRoles", | ||
| "sts:AssumeRole" | ||
| ] | ||
| resources = ["arn:aws:iam::${local.account_id}:role/${local.project}-kubernetes-operator-stage"] | ||
| } | ||
|
|
||
| # EKS | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["eks:*"] | ||
| resources = ["arn:aws:eks:${local.region}:${local.account_id}:cluster/${local.project}-stage*"] | ||
| } | ||
|
|
||
| # ECR | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["ecr:*"] | ||
| resources = ["*"] | ||
| } | ||
|
|
||
| # S3 | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["s3:*"] | ||
| resources = ["arn:aws:s3:::*${local.domain_name}"] | ||
| } | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["s3:*"] | ||
| resources = ["arn:aws:s3:::*${local.domain_name}/*"] | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| locals { | ||
| # define Kubernetes policy for developer | ||
| k8s_developer_access = [ | ||
| { | ||
| verbs = ["exec"] | ||
| api_groups = [""] | ||
| resources = ["pods", "pods/exec", "pods/log", "pods/portforward"] | ||
| }, { | ||
| verbs = ["get", "list", "watch"] | ||
| api_groups = [""] | ||
| resources = ["deployments", "configmaps", "pods", "services", "endpoints"] | ||
| } | ||
| ] | ||
|
|
||
| # define Kubernetes policy for operator | ||
| k8s_operator_access = [ | ||
| { | ||
| verbs = ["exec", "create", "list", "get", "delete", "patch", "update"] | ||
| api_groups = [""] | ||
| resources = ["deployments", "configmaps", "pods", "secrets", "services", "endpoints"] | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| terraform { | ||
| required_version = ">= 0.13" | ||
| backend "s3" { | ||
| bucket = "<% .Name %>-shared-terraform-state" | ||
| key = "infrastructure/terraform/environments/shared/main" | ||
| encrypt = true | ||
| region = "<% index .Params `region` %>" | ||
| dynamodb_table = "<% .Name %>-shared-terraform-state-locks" | ||
| } | ||
| } | ||
|
|
||
| locals { | ||
| project = "<% .Name %>" | ||
| region = "<% index .Params `region` %>" | ||
| account_id = "<% index .Params `accountId` %>" | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = local.region | ||
| allowed_account_ids = [local.account_id] | ||
| } | ||
|
|
||
| # Instantiate the environment | ||
| locals { | ||
| # Users configuration | ||
| users = [ | ||
| # { | ||
| # name = "dev1" | ||
| # roles = [ | ||
| # { name = "developer", environments = ["stage", "prod"] } | ||
| # ] | ||
| # }, { | ||
| # name = "devops1" | ||
| # roles = [ | ||
| # { name = "developer", environments = ["stage", "prod"] }, | ||
| # { name = "operator", environments = ["stage"] } | ||
| # ] | ||
| # }, { | ||
| # name = "operator1" | ||
| # roles = [ | ||
| # { name = "operator", environments = ["stage", "prod"] } | ||
| # ] | ||
| # }, | ||
| ] | ||
| } | ||
|
|
||
| ## Create users | ||
| resource "aws_iam_user" "access_user" { | ||
| count = length(local.users) | ||
| name = "${local.project}-${local.users[count.index].name}" | ||
|
|
||
| tags = { | ||
| for r in local.users[count.index].roles : "role:${r.name}" => join("/", r.environments) | ||
| } | ||
| } | ||
|
|
||
| output "iam_users" { | ||
| value = aws_iam_user.access_user | ||
| } | ||
|
|
||
| output "user_role_mapping" { | ||
| value = local.users | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.