-
Notifications
You must be signed in to change notification settings - Fork 2
[#327] Use AWS Session Manager to Securely connect to an EC2 instance #330
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
Open
tung-nimblehq
wants to merge
4
commits into
develop
Choose a base branch
from
feature/327-add-ssm-login-instead-of-key-pair
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d9f8892
[#327] Update bastion module to use ssm for login, add iam role modul…
tung-nimblehq 91d120f
[#327] Fix typo and add modules/iam_role/variables.tf into test
tung-nimblehq d2b9d31
[#327] Add missing await and upgrade trivy version
tung-nimblehq 90b3e99
[#327] Remove key name
tung-nimblehq 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| nodejs 18.12.1 | ||
| terraform 1.13.3 | ||
| trivy 0.47.0 | ||
| trivy 0.69.2 |
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
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,45 @@ | ||
| import { AwsOptions } from '@/generators/addons/aws'; | ||
| import { applyTerraformCore } from '@/generators/terraform'; | ||
| import { remove } from '@/helpers/file'; | ||
|
|
||
| import applyAwsIamRole from './iamRole'; | ||
| import applyTerraformAwsProvider from './provider'; | ||
|
|
||
| describe('IAM Role add-on', () => { | ||
| describe('given valid AWS options', () => { | ||
| const projectDir = 'iam-addon-test'; | ||
|
|
||
| beforeAll(async () => { | ||
| const awsOptions: AwsOptions = { | ||
| projectName: projectDir, | ||
| provider: 'aws', | ||
| infrastructureType: 'advanced', | ||
| }; | ||
|
|
||
| await applyTerraformCore(awsOptions); | ||
| await applyTerraformAwsProvider(awsOptions); | ||
| await applyAwsIamRole(awsOptions); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| jest.clearAllMocks(); | ||
| remove('/', projectDir); | ||
| }); | ||
|
|
||
| it('creates expected files', () => { | ||
| const expectedFiles = [ | ||
| 'shared/main.tf', | ||
| 'shared/providers.tf', | ||
| 'shared/outputs.tf', | ||
| 'shared/variables.tf', | ||
|
|
||
| 'modules/iam_role/data.tf', | ||
| 'modules/iam_role/variables.tf', | ||
| 'modules/iam_role/main.tf', | ||
| 'modules/iam_role/outputs.tf', | ||
| ]; | ||
|
|
||
| expect(projectDir).toHaveFiles(expectedFiles); | ||
| }); | ||
| }); | ||
| }); | ||
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,18 @@ | ||
| import { AwsOptions } from '@/generators/addons/aws'; | ||
| import { AWS_TEMPLATE_PATH } from '@/generators/addons/aws/constants'; | ||
| import { isAwsModuleAdded } from '@/generators/addons/aws/dependencies'; | ||
| import { copy } from '@/helpers/file'; | ||
|
|
||
| const applyAwsIamRole = async (options: AwsOptions) => { | ||
| if (isAwsModuleAdded('iamRole', options.projectName)) { | ||
| return; | ||
| } | ||
|
|
||
| copy( | ||
| `${AWS_TEMPLATE_PATH}/modules/iam_role`, | ||
| 'modules/iam_role', | ||
| options.projectName | ||
| ); | ||
| }; | ||
|
|
||
| export default applyAwsIamRole; |
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,19 @@ | ||
| data "aws_ami" "amazon_linux_2023" { | ||
| most_recent = true | ||
| owners = ["amazon"] | ||
|
|
||
| filter { | ||
| name = "name" | ||
| values = ["al2023-ami-2023.*-x86_64"] | ||
| } | ||
|
|
||
| filter { | ||
| name = "architecture" | ||
| values = ["x86_64"] | ||
| } | ||
|
|
||
| filter { | ||
| name = "virtualization-type" | ||
| values = ["hvm"] | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,10 +1,14 @@ | ||
| # trivy:ignore:AVD-AWS-0009 | ||
| resource "aws_launch_template" "bastion_instance" { | ||
| name_prefix = "${local.name_prefix}-" | ||
| image_id = var.image_id | ||
| image_id = data.aws_ami.amazon_linux_2023.id | ||
| instance_type = var.instance_type | ||
| key_name = var.key_name | ||
|
||
|
|
||
| iam_instance_profile { | ||
| name = var.iam_instance_profile | ||
| } | ||
|
|
||
| metadata_options { | ||
| http_tokens = local.metadata_options.http_tokens | ||
| } | ||
|
|
||
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,12 @@ | ||
| data "aws_iam_policy_document" "assume_role" { | ||
| statement { | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = var.assume_role_services | ||
| } | ||
|
|
||
| actions = ["sts:AssumeRole"] | ||
| } | ||
| } |
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,26 @@ | ||
| resource "aws_iam_role" "role" { | ||
| name = var.role_name | ||
| assume_role_policy = data.aws_iam_policy_document.assume_role.json | ||
|
|
||
| tags = { | ||
| Name = var.role_name | ||
| } | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "this" { | ||
| for_each = toset(var.policy_arns) | ||
|
|
||
| role = aws_iam_role.role.name | ||
| policy_arn = each.value | ||
| } | ||
|
|
||
| resource "aws_iam_instance_profile" "instance_profile" { | ||
| count = var.create_instance_profile ? 1 : 0 | ||
|
|
||
| name = var.role_name | ||
| role = aws_iam_role.role.name | ||
|
|
||
| tags = { | ||
| Name = var.role_name | ||
| } | ||
| } |
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,9 @@ | ||
| output "role_arn" { | ||
| description = "The ARN of the IAM role" | ||
| value = aws_iam_role.role.arn | ||
| } | ||
|
|
||
| output "instance_profile_name" { | ||
| description = "The name of the IAM instance profile" | ||
| value = var.create_instance_profile ? aws_iam_instance_profile.instance_profile[0].name : null | ||
| } |
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,22 @@ | ||
| variable "role_name" { | ||
| description = "The name of the IAM role" | ||
| type = string | ||
| } | ||
|
|
||
| variable "assume_role_services" { | ||
| description = "List of AWS services that can assume this role" | ||
| type = list(string) | ||
| default = ["ec2.amazonaws.com"] | ||
| } | ||
|
|
||
| variable "policy_arns" { | ||
| description = "List of IAM policy ARNs to attach to the role" | ||
| type = list(string) | ||
| default = [] | ||
| } | ||
|
|
||
| variable "create_instance_profile" { | ||
| description = "Whether to create an IAM instance profile" | ||
| type = bool | ||
| default = false | ||
| } |
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.