Skip to content
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
1 change: 1 addition & 0 deletions src/confcom/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release History
* making diff mode more robust
* bugfix for arm template regex
* updating genpolicy version up through 3.2.0.azl0.genpolicy1
* adding configmap sidecar

0.3.4
++++++
Expand Down
4 changes: 4 additions & 0 deletions src/confcom/azext_confcom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
ACI_FIELD_CONTAINERS_REGO_FRAGMENTS_MINIMUM_SVN = "minimumSvn"
ACI_FIELD_CONTAINERS_REGO_FRAGMENTS_INCLUDES = "includes"
ACI_FIELD_CONTAINERS_ID = "id"
ACI_FIELD_CONTAINERS_CONFIGMAP = "configMap"
ACI_FIELD_CONTAINERS_CONFIGMAP_KEYVALUE = "keyValuePairs"

ACI_FIELD_CONTAINERS_ARCHITECTURE_KEY = "Architecture"
ACI_FIELD_CONTAINERS_ARCHITECTURE_VALUE = "amd64"
Expand Down Expand Up @@ -118,6 +120,8 @@
POLICY_FIELD_CONTAINERS_ELEMENTS_REGO_FRAGMENTS_ISS = "iss"
POLICY_FIELD_CONTAINERS_ELEMENTS_REGO_FRAGMENTS_MINIMUM_SVN = "minimum_svn"
POLICY_FIELD_CONTAINERS_ELEMENTS_REGO_FRAGMENTS_INCLUDES = "includes"
POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS_CONFIGMAP_LOCATION = "/mnt/configmap"
POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS_CONFIGMAP_TYPE = "emptyDir"

CONFIG_FILE = "./data/internal_config.json"

Expand Down
3 changes: 2 additions & 1 deletion src/confcom/azext_confcom/data/internal_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
"mcr.microsoft.com/aci/atlas-mount-gitrepo-volume",
"k8s.gcr.io/pause",
"mcr.microsoft.com/aci/sc-proxy",
"mcr.microsoft.com/aci/vk-metrics-sidecar"
"mcr.microsoft.com/aci/vk-metrics-sidecar",
"mcr.microsoft.com/aci/configmaps-adapter-linux"
],
"default_rego_fragments": [
{
Expand Down
4 changes: 3 additions & 1 deletion src/confcom/azext_confcom/security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
compare_containers,
get_values_for_params,
process_mounts,
process_configmap,
extract_probe,
process_env_vars_from_template,
get_image_info,
Expand Down Expand Up @@ -648,7 +649,8 @@ def load_policy_from_arm_template_str(
image_properties, config.ACI_FIELD_TEMPLATE_COMMAND
)
or [],
config.ACI_FIELD_CONTAINERS_MOUNTS: process_mounts(image_properties, volumes),
config.ACI_FIELD_CONTAINERS_MOUNTS: process_mounts(image_properties, volumes)
+ process_configmap(image_properties),
config.ACI_FIELD_CONTAINERS_EXEC_PROCESSES: exec_processes
+ config.DEBUG_MODE_SETTINGS.get("execProcesses")
if debug_mode
Expand Down
15 changes: 15 additions & 0 deletions src/confcom/azext_confcom/template_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ def process_mounts(image_properties: dict, volumes: List[dict]) -> List[Dict[str
return mounts


def process_configmap(image_properties: dict) -> List[Dict[str, str]]:
Comment thread
hgarvison marked this conversation as resolved.
# return empty list if we don't have a configmap
if not case_insensitive_dict_get(
image_properties, config.ACI_FIELD_CONTAINERS_CONFIGMAP
):
return []

return [{
config.ACI_FIELD_CONTAINERS_MOUNTS_TYPE:
config.POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS_CONFIGMAP_TYPE,
config.ACI_FIELD_CONTAINERS_MOUNTS_PATH:
config.POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS_CONFIGMAP_LOCATION,
config.ACI_FIELD_CONTAINERS_MOUNTS_READONLY: False,
}]

def get_values_for_params(input_parameter_json: dict, all_params: dict) -> Dict[str, Any]:
# combine the parameter file into a single dictionary with the template
# parameters
Expand Down
16 changes: 16 additions & 0 deletions src/confcom/azext_confcom/tests/latest/test_confcom_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3627,6 +3627,11 @@ class PolicyGeneratingEdgeCases(unittest.TestCase):
"port": "[parameters('port')]"
}
],
"configMap": {
"keyValuePairs": {
"key1": "value1"
}
},
"command": [
"/bin/bash",
"-c",
Expand Down Expand Up @@ -3688,6 +3693,17 @@ def test_arm_template_with_env_var(self):
self.assertEqual(env_var, "PORT=parameters('abc')")
self.assertEqual(regular_image_json[0][config.POLICY_FIELD_CONTAINERS_ID], "alpine:3.16")

def test_arm_template_config_map_sidecar(self):
regular_image_json = json.loads(
self.aci_arm_policy.get_serialized_output(
output_type=OutputType.RAW, rego_boilerplate=False
)
)

mount_locations = list(map(lambda x: x[config.POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS_DESTINATION] ,regular_image_json[0][config.POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS]))

self.assertTrue(config.POLICY_FIELD_CONTAINERS_ELEMENTS_MOUNTS_CONFIGMAP_LOCATION in mount_locations)


class PolicyGeneratingSecurityContext(unittest.TestCase):
custom_arm_json = """
Expand Down
Binary file modified src/confcom/samples/sample-policy-output.rego
Binary file not shown.
5 changes: 5 additions & 0 deletions src/confcom/samples/sample-template-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"port": 80
}
],
"configMap": {
"keyValuePairs": {
"key1": "value1"
}
},
"volumeMounts": [
{
"name": "azurefile",
Expand Down
Loading