Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
paulschwarzenberger committed Aug 19, 2024
1 parent 0746aea commit f55a060
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
db_list_certificates,
db_issue_certificate,
)
from utils.certs.s3 import s3_download, is_cert_gitops
from utils.certs.s3 import cert_issued_via_gitops, s3_download
from cryptography.x509 import load_pem_x509_certificate, load_pem_x509_csr
from cryptography.hazmat.primitives import serialization
from dataclasses import dataclass, field
Expand Down Expand Up @@ -287,7 +287,7 @@ def lambda_handler(event, context): # pylint:disable=unused-argument,too-many-l
base64_ca_chain=ca_chain_response.base64_ca_chain,
)

if is_cert_gitops(internal_s3_bucket_name, response.subject):
if cert_issued_via_gitops(internal_s3_bucket_name, response.subject):
sns_notify_cert_issued(response.to_dict(), sns_topic_arn)

return response.to_dict()
16 changes: 10 additions & 6 deletions modules/terraform-aws-ca-lambda/utils/certs/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def s3_upload(
return s3_upload_file(file, internal_s3_bucket_name, key, content_type)


def convert_to_json(input_str):
def convert_x509_subject_str_to_dict(input_str):
# split string by commas
pairs = input_str.split(",")

Expand All @@ -55,16 +55,20 @@ def convert_to_json(input_str):
return json_dictionary


def is_cert_gitops(internal_s3_bucket_name, subject):
subject_json = convert_to_json(subject)
def cert_issued_via_gitops(internal_s3_bucket_name, subject):
# get list of GitOps certificates from internal S3 bucket
tls_file = s3_download_file(internal_s3_bucket_name, "tls.json")

return is_cert_gitops(tls_file, subject)


def is_cert_gitops(tls_file, subject):
subject_json = convert_x509_subject_str_to_dict(subject)

cn = subject_json["CN"]
o = subject_json.get("O")
ou = subject_json.get("OU")

# get list of GitOps certificates from internal S3 bucket
tls_file = s3_download_file(internal_s3_bucket_name, "tls.json")

if tls_file is None:
gitops_certs = []

Expand Down
2 changes: 1 addition & 1 deletion modules/terraform-aws-ca-sns/locals.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
sns_topic_display_name = coalesce(var.custom_sns_topic_name, title(replace("${var.project}-${var.function}-${var.env}", "-", " ")))
sns_topic_display_name = coalesce(var.custom_sns_topic_name, replace(title(replace("${var.project}-${var.function}-${var.env}", "-", " ")), " Ca ", " CA "))
sns_topic_name = coalesce(var.custom_sns_topic_name, "${var.project}-${var.function}-${var.env}")

tags = merge(var.tags, {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_issued_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ def test_csr_uploaded_to_s3():

assert_that(issued_cert.subject.rfc4514_string()).is_equal_to(expected_subject)
if test_sns:
# check SNS messsage received via email subscription
# TODO: implement programatically within tests
delete_s3_object(bucket_name, "tls.json")


Expand Down

0 comments on commit f55a060

Please sign in to comment.