Skip to content
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

Add KMS key creation and conditional policy for SNS + Other Services #49

Closed
wants to merge 14 commits into from

Conversation

kristianiliev1
Copy link
Contributor

Description

Added KMS Key creation. Added policy for it. Added a variable - if set, will create CMK key, if not - will use AWS default keys.

Related Issues

https://ontotext.atlassian.net/browse/GDB-9961

Changes

Screenshots (if applicable)

Checklist

  • I have tested these changes thoroughly.
  • My code follows the project's coding style.
  • I have added appropriate comments to my code, especially in complex areas.
  • All new and existing tests passed locally.

@kristianiliev1 kristianiliev1 requested review from viktor-ribchev and a user May 29, 2024 15:02
@ghost
Copy link

ghost commented May 30, 2024

  1. Use [ GDB-9961 ] without interval to link the MR to the ticket, there is no need to paste the whole link.
  2. Create one MR with multiple commits for the different services. ( I see that your MR Is named add kms key creation and conditional policy for SNS, so I assume that you will create different merge requests per "service"). That is not mandatory, instead you can create one MR and push multiple commits named for example: Added CMK support for SNS, Added CMK support for S3, Added CMK support for LB and etc.)

@ghost ghost self-requested a review May 30, 2024 05:38
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
modules/monitoring/sns.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
@kristianiliev1 kristianiliev1 changed the title Add KMS key creation and conditional policy for SNS Add KMS key creation and conditional policy for SNS + Other Services May 30, 2024
@kristianiliev1 kristianiliev1 requested review from mihailradkov and removed request for viktor-ribchev May 30, 2024 12:40
modules/monitoring/cmk.tf Outdated Show resolved Hide resolved
default = "KMS Key to encrypt SNS"
}

variable "key_spec" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add missing types

variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated
# KMS CMK

variable "enable_cmk" {
description = "Enable CMK for encryption. If false, use AWS managed key."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expand the CMK abbreviation in the description.

variables.tf Outdated
# KMS CMK

variable "enable_cmk" {
description = "Enable CMK for encryption. If false, use AWS managed key."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key or keys?

variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated
default = false
}

variable "kms_master_key_id" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this used anywhere in the monitoring module, do we support passing existing keys or not?

variables.tf Outdated
default = ""
}

variable "sns_cmk_policy" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another variable that I think is not even used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I've been testing something. Thanks for noticing...

variables.tf Outdated Show resolved Hide resolved
"Effect" : "Allow",
"Principal" : {
# Use 'var.sns_key_admin_arn' if available and root if not provided
"AWS" : var.sns_key_admin_arn != "" ? var.sns_key_admin_arn : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simeonzhekofff, is root okey here? I'm not familiar with the requirements.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter defines who is the principal of the key, It shouldn't be root. It's better to be a group for example KeyAdmins or something like that.

@kristianiliev1 kristianiliev1 requested a review from a user June 21, 2024 11:21
}

variable "key_spec" {
description = "Specification of the Key."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description doesn't give me info why it's needed and what's the use of it.

@@ -5,7 +5,7 @@
resource "aws_sns_topic" "graphdb_route53_sns_topic" {
provider = aws.useast1
name = "${var.resource_name_prefix}-route53-sns-notifications"
kms_master_key_id = "alias/aws/sns"
kms_master_key_id = var.sns_external_kms_key != "" ? var.sns_external_kms_key : (var.enable_sns_kms_key ? aws_kms_key.sns_cmk[0].arn : var.sns_default_kms_key)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that you need an additional variable for the default KMS key variable. Instead, use:

kms_master_key_id = var.sns_external_kms_key != "" ? var.sns_external_kms_key : (var.enable_sns_kms_key ? aws_kms_key.sns_cmk[0].arn : "alias/aws/sns")

"Sid" : "Allow root user to manage key",
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that work without specifying root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the idea is that the Root account have access so if anything goes wrong like it did in the other account, that the root account can fix it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like a good approach. Imagine deploying this in your department AWS account, something goes wrong and you need to request support from the root account holder. This could be incredibly slow and tedious procedure in some companies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, however we have had a problem last week with a Key that was created without a policy for some reason and it could not be reached, opened or deleted. That's why I have added this "safety net" just in case. It is only for the root account. I could remove it if you think it is bad, I don't think it will affect the rest of the module, however I have only put it in case it goes wrong agian.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was rather going in another direction, can't se allow only people with admin roles to access it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll research for another solution, test it and come back to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there isn't a default admin group/role that we can use, I can create it so that they can (if they want) provide admin group's ARN which will get the full access over the keys and if not provided it will be left empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see other options here @simeonzhekofff WDYT?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have an admin group that should have the right to assume an IAM role that has permission to take actions on the key.

@ghost ghost self-requested a review June 28, 2024 10:41
@ghost ghost closed this Jul 2, 2024
@ghost ghost deleted the GDB-9961-KMS-CMK branch July 3, 2024 10:56
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants