-
Notifications
You must be signed in to change notification settings - Fork 89
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
Policy key already exists #1653
Comments
@BernieWhite I can work on this one. Not sure how we would generate a unique Also, not sure how we'd handle cases where the same policy definition is assigned but different variations of parameters are used. Would we include all rules and generate unique Also thinking for the dictionary key collision issue, should include the |
@ArmaanMcleod Yes. I think the error is a dictionary collision, however I think we are still going to need to resolve it more broadly. Consider an initiative assignment that might be used for tagging. To enforce two or more tags it's highly likely and recommended that a customer would reference the same policy definition twice such as the built-in In both cases the customer would just use the I was thinking a hash could be generated of the
Although we would probably also need to think about any pre-conditions that would come out of #1708 at some point. If we generate a hash based on definitionId + condition + pre-conditions this should give us something unique that can be used to avoid collisions and deterministic. |
@BernieWhite I'm assuming your tags example would like: "policyDefinitions": [
{
"policyDefinitionReferenceId": "Inherit a tag from the subscription_1",
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/b27a0cbd-a167-4dfa-ae64-4337be671140",
"parameters": {
"tagName": {
"value": "costCentre"
}
},
"groupNames": []
},
{
"policyDefinitionReferenceId": "Inherit a tag from the subscription_2",
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/b27a0cbd-a167-4dfa-ae64-4337be671140",
"parameters": {
"tagName": {
"value": "department"
}
},
"groupNames": []
}
] Where the same definition is used in the initiative twice, but different The problem I see here is I think this can be fixed by tweaking What do you think? |
@ArmaanMcleod That's one variation, but definition parameter can be fed from initiative assignment parameters as well.
Using the |
@BernieWhite Yeah fully agree, I think the issue I'm seeing is how the visitor is processing parameters before expanding the policy rule: https://github.com/Azure/PSRule.Rules.Azure/blob/main/src/PSRule.Rules.Azure/Data/Policy/PolicyAssignmentVisitor.cs#L171-L182 In order for it to look up and expand parameters, the parameters from assignment level are set beforehand. This means for the condition approach to be reliable, it must be processed and expanded first, otherwise policy definitions will be duplicated since the conditions will remain the same. Gets challenging to do definition duplication detection with condition hash before the condition is expanded 😄. |
@ArmaanMcleod I've refactored for a fair bit for #1708. I think it should be easier to implement this with the latest updates. If you get stuck, let me know. |
@BernieWhite What do you think of this for unique hashes for "name": "Azure.Policy.f5388351250d",
"ref": "Azure.Policy.f5388351250d", I kept them the same for now as they both use the hash(hexidecimal with length 6) of the definitionId + condition + pre-condition. |
@ArmaanMcleod That should be fine. In terms of Configuration would be by Maybe let's allow for this. And either tackle this in this or a separate issue. |
@BernieWhite That sounds good. Should we create something like a Something like this: configuration:
AZURE_POLICY_RULE:
prefix: 'something'
otherConfig: ... Or would you rather just keep it simpler configuration:
AZURE_POLICY_RULE_PREFIX: 'something' I was thinking if we should use the first approach in case we need to configure more stuff together like the other options. |
@ArmaanMcleod Let's go with option 2. It adds complexity to manage merging nested objects. If we don't need to better to keep it simple. |
Description of the issue
When policy definitions are assigned multiple times (which may have different parameters) the subsequent occurrences fail.
Expected behaviour
We need to:
name
andref
for each policy rule. We should be able to do this via a hash of the condition/ pre-conditions.For example:
Policy.e749c2d003da
Error output
Module in use and version:
Captured output from
$PSVersionTable
:Additional context
Related to #181
The text was updated successfully, but these errors were encountered: