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

[BUG] Export-AzPolicyAssignmentRuleData unable to export Azure policy as PSRule (The function "field" was not found) [Custom policy: Prevent cross tenant Private Link for ampls] #2731

Open
Marc013 opened this issue Mar 5, 2024 · 1 comment
Assignees
Labels
bug Something isn't working feature: policy-as-rules Issues that related to exporting policy as rules.

Comments

@Marc013
Copy link

Marc013 commented Mar 5, 2024

Existing rule

No response

Description of the issue

Unable to export policy assignment data to PSRule.

{
    "Name": "00000000-0000-0000-0000-000000000000",
    "ResourceId": "/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/00000000-0000-0000-0000-000000000000",
    "ResourceName": "00000000-0000-0000-0000-000000000000",
    "ResourceType": "Microsoft.Authorization/policyDefinitions",
    "SubscriptionId": null,
    "Properties": {
        "Description": "This policy prevents private link between tenants for ampls.",
        "DisplayName": "Prevent cross tenant Private Link for ampls",
        "Metadata": {
            "version": "0.0.2",
            "category": "Network",
            "status": "Active",
            "Control": "ABC1, ABC2, ABC3, ABC4, ABC5",
            "purpose": "This policy prevents private link between tenants for ampls.",
            "tags": [
                {
                    "managedpolicy": "true"
                }
            ],
            "createdBy": "00000000-0000-0000-0000-000000000000",
            "createdOn": "2023-06-14T14:18:39.548002Z",
            "updatedBy": null,
            "updatedOn": null
        },
        "Mode": "All",
        "Parameters": {
            "effect": {
                "type": "String",
                "metadata": {
                    "description": "The effect of the policy",
                    "displayName": "Effect"
                },
                "allowedValues": [
                    "Audit",
                    "Deny",
                    "Disabled"
                ],
                "defaultValue": "Deny"
            }
        },
        "PolicyRule": {
            "if": {
                "allOf": [
                    {
                        "equals": "Microsoft.OperationalInsights/workspaces/privateEndpointConnections",
                        "field": "type"
                    },
                    {
                        "anyOf": [
                            {
                                "exists": false,
                                "field": "Microsoft.OperationalInsights/workspaces/privateEndpointConnections.privateEndpoint.id"
                            },
                            {
                                "notEquals": "[subscription().subscriptionId]",
                                "value": "[split(concat(field('Microsoft.OperationalInsights/workspaces/privateEndpointConnections.privateEndpoint.id'), '//'), '/')[2]]"
                            }
                        ]
                    }
                ]
            },
            "then": {
                "effect": "[parameters('effect')]"
            }
        },
        "PolicyType": 1
    },
    "PolicyDefinitionId": "/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/00000000-0000-0000-0000-000000000000"
}

Error messages

An error occurred evaluating expression '[split(concat(field('Microsoft.OperationalInsights/workspaces/privateEndpointConnections.privateEndpoint.id'), '//'), '/')[2]]' line 57. The function "field" was not found.

Reproduction

Exporting policy assignment data

Version of PSRule

2.9.0

Version of PSRule for Azure

1.33.2

Additional context

This bug is related to #1323

@Marc013 Marc013 added bug Something isn't working Needs: Triage 🔍 labels Mar 5, 2024
@BernieWhite BernieWhite added feature: policy-as-rules Issues that related to exporting policy as rules. and removed Needs: Triage 🔍 labels Mar 6, 2024
@BernieWhite BernieWhite self-assigned this May 2, 2024
@BernieWhite BernieWhite added this to the v1.37.0 milestone May 2, 2024
@BernieWhite
Copy link
Collaborator

Currently we need to support indexing into an array of string with a runtime token to fully complete this implementation which requires support to be added to PSRule.

@BernieWhite BernieWhite removed this from the v1.37.0 milestone Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature: policy-as-rules Issues that related to exporting policy as rules.
Projects
None yet
Development

No branches or pull requests

2 participants