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

feat: add support environment.yaml files #6569

Merged

Conversation

DmitriyLewen
Copy link
Contributor

Description

Add support for detecting dependencies from environment.yaml files.
We do not have a vulnerability database for conda files, so environment.yaml files will only be scanned for packages (-f json --list-all-pkgs, SBOM formats).

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Apr 26, 2024
@DmitriyLewen DmitriyLewen changed the title feat(conda): add support environment.yaml files feat: add support environment.yaml files Apr 26, 2024
Comment on lines 372 to 380
{
name: "conda environment.yaml generating SPDX SBOM",
args: args{
command: "fs",
format: "spdx-json",
input: "testdata/fixtures/repo/conda-environment",
},
golden: "testdata/conda-environment-spdx.json.golden",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already have an intermediate SBOM representation, I think either CycloneDX or SPDX is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed SPDX in d5b0a56

// Default format for files created using the `conda Export` command: `<Name>=<Version>=<Build>
// e.g. `bzip2=1.0.8=h998d150_5`
// But it is also possible to set only the dependency name
ss := strings.Split(dep.Value, "=")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we have to care about a variety of cases.
https://docs.conda.io/projects/conda-build/en/latest/resources/package-spec.html#package-match-specifications

numpy
numpy 1.8*
numpy 1.8.1
numpy >=1.8
numpy ==1.8.1
numpy 1.8|1.8*
numpy >=1.8,<2
numpy >=1.8,<2|1.9
numpy 1.8.1 py27_0
numpy=1.8.1=py27_0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated logic - 32b7ae2
@knqyf263 I couldn't create the logic without regexp.
But if you have any ideas, please tell me.

})

if tt.wantErr != "" {
require.Error(t, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this line is not needed when using ErrorContains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed - 6fc4535

return res, nil
}
func (a environmentAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return filepath.Base(filePath) == "environment.yaml" || filepath.Base(filePath) == "environment.yml"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should define a const.

// Language-specific file names
const (
NuGetPkgsLock = "packages.lock.json"
NuGetPkgsConfig = "packages.config"
GoMod = "go.mod"
GoSum = "go.sum"
MavenPom = "pom.xml"
NpmPkg = "package.json"
NpmPkgLock = "package-lock.json"
YarnLock = "yarn.lock"
PnpmLock = "pnpm-lock.yaml"
ComposerLock = "composer.lock"
ComposerJson = "composer.json"
PyProject = "pyproject.toml"
PipRequirements = "requirements.txt"
PipfileLock = "Pipfile.lock"
PoetryLock = "poetry.lock"
GemfileLock = "Gemfile.lock"
CargoLock = "Cargo.lock"
CargoToml = "Cargo.toml"
ConanLock = "conan.lock"
CocoaPodsLock = "Podfile.lock"
SwiftResolved = "Package.resolved"
PubSpecLock = "pubspec.lock"
MixLock = "mix.lock"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - a3254f9

@DmitriyLewen DmitriyLewen marked this pull request as ready for review April 27, 2024 08:20
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DmitriyLewen I refactored it a bit so it can parse more cases. Please let me know if it looks wrong.

@knqyf263 knqyf263 added this pull request to the merge queue Apr 29, 2024
Merged via the queue into aquasecurity:main with commit e3bef02 Apr 29, 2024
17 checks passed
@DmitriyLewen
Copy link
Contributor Author

Good solution!
LGTM.

@DmitriyLewen DmitriyLewen deleted the feat-conda/add-support-environment-yaml branch May 2, 2024 03:33
fl0pp5 pushed a commit to altlinux/trivy that referenced this pull request May 6, 2024
@kutkopy
Copy link

kutkopy commented May 6, 2024

Hi @knqyf263 and @DmitriyLewen, I have noticed an issue with the current implementation. In particular pip-dependencies in an environment.yml-file (as show below) are not supported:

name: lib-build-env
channels:
  - conda-forge
  - fastchan
  - pytorch
dependencies:
  - example-conda-lib=1.2.3
  - pip:
      - example-pip-lib==3.2.1

And lead to the following error:

[conda] Unable to detect the dependency versions from `environment.yml` as those versions are not pinned. Use `conda env export` to pin versions.

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

Successfully merging this pull request may close these issues.

feat(conda): detect dependencies from environment.yml
3 participants