Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data source to validate image structure #7

Open
imjasonh opened this issue Apr 27, 2023 · 1 comment
Open

data source to validate image structure #7

imjasonh opened this issue Apr 27, 2023 · 1 comment

Comments

@imjasonh
Copy link
Member

Prior art: https://github.com/GoogleContainerTools/container-structure-test

Something like:

data "oci_ref" "image" {
  ref = "alpine"
}

data "oci_validate" "validate" {
  test {
    rule = (oci_ref.image.config.user = "nobody")
  }
  test {
    rule = (contains(oci_ref.image.config.env, "FOO=bar"))
  }
  test {
    file = {
      digest = oci_ref.image.id
      path = "/etc/passwd"
      contains = "nobody"
      not_contains = "my credit card number is:"
      permissions = "-rw-r--r--"
    }
  }
}

resource "google_cloud_run_service" "service" {
  image = oci_validate.validate.validated_ref
}

We can also consider command tests that effectively docker run <image> and inspect the result.

@imjasonh
Copy link
Member Author

imjasonh commented Apr 29, 2023

We (edit: don't) need separate data sources for validating images and indexes.

image is a misnomer though, maybe digest instead?

data "oci_ref" "alpine" {
  ref = "alpine"
}

data "oci_validate" "validate" {
  image = oci_ref.alpine.image_ref
  test {
    rule = keys(oci_ref.alpine.manifests) = ["linux/amd64", "linux/arm64"]
  }
  # TODO: test index annotations and SBOM
}

data "oci_validate" "validate" {
  # test each platform
  for_each = keys(oci_ref.alpine.manifests)
  image = each.value.image_ref

  test {
    path     = "/etc/passwd"
    contains = "nobody"
  }
  # TODO: test image annotations and SBOM
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant