generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_key_vault_certificate_lifetime_action
- Loading branch information
Showing
5 changed files
with
392 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
docs/rules/azurerm_key_vault_certificate_lifetime_action.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# azurerm_key_vault_certificate_lifetime_action | ||
|
||
**Severity:** Warning | ||
|
||
|
||
## Example | ||
|
||
```hcl | ||
resource "azurerm_key_vault_certificate" "example" { | ||
certificate_policy { | ||
# missing lifetime_policy | ||
} | ||
} | ||
``` | ||
|
||
## Why | ||
|
||
Setting lifetime_action to AutoRenew or EmailContacts ensures proactive management of certificate expiration, reducing the risk of service interruptions or security vulnerabilities caused by expired certificates. | ||
|
||
## How to Fix | ||
|
||
```hcl | ||
resource "azurerm_key_vault_certificate" "example" { | ||
certificate_policy { | ||
lifetime_action { | ||
action { | ||
action_type = "AutoRenew" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
## How to disable | ||
|
||
```hcl | ||
rule "azurerm_key_vault_certificate_lifetime_action" { | ||
enabled = false | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
rules/azurerm_key_vault_certificate_lifetime_action_action_type.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package rules | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/terraform-linters/tflint-plugin-sdk/hclext" | ||
"github.com/terraform-linters/tflint-plugin-sdk/tflint" | ||
|
||
"github.com/terraform-linters/tflint-ruleset-azurerm-security/project" | ||
) | ||
|
||
// AzurermKeyVaultCertificateLifetimeAction checks that certificate_policy.lifetime_action.action.action_type | ||
// is set to either "AutoRenew" or "EmailContacts" | ||
type AzurermKeyVaultCertificateLifetimeAction struct { | ||
tflint.DefaultRule | ||
|
||
resourceType string | ||
attributePath []string | ||
validValues []string | ||
} | ||
|
||
// NewAzurermKeyVaultCertificateLifetimeAction returns a new rule instance | ||
func NewAzurermKeyVaultCertificateLifetimeAction() *AzurermKeyVaultCertificateLifetimeAction { | ||
return &AzurermKeyVaultCertificateLifetimeAction{ | ||
resourceType: "azurerm_key_vault_certificate", | ||
attributePath: []string{"certificate_policy", "lifetime_action", "action", "action_type"}, | ||
validValues: []string{"AutoRenew", "EmailContacts"}, | ||
} | ||
} | ||
|
||
// Name returns the rule name | ||
func (r *AzurermKeyVaultCertificateLifetimeAction) Name() string { | ||
return "azurerm_key_vault_certificate_lifetime_action" | ||
} | ||
|
||
// Enabled returns whether the rule is enabled by default | ||
func (r *AzurermKeyVaultCertificateLifetimeAction) Enabled() bool { | ||
return true | ||
} | ||
|
||
// Severity returns the rule severity | ||
func (r *AzurermKeyVaultCertificateLifetimeAction) Severity() tflint.Severity { | ||
return tflint.WARNING | ||
} | ||
|
||
// Link returns the rule reference link | ||
func (r *AzurermKeyVaultCertificateLifetimeAction) Link() string { | ||
return project.ReferenceLink(r.Name()) | ||
} | ||
|
||
// Check verifies that the certificate policy lifetime action is properly configured | ||
func (r *AzurermKeyVaultCertificateLifetimeAction) Check(runner tflint.Runner) error { | ||
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ | ||
Blocks: []hclext.BlockSchema{ | ||
{ | ||
Type: "certificate_policy", | ||
Body: &hclext.BodySchema{ | ||
Blocks: []hclext.BlockSchema{ | ||
{ | ||
Type: "lifetime_action", | ||
Body: &hclext.BodySchema{ | ||
Blocks: []hclext.BlockSchema{ | ||
{ | ||
Type: "action", | ||
Body: &hclext.BodySchema{ | ||
Attributes: []hclext.AttributeSchema{ | ||
{Name: "action_type"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, resource := range resources.Blocks { | ||
certPolicyBlocks := resource.Body.Blocks.OfType("certificate_policy") | ||
if len(certPolicyBlocks) == 0 { | ||
runner.EmitIssue( | ||
r, | ||
"certificate_policy block is missing", | ||
resource.DefRange, | ||
) | ||
continue | ||
} | ||
|
||
certPolicy := certPolicyBlocks[0] | ||
lifetimeActionBlocks := certPolicy.Body.Blocks.OfType("lifetime_action") | ||
if len(lifetimeActionBlocks) == 0 { | ||
runner.EmitIssue( | ||
r, | ||
"lifetime_action block is missing in certificate_policy", | ||
certPolicy.DefRange, | ||
) | ||
continue | ||
} | ||
|
||
lifetimeAction := lifetimeActionBlocks[0] | ||
actionBlocks := lifetimeAction.Body.Blocks.OfType("action") | ||
if len(actionBlocks) == 0 { | ||
runner.EmitIssue( | ||
r, | ||
"action block is missing in lifetime_action", | ||
lifetimeAction.DefRange, | ||
) | ||
continue | ||
} | ||
|
||
action := actionBlocks[0] | ||
attribute, exists := action.Body.Attributes["action_type"] | ||
if !exists { | ||
runner.EmitIssue( | ||
r, | ||
"action_type is missing in action block, should be set to either AutoRenew or EmailContacts", | ||
action.DefRange, | ||
) | ||
continue | ||
} | ||
|
||
err := runner.EvaluateExpr(attribute.Expr, func(val string) error { | ||
valid := false | ||
for _, validValue := range r.validValues { | ||
if strings.EqualFold(val, validValue) { | ||
valid = true | ||
break | ||
} | ||
} | ||
if !valid { | ||
runner.EmitIssue( | ||
r, | ||
fmt.Sprintf("action_type is set to %s, should be set to either AutoRenew or EmailContacts", val), | ||
attribute.Expr.Range(), | ||
) | ||
} | ||
return nil | ||
}, nil) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
6ab1216
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (39)
To use the spell-check-this repository and accept these unrecognized words as correct, you could run the following commands
... in a clone of the [email protected]:pregress/tflint-ruleset-azurerm-security.git repository
on the
feat_more_rules
branch (ℹ️ how do I use this?):Available 📚 dictionaries could cover words not in the 📘 dictionary
Consider adding them (in
.github/workflows/spelling.yml
) injobs:
/spelling:
foruses: check-spelling/check-spelling@main
in itswith
:To stop checking additional dictionaries, add (in
.github/workflows/spelling.yml
) foruses: check-spelling/check-spelling@main
in itswith
:Pattern suggestions ✂️ (5)
You could add these patterns to
.github/actions/spelling/patterns.txt
:Errors (2)
See the 📜action log or 📝 job summary for details.
See ❌ Event descriptions for more information.