Skip to content

Custom rule to validate ARM template resource property minimumTlsVersion #998

Answered by Marc013
Marc013 asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to solve my challenge.
Property resources of $TargetObject is an array. By specifying the first array entry in that object I got access to the properties of the ARM template.

However, I do wonder if this is the best solution.
Any feedback is much appreciated.

# Synopsis: TESTING - should reject TLS versions older than 1.2.
Rule 'Azure.Template.MinTLS' -Type '.json' -If { (IsTemplateFile) } -Tag @{ release = 'TST'; ruleSet = '2022_03' } {
    $jsonObject = $PSRule.GetContent($TargetObject)[0].resources[0];
    AnyOf {
        $Assert.NotHasField($jsonObject, 'properties.minimumTlsVersion');
        $Assert.Match($jsonObject, 'properties.minimumTlsVersion', 'TLS1_2');
        $Assert

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@BernieWhite
Comment options

@Marc013
Comment options

@Marc013
Comment options

@BernieWhite
Comment options

Answer selected by Marc013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants