diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml new file mode 100644 index 0000000..8efdaff --- /dev/null +++ b/.github/workflows/lint-test.yml @@ -0,0 +1,17 @@ +name: lint +on: + push: +jobs: + run: + permissions: + contents: read + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.5.7 + + - name: lint + run: terraform fmt **/*.tf diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml new file mode 100644 index 0000000..4958b15 --- /dev/null +++ b/.github/workflows/validate-renovate.yml @@ -0,0 +1,21 @@ +name: validate renovate.json + +on: + pull_request: + +env: + LOG_LEVEL: debug + +jobs: + renovate-config-validator: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4 + with: + node-version: 20 + + - run: npx -p renovate renovate-config-validator renovate.json diff --git a/Dockerfile b/Dockerfile index eb5bc55..026a38c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -FROM debian:buster as builder +FROM debian:bookworm as builder ARG DEBIAN_FRONTEND=noninteractive -ARG VAULT_VERSION=1.12.3 +# renovate: datasource=github-releases depName=hashicorp-vault-cli packageName=hashicorp/vault +ARG VAULT_VERSION=1.18.3 RUN apt-get update && apt-get install -y wget unzip RUN wget -q https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip RUN unzip vault_${VAULT_VERSION}_linux_amd64.zip diff --git a/example/README.md b/example/README.md deleted file mode 100644 index ab87c3a..0000000 --- a/example/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Full example - -This example - -- Creates a Vault server in a GCP project, deployed using Cloud Run -- Creates a GCS bucket with a GSA in the same GCP project that can CRUD objects on the bucket -- Configures the [GCP secret engine](https://developer.hashicorp.com/vault/docs/secrets/gcp) on the Vault server -- Configures Vault so it can create service account keys for the GSA. The GSA keys have a [default ttl of 5m, and max ttl of 30d](https://github.com/joecorall/serverless-vault-with-cloud-run/blob/23e0bb6a0d378eb1612cdf8452137ce75f5fb6e6/example/main.tf#L93-L94). After their TTL they will be deleted from Google by Vault - -In order to both create the vault server and then apply policies to it, we need to run the terraform in two stages: - -1. Create Vault server -2. Apply policies on the Vault server - -In between those two stages we need to define an environment variable `VAULT_TOKEN` so terraform can authenticate to our new Vault server in order to be able to create the policies. - -This can be accomplished by running [tf.sh](./tf.sh) - -``` -git clone https://github.com/joecorall/serverless-vault-with-cloud-run.git -cd serverless-vault-with-cloud-run/example -export TF_VAR_project=YOUR-GCP-PROJECT-ID -export TF_VAR_region=us-east5 -./tf.sh ${TF_VAR_project} -``` diff --git a/example/github.tf b/example/github.tf deleted file mode 100644 index 92cdb19..0000000 --- a/example/github.tf +++ /dev/null @@ -1,35 +0,0 @@ -# Allow GitHub actions to get a GSA key from Vault - -locals { - github_org = "joecorall" - github_vault_project = "serverless-vault-with-cloud-run" -} - -resource "vault_policy" "bucket-writer" { - name = "bucket-writer" - - policy = < /dev/null 2>&1 -base64 -d root-token.enc > root-token.dc -gcloud kms decrypt --key=vault --keyring=vault-server --location=global \ - --project=${TF_VAR_project} \ - --ciphertext-file=root-token.dc \ - --plaintext-file=root-token -export VAULT_TOKEN=$(cat root-token) -rm root-token root-token.enc root-token.dc - -# Now we can apply all of the terraform with a valid Vault token -terraform apply diff --git a/main.tf b/main.tf index 0f2b65a..e3f5f41 100644 --- a/main.tf +++ b/main.tf @@ -6,14 +6,14 @@ terraform { } google = { source = "hashicorp/google" - version = ">= 4.54.0" + version = "= 6.15.0" } } } locals { image_name = format("%s-docker.pkg.dev/%s/%s/vault-server:latest", var.country, var.project, var.repository) - kms_key = "vault" + kms_key = "vault" } ## Create the GSA the Vault CloudRun deployment will run as @@ -51,7 +51,7 @@ resource "google_artifact_registry_repository" "private" { data "google_artifact_registry_repository" "my-repo" { location = var.country - repository_id = var.create_repository ? google_artifact_registry_repository.private[0].id : var.repository + repository_id = var.repository } # docker build vault server image @@ -76,8 +76,8 @@ resource "docker_registry_image" "vault" { ## Create KMS keys resource "google_kms_key_ring" "vault-server" { - name = "vault-server" - location = "global" + name = "vault-server" + location = "global" } resource "google_kms_crypto_key" "key" { @@ -161,7 +161,7 @@ resource "google_cloud_run_v2_job" "vault-init" { service_account = google_service_account.gsa.email containers { name = "vault-init" - image = "jcorall/vault-init:0.3.0" + image = var.init_image env { name = "GOOGLE_PROJECT" diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..328332e --- /dev/null +++ b/renovate.json @@ -0,0 +1,34 @@ +{ + "extends": [ + "config:best-practices", + ":rebaseStalePrs", + "customManagers:dockerfileVersions" + ], + "enabledManagers": [ + "custom.regex", + "dockerfile", + "github-actions", + "terraform" + ], + "customManagers": [ + { + "customType": "regex", + "description": "Update _VERSION variables in Dockerfiles", + "fileMatch": [ + "(^|/|\\.)Dockerfile$", + "(^|/)Dockerfile\\.[^/]*$" + ], + "matchStrings": [ + "# renovate: datasource=(?[a-z-]+?) depName=(?.+?) packageName=(?.+?)(?: versioning=(?[a-z-]+?))?\\s(?:ENV|ARG) .+?_VERSION=(?.+?)(\\s|$)" + ] + } + ], + "labels": [ + "dependencies" + ], + "osvVulnerabilityAlerts": true, + "dependencyDashboardOSVVulnerabilitySummary": "unresolved", + "vulnerabilityAlerts": { + "enabled": true + } +} diff --git a/variables.tf b/variables.tf index 2e110ff..319eb59 100644 --- a/variables.tf +++ b/variables.tf @@ -15,6 +15,10 @@ variable "repository" { default = "private" } +variable "init_image" { + type = string +} + variable "create_repository" { type = bool description = "Whether or not the AR repo needs to be created by this terraform"