Skip to content

Instantly share code, notes, and snippets.

@iloveicedgreentea
Created June 15, 2021 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveicedgreentea/4be7f168fa8a091d28fa703cc2ff4e99 to your computer and use it in GitHub Desktop.
Save iloveicedgreentea/4be7f168fa8a091d28fa703cc2ff4e99 to your computer and use it in GitHub Desktop.
semgrep
rules:
- id: wrong-project
patterns:
- pattern-inside: resource "google_compute_firewall" "..." {...}
- pattern-inside: project="..."
- pattern-not: project = "myproject"
languages:
- generic
paths:
include:
- 'main.tf'
message: |
Firewall rule must use myproject as the target project.
severity: ERROR
- id: banned-protocol
patterns:
- pattern-inside: allow { ... }
- pattern-not-inside: allow { ... protocol = "tcp" ... }
languages:
- generic
paths:
include:
- 'main.tf'
message: |
Firewall rule must use TCP as protocol
severity: ERROR
- id: banned-80
patterns:
- pattern-inside: allow { ... }
- pattern: "80"
languages:
- generic
paths:
include:
- 'main.tf'
message: |
Firewall rule must not allow port 80
severity: ERROR
- id: banned-22
patterns:
- pattern-inside: allow { ... }
- pattern: "22"
languages:
- generic
paths:
include:
- 'main.tf'
message: |
Firewall rule must not allow port 22
severity: ERROR
- id: no-serviceaccount
patterns:
- pattern-inside: resource "google_compute_firewall" "..." {...}
- pattern-not-inside: resource "google_compute_firewall" "..." {... target_service_accounts=[...] ... }
languages:
- generic
paths:
include:
- 'main.tf'
message: |
Firewall rule must use a service account as the target.
severity: ERROR
- id: no-provisioners
patterns:
- pattern-inside: provisioner "..."
languages:
- generic
paths:
include:
- 'main.tf'
message: |
Provisioners are not allowed.
severity: ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment