Skip to content

Commit

Permalink
Merge pull request #19 from advanced-security/compose
Browse files Browse the repository at this point in the history
Add Compose support
  • Loading branch information
GeekMasher authored Sep 4, 2023
2 parents b5a18e9 + ec60ac1 commit 0fdee58
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Dependency Review"
on:
pull_request:

permissions:
contents: read
pull-requests: write

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v3
- name: "Dependency Review"
uses: actions/dependency-review-action@v3
with:
comment-summary-in-pr: true
56 changes: 56 additions & 0 deletions ql/lib/codeql/iac/compose/Compose.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
private import codeql.iac.YAML
private import codeql.files.FileSystem

/**
* A Compose file node.
*/
private class Node extends YamlNode {
Node() {
this.getFile().getBaseName() =
[
// Compose
"compose.yml", "compose.yaml",
// Docker
"docker-compose.yml", "docker-compose.yaml",
// Podman
"podman-compose.yml", "podman-compose.yaml",
]
}
}

/**
* Docker / Podman Compose file.
*/
class Compose extends Node, YamlDocument, YamlMapping {
/**
* Returns the version of the Compose file.
*/
string getApiVersion() {
result = this.lookup("version").toString().regexpReplaceAll("('|\")", "")
}

/**
* Returns the services defined in the Compose file.
*/
ComposeService getServices() { result = this.lookup("services").getAChildNode() }
}

/**
* A service defined in a Compose file.
*/
class ComposeService extends YamlMapping {
Compose compose;

/**
* Compose Service
*/
ComposeService() { compose.lookup("services").getAChildNode() = this }

/**
* Returns the name of the service.
*/
string getName() {
result = this.lookup("container_name").toString()
// TODO get parent key name
}
}
2 changes: 2 additions & 0 deletions ql/lib/iac.qll
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import codeql.iac.cloudformation.AWSCloudFormation
// Containers / Docker
import codeql.iac.containers.Containers
import codeql.iac.containers.Images
// Compose
import codeql.iac.compose.Compose
// HelmCharts
import codeql.iac.helmcharts.HelmChart
// Terraform / HCL
Expand Down
16 changes: 16 additions & 0 deletions ql/src/Security/Compose/PinnedMajorVersion.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @name Using old version of Compose
* @description Compose files with pinned version
* @kind problem
* @problem.severity note
* @security-severity 1.0
* @precision very-high
* @id iac/containers/latest-images
* @tags maintainability
*/

import iac

from Compose compose
where compose.getApiVersion() = ["2", "3"]
select compose, "pinned version of Compose spec"

0 comments on commit 0fdee58

Please sign in to comment.