Skip to content

Commit

Permalink
change what is placed in the id field in policy
Browse files Browse the repository at this point in the history
  • Loading branch information
SethHollandsworth committed Mar 22, 2024
1 parent 7c1b491 commit 3a328f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/confcom/azext_confcom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ACI_FIELD_RESOURCES = "resources"
ACI_FIELD_RESOURCES_NAME = "name"
ACI_FIELD_CONTAINERS = "containers"
ACI_FIELD_CONTAINERS_NAME = "name"
ACI_FIELD_CONTAINERS_CONTAINERIMAGE = "containerImage"
ACI_FIELD_CONTAINERS_ENVS = "environmentVariables"
ACI_FIELD_CONTAINERS_ENVS_NAME = "name"
Expand Down
12 changes: 10 additions & 2 deletions src/confcom/azext_confcom/security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ def validate(self, policy, sidecar_validation=False) -> Tuple[bool, Dict]:
container1.pop(config.POLICY_FIELD_CONTAINERS_ELEMENTS_ENVS, None)
container2.pop(config.POLICY_FIELD_CONTAINERS_ELEMENTS_ENVS, None)

temp_diff = compare_containers(container1, container2)
diff_values = compare_containers(container1, container2)
# label the diff with the ID so it can be merged
# with the env vars and other container diffs
temp_diff[id_val] = diff_values
# for sidecar validation, it's fine if the policy has
# more things defined than the image, so we can take
# those out of the diff because it would not hinder deployment
Expand Down Expand Up @@ -607,6 +610,11 @@ def load_policy_from_arm_template_str(
image_properties, config.ACI_FIELD_TEMPLATE_IMAGE
)

# this is guaranteed unique for a valid ARM template
container_name = case_insensitive_dict_get(
container, config.ACI_FIELD_CONTAINERS_NAME
)

if not image_name:
eprint(
f'Field ["{config.ACI_FIELD_TEMPLATE_PARAMETERS}"] is empty or cannot be found'
Expand All @@ -618,7 +626,7 @@ def load_policy_from_arm_template_str(

containers.append(
{
config.ACI_FIELD_CONTAINERS_ID: image_name,
config.ACI_FIELD_CONTAINERS_ID: container_name,
config.ACI_FIELD_CONTAINERS_CONTAINERIMAGE: image_name,
config.ACI_FIELD_CONTAINERS_ENVS: process_env_vars_from_template(
AciPolicy.all_params, AciPolicy.all_vars, image_properties, approve_wildcards),
Expand Down
4 changes: 2 additions & 2 deletions src/confcom/azext_confcom/tests/latest/test_confcom_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ def test_multiple_policies(self):
is_valid, diff = self.aci_policy.validate_cce_policy()
self.assertFalse(is_valid)
# just check to make sure the containers in both policies are different
expected_diff = {"alpine:3.16": "alpine:3.16 not found in policy"}
expected_diff = {"aci-test": "aci-test not found in policy"}
self.assertEqual(diff, expected_diff)


Expand Down Expand Up @@ -2092,7 +2092,7 @@ class PolicyGeneratingArmInitContainer(unittest.TestCase):
],
"initContainers": [
{
"name": "init-container",
"name": "init-container-python",
"properties": {
"image": "python:3.6.14-slim-buster",
"environmentVariables": [
Expand Down

0 comments on commit 3a328f2

Please sign in to comment.