Skip to content

Commit

Permalink
Add a yara image. (#2418)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Moore <[email protected]>
  • Loading branch information
mattmoor authored Mar 31, 2024
1 parent 7b875ef commit fd8625d
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 0 deletions.
36 changes: 36 additions & 0 deletions images/yara/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--monopod:start-->
# yara
| | |
| - | - |
| **OCI Reference** | `cgr.dev/chainguard/yara` |


* [View Image in Chainguard Academy](https://edu.chainguard.dev/chainguard/chainguard-images/reference/yara/overview/)
* [View Image Catalog](https://console.enforce.dev/images/catalog) for a full list of available tags.
* [Contact Chainguard](https://www.chainguard.dev/chainguard-images) for enterprise support, SLAs, and access to older tags.*

---
<!--monopod:end-->

<!--overview:start-->
The pattern matching swiss knife.
<!--overview:end-->

<!--getting:start-->
## Download this Image
The image is available on `cgr.dev`:

```
docker pull cgr.dev/chainguard/yara:latest
```
<!--getting:end-->

<!--body:start-->
## Usage

Inspect the crane image manifest using the crane image:

```
docker run --rm cgr.dev/chainguard/crane:latest manifest cgr.dev/chainguard/crane:latest --platform=linux/amd64
```
<!--body:end-->
19 changes: 19 additions & 0 deletions images/yara/config/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_providers {
apko = { source = "chainguard-dev/apko" }
}
}

variable "extra_packages" {
description = "The additional packages to install (e.g. yara)."
default = ["yara"]
}

data "apko_config" "this" {
config_contents = file("${path.module}/template.apko.yaml")
extra_packages = var.extra_packages
}

output "config" {
value = jsonencode(data.apko_config.this.config)
}
15 changes: 15 additions & 0 deletions images/yara/config/template.apko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contents:
packages: []

accounts:
groups:
- groupname: nonroot
gid: 65532
users:
- username: nonroot
uid: 65532
gid: 65532
run-as: 65532

entrypoint:
command: /usr/bin/yara
36 changes: 36 additions & 0 deletions images/yara/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
}
}

variable "target_repository" {
description = "The docker repo into which the image and attestations should be published."
}

module "latest-config" { source = "./config" }

module "latest" {
source = "../../tflib/publisher"
name = basename(path.module)
target_repository = var.target_repository
config = module.latest-config.config
build-dev = true
}

module "test-latest" {
source = "./tests"
digest = module.latest.image_ref
}

resource "oci_tag" "latest" {
depends_on = [module.test-latest]
digest_ref = module.latest.image_ref
tag = "latest"
}

resource "oci_tag" "latest-dev" {
depends_on = [module.test-latest]
digest_ref = module.latest.dev_ref
tag = "latest-dev"
}
13 changes: 13 additions & 0 deletions images/yara/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: yara
image: cgr.dev/chainguard/yara
logo: https://github.com/VirusTotal.png
endoflife: ""
console_summary: ""
short_description: The pattern matching swiss knife.
compatibility_notes: ""
readme_file: README.md
upstream_url: https://github.com/VirusTotal/yara
keywords:
- security
- yara
- malware
21 changes: 21 additions & 0 deletions images/yara/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
}
}

variable "digest" {
description = "The image digest to run tests over."
}

data "oci_exec_test" "version" {
digest = var.digest
script = "docker run --rm $IMAGE_NAME --version"
}

data "oci_exec_test" "test-yar" {
digest = var.digest
script = "./test-yar.sh"

working_dir = path.module
}
6 changes: 6 additions & 0 deletions images/yara/tests/test-yar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o errtrace -o pipefail -x

# Grep checks for the expected output
docker run --rm -v "${PWD}:/work" -w /work "${IMAGE_NAME}" test.yar /usr/bin/yara | grep test_rule | grep /usr/bin/yara
6 changes: 6 additions & 0 deletions images/yara/tests/test.yar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rule test_rule {
strings:
$a = "yr_scanner_create"
condition:
$a
}
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,11 @@ module "wolfi-base" {
target_repository = "${var.target_repository}/wolfi-base"
}

module "yara" {
source = "./images/yara"
target_repository = "${var.target_repository}/yara"
}

module "zig" {
source = "./images/zig"
target_repository = "${var.target_repository}/zig"
Expand Down

0 comments on commit fd8625d

Please sign in to comment.