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

Add Dependency Analysis Action and Dockerfile #1095

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/publish-dependency-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Dependency Analysis Docker image

on:
push:
branches:
- main
tags:
- 'v*'

env:
REGISTRY: ghcr.io
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
Copy link
Contributor

Choose a reason for hiding this comment

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

uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-dependency-analysis

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
file: ./Dependency-analysis.dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
35 changes: 35 additions & 0 deletions Dependency-analysis.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2023 Security Scorecard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Testing: docker run -e GITHUB_REPOSITORY_OWNER=naveensrinivasan \
# -e GITHUB_REPOSITORY=scorecard-action \
# -e GITHUB_SHA=3fd6b13799a3e63276d0913fefa90c0e9ca32e31 \
# -e GITHUB_TOKEN=GH_TOKEN \
# -e GITHUB_PR_NUMBER=9 \

#v1.19 go
FROM golang:1.19.5@sha256:bb9811fad43a7d6fd2173248d8331b2dcf5ac9af20976b1937ecd214c5b8c383 AS builder
WORKDIR /
ENV CGO_ENABLED=0
COPY go.mod go.sum ./
COPY dependency-analysis/*.go /

FROM builder AS build
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /dependency-analysis /

FROM gcr.io/distroless/base@sha256:122585ba4c098993df9f8dc7285433e8a19974de32528ee3a4b07308808c84ce
COPY --from=build /dependency-analysis /dependency-analysis
ENTRYPOINT ["/dependency-analysis"]
58 changes: 58 additions & 0 deletions dependency-analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# OpenSSF Scorecard Dependency Analysis

This repository contains the source code for the OpenSSF Dependency Analysis project. The aim of the project is to check the security posture of a project's dependencies using the [GitHub Dependency Graph API](https://docs.github.com/en/rest/dependency-graph/dependency-review?apiVersion=2022-11-28#get-a-diff-of-the-dependencies-between-commits) and the [Security Scorecards API](https://api.securityscorecards.dev).

## Usage
The OpenSSF Dependency Analysis is a GitHub Action that can be easily incorporated into a workflow.
The workflow can be triggered on a pull request event.
The action will run on the latest commit on the default branch of the repository, and will create a comment on the pull request with the results of the analysis.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe clarify what this means. Default branch of which repo?

An example of the comment can be found [here](https://github.com/ossf-tests/vulpy/pull/2#issuecomment-1442310469).
Copy link
Contributor

Choose a reason for hiding this comment

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

are we showing the aggregate score in the summary for each result? Do users need to click to see it?
Are we creating a new comment for each run?

Copy link
Member Author

Choose a reason for hiding this comment

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

are we showing the aggregate score in the summary for each result

We aren't showing aggregate score. Do you think we should show the aggregate score?

Are we creating a new comment for each run?

We will not create results for reach run. Only if the user manually runs it only then we create another comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

so we run it once for the first commit, and then only if the user asks to run?
Maybe add to the comment description to explain to users that they can re-run to update?


## Prerequisites
The actions require enabling the [GitHub Dependency Review](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review) for the repository.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really true? For go projects, unlikely. For other projects, is it? We don't need an exact dependency tag, so it should not be needed. Does GitHub API return dependency name / repo without enabling this feature?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this really true? For go projects, unlikely. For other projects, is it? We don't need an exact dependency tag, so it should not be needed. Does GitHub API return dependency name / repo without enabling this feature?

I have tested for go projects and here is python package https://github.com/ossf-tests/vulpy/pull/2/files. For teh GH API to return results it needs this feature to be tuned on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very interesting... and unexpected to me


### Configuration
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
The action can be configured using the following inputs:

- `SCORECARD_CHECKS`: This environment variable takes a file containing a list of checks to run.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need JSON format? I could imagine a single Action input that takes a comma-separated list check1, check2, check3. Action inputs are the standard way to pass parameters into Action, no?

Do you anticipate more complicated structure needed in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can give users the option to exclude certain repositories or checks for a particular repo, which we can make possible with the file option.

This will also give us the ability to extend the feature in the future. That's the idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a config file in this case then. Standard way to pass parameters to an Action is not env variables. It's inputs.

- The file should be in JSON format and follow the format provided by the [Scorecard checks documentation](https://github.com/ossf/scorecard/blob/main/docs/checks.md). For example:
```json
[
"Binary-Artifacts",
"Pinned-Dependencies"
]
```

### Installation
The action can be installed by adding the following snippet to the workflow file:
```yaml
name: scorecard-dependency-analysis

on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
pull-requests: write # Required to create a comment on the pull request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need at least contents: read for private repos?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't tested with a private repo. I will test it and update it.


jobs:
dependency-analysis:
name: Scorecards dependency analysis
runs-on: ubuntu-latest
env:
GITHUB_PR_NUMBER: ${{ github.event.number }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need these env variables declared by a user?
Except for the GITHUB_TOKEN, the other env variables should be available to the Action, like we do with the existing Action?

Copy link
Member Author

Choose a reason for hiding this comment

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

${{ github.event.number }} isn't directly accessible within the GH action.

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_ACTOR: ${{ github.actor }}


steps:
- name: Checkout code
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Run dependency analysis
uses: ossf/scorecard-action/dependency-analysis@main # Replace with the latest release version.
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
```
23 changes: 23 additions & 0 deletions dependency-analysis/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Security Scorecard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Action syntax: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions.

name: "OSSF Scorecard dependency analysis"
description: "Run OSSF Scorecard dependency analysis on your repository to get quality metrics on your dependencies."
author: "OSSF - github.com/ossf/scorecard"

runs:
using: "docker"
image: "docker://ghcr.io/ossf/scorecard-action-dependency-analysis:latest"
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved