aboutsummaryrefslogtreecommitdiff
path: root/content/blog/terraform
diff options
context:
space:
mode:
Diffstat (limited to 'content/blog/terraform')
-rw-r--r--content/blog/terraform/acme.md6
-rw-r--r--content/blog/terraform/caa.md22
-rw-r--r--content/blog/terraform/chart-http-datasources.md8
-rw-r--r--content/blog/terraform/email-dns-unused-zone.md104
-rw-r--r--content/blog/terraform/tofu.md18
5 files changed, 131 insertions, 27 deletions
diff --git a/content/blog/terraform/acme.md b/content/blog/terraform/acme.md
index f19302b..37045fd 100644
--- a/content/blog/terraform/acme.md
+++ b/content/blog/terraform/acme.md
@@ -1,16 +1,16 @@
---
-title: Certificate management with opentofu and eventline
+title: Certificate management with OpenTofu and eventline
description: How I manage for my personal infrastructure
date: 2024-03-06
tags:
- Eventline
-- opentofu
+- OpenTofu
- terraform
---
## Introduction
-In this article, I will explain how I handle the management and automatic renewal of SSL certificates on my personal infrastructure using opentofu (the fork of terraform) and [eventline](https://www.exograd.com/products/eventline/). I chose to centralise the renewal on my single host running eventline and to generate a single wildcard certificate for each domain I manage.
+In this article, I will explain how I handle the management and automatic renewal of SSL certificates on my personal infrastructure using OpenTofu (the fork of terraform) and [eventline](https://www.exograd.com/products/eventline/). I chose to centralise the renewal on my single host running eventline and to generate a single wildcard certificate for each domain I manage.
## Wildcard certificates
diff --git a/content/blog/terraform/caa.md b/content/blog/terraform/caa.md
index 2f3f9ad..ce6ff37 100644
--- a/content/blog/terraform/caa.md
+++ b/content/blog/terraform/caa.md
@@ -3,19 +3,19 @@ title: CAA DNS records with OpenTofu
description: How I manage which acme CA can issue certificates for me
date: 2024-05-27
tags:
-- opentofu
+- OpenTofu
- terraform
---
-# Introduction
+## Introduction
Certification Authority Authorization (CAA) are a type of DNS records that allows the owner of a domain to restrict which Certificate Authority (CA) can emit a certificate for the domain. This is a protection mechanism that is easy to setup and that has absolutely no drawbacks.
One good reason to use CAA records in our modern world of servers running in the cloud is that when you decommission or change a server you very often lose access to its IP address and get a new one. If you mess up cleaning the old IP address from your DNS records and have no CAA records, someone who grabs it could then start issuing certificates for your domain.
-# CAA records
+## CAA records
-## Basics
+### Basics
CAA record can be queried with your favorite DNS lookup utility (`dig`, `drill`, `nslookup`, etc). A basic example looks like this:
```
@@ -26,7 +26,7 @@ $ dig +short CAA adyxax.org
In this example, letsencrypt is authorized to issue both standard and wildcard certificates for the adyxax.org domain.
-## Getting notified of wrongful attempts
+### Getting notified of wrongful attempts
There are several bits of syntax in the RFC that can be of interest, especially if you want to be notified when someone tries to issue a certificate from an unauthorized CA:
@@ -37,7 +37,7 @@ $ dig +short CAA adyxax.org
0 issuewild "letsencrypt.org"
```
-## Securing a domain even further
+### Securing a domain even further
There are other extensions that allow domain owners to restrict even more things like which certificate validation method can be used. Just keep in mind that these extensions will vary from CA to CA and you will need to read the documentation of your CA of choice. A letsencrypt locked down certificate issuance to a specific account ID with a specific validation method looks like this:
@@ -49,15 +49,15 @@ $ dig +short CAA adyxax.org
With this configuration, I can be pretty sure only I will be able to generate a (wildcard, other types are not authorized) certificate for my domain.
-## Caveat
+### Caveat
Note that some DNS providers that offer hosting services will sometimes provision invisible CAA records on your behalf and it might not be obvious this is happening. For example if your domain is hosted on Cloudflare and you use their `pages` service, they will add CAA records to issue their certificates. You will be able to see these records using your lookup tool, but not if you look at your Cloudflare dashboard.
-# Opentofu code
+## Opentofu code
The following code examples will first feature a standard version (suitable for AWS, GCP and other providers), and one for Cloudflare. Cloudflare records are built different than other providers I know of because the Cloudflare terraform provider does some validation by itself while others simply rely on their APIs. Another important difference is that terraform resources use a list of records as input, while Cloudflare forces you to create one resource per value you need for a record. Yes this will clutter your terraform states!
-## Basic
+### Basic
Here is a simple definition for multiple zones managed the same way on AWS:
```hcl
@@ -133,7 +133,7 @@ resource "cloudflare_record" "caa" {
}
```
-## Advanced
+### Advanced
Here is a more advanced definition that handles zones that have different needs than others, as well as CAs that have multiple signing domains like AWS does:
```hcl
@@ -236,6 +236,6 @@ resource "cloudflare_record" "caa" {
}
```
-# Conclusion
+## Conclusion
I hope I showed you that CAA records are both useful and accessible. Please start protecting your domains with CAA records now!
diff --git a/content/blog/terraform/chart-http-datasources.md b/content/blog/terraform/chart-http-datasources.md
index ebf0aba..5c4108d 100644
--- a/content/blog/terraform/chart-http-datasources.md
+++ b/content/blog/terraform/chart-http-datasources.md
@@ -1,18 +1,18 @@
---
-title: Manage helm charts extras with opentofu
+title: Manage helm charts extras with OpenTofu
description: a use case for the http datasource
date: 2024-04-25
tags:
- aws
-- opentofu
+- OpenTofu
- terraform
---
## Introduction
-When managing helm charts with opentofu (terraform), you often have to hard code correlated settings for versioning (like app version and chart version). Sometimes it goes even further and you need to fetch a policy or a manifest with some CRDs that the chart will depend on.
+When managing helm charts with OpenTofu (terraform), you often have to hard code correlated settings for versioning (like app version and chart version). Sometimes it goes even further and you need to fetch a policy or a manifest with some CRDs that the chart will depend on.
-Here is an example of how to manage that with opentofu and an http datasource for the AWS load balancer controller.
+Here is an example of how to manage that with OpenTofu and an http datasource for the AWS load balancer controller.
## A word about the AWS load balancer controller
diff --git a/content/blog/terraform/email-dns-unused-zone.md b/content/blog/terraform/email-dns-unused-zone.md
new file mode 100644
index 0000000..e1f9b81
--- /dev/null
+++ b/content/blog/terraform/email-dns-unused-zone.md
@@ -0,0 +1,104 @@
+---
+title: Email DNS records for zones that do not send emails
+description: Automated with terraform/OpenTofu
+date: 2024-09-03
+tags:
+- cloudflare
+- DNS
+- OpenTofu
+- terraform
+---
+
+## Introduction
+
+There are multiple DNS records one needs to configure in order to setup and securely use a domain to send or receive emails: MX, DKIM, DMARC and SPF.
+
+An often overlooked fact is that you also need to configure some of these records even if you do not intend to use a domain to send emails. If you do not, scammers will spoof your domain to send fraudulent emails and your domain's reputation will suffer.
+
+## DNS email records you need
+
+### SPF
+
+The most important and only required record you need is a TXT record on the apex of your domain that advertises the fact that no server can send emails from your domain:
+```
+"v=spf1 -all"
+```
+
+### MX
+
+If you do not intend to ever send emails, you certainly do not intend to receive emails either. Therefore you should consider removing all MX records on your zone. Oftentimes your registrar will provision some pointing to a free email infrastructure that they provide along with your domain.
+
+### DKIM
+
+You do not need DKIM records if you are not sending emails.
+
+### DMARC
+
+While not strictly necessary, I strongly recommend to set a DMARC record that instructs the world to explicitly reject all emails not matching the SPF policy:
+
+```
+"v=DMARC1;p=reject;sp=reject;pct=100"
+```
+
+## Terraform / OpenTofu code
+
+### Zones
+
+I use a map of simple objects to specify email profiles for my DNS zones:
+``` hcl
+locals {
+ zones = {
+ "adyxax.eu" = { emails = "adyxax" }
+ "adyxax.org" = { emails = "adyxax" }
+ "anne-so-et-julien.fr" = { emails = "no" }
+ }
+}
+
+data "cloudflare_zone" "main" {
+ for_each = local.zones
+
+ name = each.key
+}
+```
+
+### SPF
+
+Then I map each profile to spf records:
+``` hcl
+locals {
+ spf = {
+ "adyxax" = "v=spf1 mx -all"
+ "no" = "v=spf1 -all"
+ }
+}
+
+resource "cloudflare_record" "spf" {
+ for_each = local.zones
+
+ name = "@"
+ type = "TXT"
+ value = local.spf[each.value.emails]
+ zone_id = data.cloudflare_zone.main[each.key].id
+}
+```
+
+### DMARC
+
+The same mapping system we had for spf can be used here too, but I choose to keep things simple and in the scope of this article. My real setup has some clever tricks to make dmarc notifications work centralized to a single domain that will be the subject another post:
+
+``` hcl
+resource "cloudflare_record" "dmarc" {
+ for_each = { for name, info in local.zones :
+ name => info if info.emails == "no"
+ }
+
+ name = "@"
+ type = "TXT"
+ value = "v=DMARC1;p=reject;sp=reject;pct=100"
+ zone_id = data.cloudflare_zone.main[each.key].id
+}
+```
+
+## Conclusion
+
+Please keep your email DNS records tight and secure!
diff --git a/content/blog/terraform/tofu.md b/content/blog/terraform/tofu.md
index 48ec621..b52b97f 100644
--- a/content/blog/terraform/tofu.md
+++ b/content/blog/terraform/tofu.md
@@ -1,20 +1,20 @@
---
-title: Testing opentofu
+title: Testing OpenTofu
description: Little improvements and what it means for small providers like mine
date: 2024-01-31
tags:
- Eventline
-- opentofu
+- OpenTofu
- terraform
---
## Introduction
-This January, the opentofu project announced the general availability of their terraform fork. Not much changes for now between terraform and opentofu (and that is a good thing!), as far as I can tell the announcement was mostly about the new provider registry and of course the truly open source license.
+This January, the OpenTofu project announced the general availability of their terraform fork. Not much changes for now between terraform and OpenTofu (and that is a good thing!), as far as I can tell the announcement was mostly about the new provider registry and of course the truly open source license.
## Registry change
-The opentofu registry already has all the providers you are accustomed to, but your state will need to be migrated with:
+The OpenTofu registry already has all the providers you are accustomed to, but your state will need to be migrated with:
```sh
tofu init -upgrade`
```
@@ -24,19 +24,19 @@ For some providers you might encounter the following warning:
- Installed cloudflare/cloudflare v4.23.0. Signature validation was skipped due to the registry not containing GPG keys for this provider
```
-This is harmless and will resolve itself when the providers' developers provide the public GPG key used to sign their releases to the opentofu registry. The process is very simple thanks to their GitHub workflow automation.
+This is harmless and will resolve itself when the providers' developers provide the public GPG key used to sign their releases to the OpenTofu registry. The process is very simple thanks to their GitHub workflow automation.
## Little improvements
- `tofu init` seems significantly faster than `terraform init`.
-- You never could interrupt a terraform plan with `C-C`. I am so very glad to see that it is not a problem with opentofu! This really needs more advertising: proper Unix signal handling is like a superpower that is too often ignored by modern software.
-- `tofu test` can be used to assert things about your state and your configuration. I did not play with it yet but it opens [a whole new realm of possibilities](https://opentofu.org/docs/cli/commands/test/)!
+- You never could interrupt a terraform plan with `C-C`. I am so very glad to see that it is not a problem with OpenTofu! This really needs more advertising: proper Unix signal handling is like a superpower that is too often ignored by modern software.
+- `tofu test` can be used to assert things about your state and your configuration. I did not play with it yet but it opens [a whole new realm of possibilities](https://OpenTofu.org/docs/cli/commands/test/)!
- `tofu import` can use expressions referencing other values or resources attributes, this is a big deal when handling massive imports!
## Eventline terraform provider
-I did the required pull requests on the [opentofu registry](https://github.com/opentofu/registry) to have my [Eventline provider](https://github.com/adyxax/terraform-provider-eventline) all fixed up and ready to rock!
+I did the required pull requests on the [OpenTofu registry](https://github.com/OpenTofu/registry) to have my [Eventline provider](https://github.com/adyxax/terraform-provider-eventline) all fixed up and ready to rock!
## Conclusion
-I hope opentofu really takes off, the little improvements they made already feel like a breath of fresh air. Terraform could be so much more!
+I hope OpenTofu really takes off, the little improvements they made already feel like a breath of fresh air. Terraform could be so much more!