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 additional classifiers #1

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions Terraform_Examples/data_labels.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@

terraform {
required_providers {
cyral = {
source = "cyralinc/cyral"
version = "~> 4.0"
}
}
}

## Setup connection to the control plane

provider "cyral" {
client_id = ""
client_secret = ""

control_plane = ""
}

locals {
no_code_data_labels = toset(compact((split("\n", file("./resource_files/no_code_data_labels.txt")))))
}
Expand All @@ -7,14 +26,14 @@ locals {
}


resource "cyral_datalabel" "data_labels" {
for_each = local.no_code_data_labels
name = each.key
classification_rule {
rule_status = "DISABLED"
rule_type = "UNKNOWN"
}
}
#resource "cyral_datalabel" "data_labels" {
# for_each = local.no_code_data_labels
# name = each.key
# classification_rule {
# rule_status = "DISABLED"
# rule_type = "UNKNOWN"
# }
#}

resource "cyral_datalabel" "data_labels_with_code" {
for_each = local.data_labels_json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package classifier_cardholder_name

test_dob_pattern {
test_chn_pattern {
output.cardholder_name == "CARDHOLDER_NAME" with input as {"cardholder_name":"John Doe"}
}

test_dob_pattern {
test_chn_pattern {
output.cardholder_name == "CARDHOLDER_NAME" with input as {"cardholder_name":"Robert Williams-Brown"}
}

test_dob_pattern {
test_chn_pattern {
output.cardholdername == "CARDHOLDER_NAME" with input as {"cardholdername":"Robert Williams-Brown"}
}

test_dob_pattern {
test_chn_pattern {
output.cardholderName == "CARDHOLDER_NAME" with input as {"cardholderName":"Robert Williams-Brown"}
}

test_dob_pattern {
test_chn_pattern {
output.cardholder_Name == "CARDHOLDER_NAME" with input as {"cardholder_Name":"Robert Williams-Brown"}
}

test_dob_pattern {
test_chn_pattern {
output.cardholderName == "CARDHOLDER_NAME" with input as {"cardholderName":"Robert Williams-Brown"}
}
7 changes: 6 additions & 1 deletion Terraform_Examples/resource_files/data_label_rego/dob.rego
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ classify(key, val) := "DOB" {
any([
lower(key) == "dob",
lower(key) == "birthdate",
regex.match(`^(0?[1-9]|1[0-2])[\/](0?[1-9]|[12]\d|3[01])[\/](19|20)\d{2}$`, val)
# mm/dd/yyyy mm-dd-yyyy mm.dd.yyyy
regex.match(`^(0?[1-9]|1[0-2])[\/\.-](0?[1-9]|[12]\d|3[01])[\/\.-](19|20)\d{2}$`, val),
# dd/mm/yyyy
regex.match(`^(0?[1-9]|[12]\d|3[01])[\/\.-](0?[1-9]|1[0-2])[\/\.-](19|20)\d{2}$`, val),
# yyyy/mm/dd
regex.match(`^(19|20)\d{2}[\/\.-](0?[1-9]|1[0-2])[\/\.-](0?[1-9]|[12]\d|3[01])$`, val),
])
} else = "UNLABELED" {
true
Expand Down
41 changes: 40 additions & 1 deletion Terraform_Examples/resource_files/data_label_rego/dob_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ test_dob_key {
output.BirthDate == "DOB" with input as {"BirthDate":"test"}
}

# mm/dd/yyyy

test_dob_pattern {
output.message == "DOB" with input as {"message":"01/01/1900"}
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"1-1-1900"}
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"10.01.1971"}
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"11/30/2023"}
}

# dd/mm/yyyy

test_dob_pattern {
output.message == "DOB" with input as {"message":"01/01/1900"}
}
Expand All @@ -33,5 +53,24 @@ test_dob_pattern {
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"11/30/2023"}
output.message == "DOB" with input as {"message":"30/11/2023"}
}


# yyyy/mm/dd

test_dob_pattern {
output.message == "DOB" with input as {"message":"1900/01/10"}
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"1900/1/1"}
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"1971/10/01"}
}

test_dob_pattern {
output.message == "DOB" with input as {"message":"2023/12/31"}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package classifier_first_name

test_dob_pattern {
test_fn_pattern {
output.first_name == "FIRST_NAME" with input as {"first_name":"John"}
}

test_dob_pattern {
test_fn_pattern {
output.first_name == "FIRST_NAME" with input as {"first_name":"Robert"}
}

test_dob_pattern {
test_fn_pattern {
output.firstname == "FIRST_NAME" with input as {"firstname":"Robert"}
}

test_dob_pattern {
test_fn_pattern {
output.firstName == "FIRST_NAME" with input as {"firstName":"Robert"}
}

test_dob_pattern {
test_fn_pattern {
output.First_Name == "FIRST_NAME" with input as {"First_Name":"Robert"}
}

test_dob_pattern {
test_fn_pattern {
output.FirstName == "FIRST_NAME" with input as {"FirstName":"Robert"}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package classifier_full_name

test_dob_pattern {
test_fullname_pattern {
output.full_name == "FULL_NAME" with input as {"full_name":"John Doe"}
}

test_dob_pattern {
test_fullname_pattern {
output.full_name == "FULL_NAME" with input as {"full_name":"Robert Williams-Brown"}
}

test_dob_pattern {
test_fullname_pattern {
output.fullname == "FULL_NAME" with input as {"fullname":"Robert Williams-Brown"}
}

test_dob_pattern {
test_fullname_pattern {
output.fullName == "FULL_NAME" with input as {"fullName":"Robert Williams-Brown"}
}

test_dob_pattern {
test_fullname_pattern {
output.Full_Name == "FULL_NAME" with input as {"Full_Name":"Robert Williams-Brown"}
}

test_dob_pattern {
test_fullname_pattern {
output.FullName == "FULL_NAME" with input as {"FullName":"Robert Williams-Brown"}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package classifier_last_name

test_dob_pattern {
test_ln_pattern {
output.last_name == "LAST_NAME" with input as {"last_name":"Doe"}
}

test_dob_pattern {
test_ln_pattern {
output.last_name == "LAST_NAME" with input as {"last_name":"Williams-Brown"}
}

test_dob_pattern {
test_ln_pattern {
output.lastname == "LAST_NAME" with input as {"lastname":"Williams-Brown"}
}

test_dob_pattern {
test_ln_pattern {
output.lastName == "LAST_NAME" with input as {"lastName":"Williams-Brown"}
}

test_dob_pattern {
test_ln_pattern {
output.Last_Name == "LAST_NAME" with input as {"Last_Name":"Williams-Brown"}
}

test_dob_pattern {
test_ln_pattern {
output.LastName == "LAST_NAME" with input as {"LastName":"Williams-Brown"}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ test_passport_pattern {
output.message == "PASSPORT" with input as {"message":"E12345678"}
}


# South Africa (diplomat, standard covered by other countries)
test_passport_sa_pattern {
output.message == "PASSPORT" with input as {"message":"D123456789"}
}



Expand Down
7 changes: 3 additions & 4 deletions Terraform_Examples/resource_files/data_label_rego/phone.rego
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ output := {k: v |
classify(key, val) := "PHONE" {
any([
contains(lower(key), "phone"),
regex.match(
`\(?\d{3}\)?[ .-]?\d{3}[ .-]?\d{4}`,
val
)
regex.match(`\(?\d{3}\)?[ .-]?\d{3}[ .-]?\d{4}`, val),
regex.match(`\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$`, val),
regex.match(`((?:9[679]|8[035789]|6[789]|5[90]|42|3[578]|2[1-689])|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)(?:\W*\d){0,13}\d$`, val)
])
} else := "UNLABELED" {
true
Expand Down
18 changes: 18 additions & 0 deletions Terraform_Examples/resource_files/data_label_rego/phone_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ test_phone_key {
output.PhoneNumber == "PHONE" with input as {"PhoneNumber":"some number"}
}


# standard US patterns

test_phone_pattern {
output.message == "PHONE" with input as {"message":"+1-(800)-123-4567"}
}
Expand All @@ -39,3 +42,18 @@ test_phone_pattern {
test_phone_pattern {
output.message == "PHONE" with input as {"message":"123 456 7890"}
}


# South Africa specific tests

test_phone_valid_with_country_code {
output.message == "PHONE" with input as {"message": "0027 12 456 7890"}
}

test_phone_valid_with_plus_sign {
output.message == "PHONE" with input as {"message": "+27 11 123 4567"}
}

test_phone_valid_mobile {
output.message == "PHONE" with input as {"message": "+27791234567"}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package classifier_surname

test_dob_pattern {
test_sn_pattern {
output.surname == "SURNAME" with input as {"surname":"Doe"}
}

test_dob_pattern {
test_sn_pattern {
output.surname == "SURNAME" with input as {"surname":"Williams-Brown"}
}

test_dob_pattern {
test_sn_pattern {
output.surname == "SURNAME" with input as {"surname":"Williams-Brown"}
}

test_dob_pattern {
test_sn_pattern {
output.SurName == "SURNAME" with input as {"SurName":"Williams-Brown"}
}

test_dob_pattern {
test_sn_pattern {
output.SurName == "SURNAME" with input as {"SurName":"Williams-Brown"}
}
Loading
Loading