diff --git a/.github/workflows/README.md b/.github/workflows/README.md index da73173118b..6f87d95f193 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -74,13 +74,24 @@ _Action:_ _Recovery:_ Check at the milestone for the related issues and update them manually. +### prune-github-container-registry [πŸ”—](prune-github-container-registry.yaml) + +_Trigger:_ Every week or manually. + +_Action:_ Clean up old lib-injection OCI images from GitHub Container Registry. + +_Recovery:_ Manually trigger the action again. + ## Code Quality and Security -### ci-static-analysis [πŸ”—](ci-static-analysis.yml) +### analyze-changes [πŸ”—](analyze-changes-with-github-codeql.yaml) -_Trigger:_ When pushing commits to `master` or any pull request to `master`. +_Trigger:_ When pushing commits to `master` or any pull request targeting `master`. -_Actions:_ Run [DataDog Static Analysis](https://docs.datadoghq.com/static_analysis/) and upload result to DataDog Code Analysis. +_Action:_ +* Run [DataDog Static Analysis](https://docs.datadoghq.com/static_analysis/) and upload result to DataDog Code Analysis, +* Run [GitHub CodeQL](https://codeql.github.com/) action, upload result to GitHub security tab and DataDog Code Analysis -- do not apply to pull request, only when pushing to `master`, +* Run [Trivy security scanner](https://github.com/aquasecurity/trivy) on built artifacts and upload result to GitHub security tab. ### comment-on-submodule-update [πŸ”—](comment-on-submodule-update.yaml) @@ -88,13 +99,7 @@ _Trigger:_ When creating a PR commits to `master` or a `release/*` branch with a _Action:_ Notify the PR author through comments that about the Git Submodule update. -### codeql-analysis [πŸ”—](codeql-analysis.yml) - -_Trigger:_ When pushing commits to `master`. - -_Action:_ Run GitHub CodeQL action, upload result to GitHub security tab and DataDog Code Analysis. - -### update-gradle-dependencies [πŸ”—](trivy-analysis.yml) +### update-gradle-dependencies [πŸ”—](update-gradle-dependencies.yml) _Trigger:_ Every week or manually. @@ -102,24 +107,13 @@ _Action:_ Create a PR updating the Grade dependencies and their locking files. _Recovery:_ Manually trigger the action again. -### trivy-analysis [πŸ”—](trivy-analysis.yml) -_Trigger:_ When pushing commits to `master` or any pull request to `master`. +## Maintenance -_Action:_ Run Trivy security scanner on built artifacts and upload result to GitHub security tab. +GitHub actions should be part of the [repository allowed actions to run](https://github.com/DataDog/dd-trace-java/settings/actions). +While GitHub owned actions are allowed by default, the other ones must be declared. -### gradle-wrapper-validation [πŸ”—](gradle-wrapper-validation.yaml.disabled) - -**DISABLED** - GitHub provides a way to disable actions rather than changing their extensions. - -_Comment:_ To delete? - -## Lib Injection - -### lib-injection-prune-registry [πŸ”—](lib-injection-prune-registry.yaml) - -_Trigger:_ Every week or manually. - -_Action:_ Clean up old lib-injection Docker images from GHCR. - -_Recovery:_ Manually trigger the action again. +Run the following script to get the list of actions to declare according the state of your working copy: +```bash +find .github/workflows -name "*.yaml" -exec awk '/uses:/{print $2 ","}' {} \; | grep -vE '^(actions|github)/' | sort | uniq +``` diff --git a/.github/workflows/add-milestone-to-pull-requests.yaml b/.github/workflows/add-milestone-to-pull-requests.yaml index 382bdc69a0e..8fc02d252f1 100644 --- a/.github/workflows/add-milestone-to-pull-requests.yaml +++ b/.github/workflows/add-milestone-to-pull-requests.yaml @@ -5,11 +5,12 @@ on: branches: - master - release/v* - jobs: add_milestone_to_merged: - if: github.event.pull_request.merged && github.event.pull_request.milestone == null name: Add milestone to merged pull requests + permissions: + issues: write # Required to update the milestone of a pull request + if: github.event.pull_request.merged && github.event.pull_request.milestone == null runs-on: ubuntu-latest steps: - name: Add milestone to merged pull requests diff --git a/.github/workflows/add-release-to-cloudfoundry.yaml b/.github/workflows/add-release-to-cloudfoundry.yaml index bd8a6e099e0..eedfe1dbd8a 100644 --- a/.github/workflows/add-release-to-cloudfoundry.yaml +++ b/.github/workflows/add-release-to-cloudfoundry.yaml @@ -5,6 +5,8 @@ on: - released jobs: update-releases: + permissions: + contents: write # Required to commit and push changes to the repository runs-on: ubuntu-latest steps: - name: Checkout "cloudfoundry" branch diff --git a/.github/workflows/analyze-changes.yaml b/.github/workflows/analyze-changes.yaml new file mode 100644 index 00000000000..9744a3dbfa6 --- /dev/null +++ b/.github/workflows/analyze-changes.yaml @@ -0,0 +1,133 @@ +name: Analyze changes + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + +jobs: + datadog-static-analyzer: + name: Analyze changes with DataDog Static Analyzer + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # 4.1.6 + with: + submodules: 'recursive' + - name: Check code meets quality standards + id: datadog-static-analysis + uses: DataDog/datadog-static-analyzer-github-action@c74aff158c8cc1c3e285660713bcaa5f9c6d696e # v1 + with: + dd_app_key: ${{ secrets.DD_APP_KEY }} + dd_api_key: ${{ secrets.DD_API_KEY }} + dd_site: datad0g.com + dd_service: "dd-trace-java" + dd_env: "ci" + cpu_count: 2 + enable_performance_statistics: false + + codeql: + name: Analyze changes with GitHub CodeQL + # Don’t run on PR, only when pushing to master + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write # Required to upload the results to the Security tab + + steps: + - name: Checkout repository + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # 4.1.6 + with: + submodules: 'recursive' + - name: Initialize CodeQL + uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + with: + languages: 'java' + build-mode: 'manual' + - name: Build dd-trace-java for creating the CodeQL database + run: | + GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx2G -Xms2G'" \ + JAVA_HOME=$JAVA_HOME_8_X64 \ + JAVA_8_HOME=$JAVA_HOME_8_X64 \ + JAVA_11_HOME=$JAVA_HOME_11_X64 \ + JAVA_17_HOME=$JAVA_HOME_17_X64 \ + JAVA_21_HOME=$JAVA_HOME_21_X64 \ + ./gradlew clean :dd-java-agent:shadowJar \ + --build-cache --parallel --stacktrace --no-daemon --max-workers=4 + - name: Perform CodeQL Analysis and upload results to GitHub Security tab + uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + + - name: Upload results to Datadog CI Static Analysis + run: | + wget --no-verbose https://github.com/DataDog/datadog-ci/releases/download/v2.42.0/datadog-ci_linux-x64 -O datadog-ci + chmod +x datadog-ci + ./datadog-ci sarif upload /home/runner/work/dd-trace-java/results/java.sarif --service dd-trace-java --env ci + env: + DD_API_KEY: ${{ secrets.DD_API_KEY }} + DD_SITE: datad0g.com + + trivy: + name: Analyze changes with Trivy + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write # Required to upload the results to the Security tab + + steps: + - name: Checkout repository + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # 4.1.6 + with: + submodules: 'recursive' + + - name: Remove old artifacts + run: | + MVN_LOCAL_REPO=$(./mvnw help:evaluate -Dexpression=settings.localRepository -q -DforceStdout) + echo "MVN_LOCAL_REPO=${MVN_LOCAL_REPO}" >> "$GITHUB_ENV" + rm -rf "${MVN_LOCAL_REPO}/com/datadoghq" + + - name: Build and publish artifacts locally + run: | + GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx2G -Xms2G'" \ + JAVA_HOME=$JAVA_HOME_8_X64 \ + JAVA_8_HOME=$JAVA_HOME_8_X64 \ + JAVA_11_HOME=$JAVA_HOME_11_X64 \ + JAVA_17_HOME=$JAVA_HOME_17_X64 \ + JAVA_21_HOME=$JAVA_HOME_21_X64 \ + ./gradlew clean publishToMavenLocal \ + --build-cache --parallel --stacktrace --no-daemon --max-workers=4 + + - name: Copy published artifacts + run: | + mkdir -p ./workspace/.trivy + cp -RP "${MVN_LOCAL_REPO}/com/datadoghq" ./workspace/.trivy/ + ls -laR "./workspace/.trivy" + + - name: Run Trivy security scanner + uses: aquasecurity/trivy-action@6e7b7d1fd3e4fef0c5fa8cce1229c54b2c9bd0d8 # v0.24.0 + with: + scan-type: rootfs + scan-ref: './workspace/.trivy/' + format: 'sarif' + output: 'trivy-results.sarif' + severity: 'CRITICAL,HIGH' + limit-severities-for-sarif: true + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + if: always() + with: + sarif_file: 'trivy-results.sarif' + + - name: Upload results to Datadog CI Static Analysis + run: | + wget --no-verbose https://github.com/DataDog/datadog-ci/releases/download/v2.42.0/datadog-ci_linux-x64 -O datadog-ci + chmod +x datadog-ci + ./datadog-ci sarif upload trivy-results.sarif --service dd-trace-java --env ci + env: + DD_API_KEY: ${{ secrets.DD_API_KEY }} + DD_SITE: datad0g.com diff --git a/.github/workflows/ci-static-analysis.yml b/.github/workflows/ci-static-analysis.yml deleted file mode 100644 index f0e86449fbb..00000000000 --- a/.github/workflows/ci-static-analysis.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: "DataDog CI Static Analysis" -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] -jobs: - check-quality: - runs-on: ubuntu-latest - name: Datadog Static Analyzer - steps: - - name: Checkout repository - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4 - - name: Check code meets quality standards - id: datadog-static-analysis - uses: DataDog/datadog-static-analyzer-github-action@v1 - with: - dd_app_key: ${{ secrets.DD_APP_KEY }} - dd_api_key: ${{ secrets.DD_API_KEY }} - dd_site: datad0g.com - dd_service: "dd-trace-java" - dd_env: "ci" - cpu_count: 2 - enable_performance_statistics: false diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index dcfc2df8f60..00000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ master ] - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - - steps: - - name: Checkout repository - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@1a927e9307bc11970b2c679922ebc4d03a5bd980 # 1.0.31 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - name: Build dd-trace-java for creating the CodeQL database - run: JAVA_HOME=$JAVA_HOME_8_X64 JAVA_8_HOME=$JAVA_HOME_8_X64 JAVA_11_HOME=$JAVA_HOME_11_X64 JAVA_17_HOME=$JAVA_HOME_17_X64 JAVA_21_HOME=$JAVA_HOME_21_X64 ./gradlew clean :dd-java-agent:shadowJar --build-cache --parallel --stacktrace --no-daemon --max-workers=8 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@1a927e9307bc11970b2c679922ebc4d03a5bd980 # 1.0.31 - - - name: upload_artifact - uses: actions/upload-artifact@82c141cc518b40d92cc801eee768e7aafc9c2fa2 # 2.3.1 - with: - name: CodeQL Analysis Sarif - path: /home/runner/work/dd-trace-java/results/java.sarif - - - name: upload to DD CI Static Analysis - run: | - wget --no-verbose https://github.com/DataDog/datadog-ci/releases/download/v2.27.0/datadog-ci_linux-x64 -O datadog-ci - chmod +x datadog-ci - ./datadog-ci sarif upload /home/runner/work/dd-trace-java/results/java.sarif --service dd-trace-java --env ci - env: - DD_API_KEY: ${{ secrets.DD_API_KEY }} - DD_SITE: datad0g.com diff --git a/.github/workflows/comment-on-submodule-update.yaml b/.github/workflows/comment-on-submodule-update.yaml index df60b2044b0..4983bf27dbe 100644 --- a/.github/workflows/comment-on-submodule-update.yaml +++ b/.github/workflows/comment-on-submodule-update.yaml @@ -10,11 +10,13 @@ on: jobs: comment_on_submodule_update: + permissions: + issues: write # Required to create a comment on the pull request runs-on: ubuntu-latest steps: - name: Post comment on submodule update - uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # 6.3.3 + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | diff --git a/.github/workflows/create-next-milestone.yaml b/.github/workflows/create-next-milestone.yaml index 564d38e6e16..b444de77698 100644 --- a/.github/workflows/create-next-milestone.yaml +++ b/.github/workflows/create-next-milestone.yaml @@ -5,15 +5,17 @@ on: jobs: create_next_milestone: + permissions: + issues: write # Required to create a milestone runs-on: ubuntu-latest steps: - name: Get next minor version id: semvers - uses: WyriHaximus/github-action-next-semvers@33d116a4c239252582a60a1ba8dbba63ad493ffd # 1.1.0 + uses: WyriHaximus/github-action-next-semvers@18aa9ed4152808ab99b88d71f5481e41f8d89930 # 1.2.1 with: version: ${{ github.event.milestone.title }} - name: Create next milestone - uses: WyriHaximus/github-action-create-milestone@b86699ba7511fa3b61154ac8675d86b01938fc16 # 1.0.0 + uses: WyriHaximus/github-action-create-milestone@bb0276ee386c630b476fa3ca788457bf3daa7c2e # 1.1.1 with: title: ${{ steps.semvers.outputs.minor }} env: diff --git a/.github/workflows/draft-release-notes-on-tag.yaml b/.github/workflows/draft-release-notes-on-tag.yaml index 7b08eb63dce..a0fe798be5f 100644 --- a/.github/workflows/draft-release-notes-on-tag.yaml +++ b/.github/workflows/draft-release-notes-on-tag.yaml @@ -6,12 +6,14 @@ on: jobs: draft_release_notes: name: Draft release notes + permissions: + contents: write # Required to create a release if: (github.event.ref_type == 'tag' && github.event.master_branch == 'master') || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - name: Get milestone title id: milestoneTitle - uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # 6.4.1 + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1 with: result-encoding: string script: | diff --git a/.github/workflows/gradle-wrapper-validation.yaml.disabled b/.github/workflows/gradle-wrapper-validation.yaml.disabled deleted file mode 100644 index 52bf278293f..00000000000 --- a/.github/workflows/gradle-wrapper-validation.yaml.disabled +++ /dev/null @@ -1,11 +0,0 @@ -name: "Validate Gradle Wrapper" -on: [push, pull_request] - -jobs: - validation: - name: "Gradle wrapper validation" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4 - # When updating this, you need to ADD the new version to https://github.com/DataDog/dd-trace-java/settings/actions - - uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b # 1.0.4 diff --git a/.github/workflows/lib-injection-prune-registry.yaml b/.github/workflows/lib-injection-prune-registry.yaml deleted file mode 100644 index 72bc5d70a2b..00000000000 --- a/.github/workflows/lib-injection-prune-registry.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: Prune Lib Injection images -on: - schedule: - - cron: '15 3 * * *' - workflow_dispatch: - -jobs: - prune-init-images: - name: Prune dd-lib-java-init docker images - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Prune registry - uses: vlaurin/action-ghcr-prune@0a539594d122b915e71c59733a5b115bfaaf5d52 #v0.5.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - organization: Datadog - container: dd-trace-java/dd-lib-java-init - keep-younger-than: 7 # days - keep-last: 10 - keep-tags: | - latest_snapshot - prune-tags-regexes: | - ^[a-z0-9]{40}$ - prune-untagged: true - - prune-init-test-app-images: - name: Prune dd-lib-java-init-test-app docker images - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Prune registry - uses: vlaurin/action-ghcr-prune@0a539594d122b915e71c59733a5b115bfaaf5d52 #v0.5.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - organization: Datadog - container: dd-trace-java/dd-lib-java-init-test-app - keep-younger-than: 15 # days - keep-last: 5 - keep-tags: | - latest_snapshot - prune-tags-regexes: | - ^[a-z0-9]{40}$ - prune-untagged: true diff --git a/.github/workflows/prune-github-container-registry.yaml b/.github/workflows/prune-github-container-registry.yaml new file mode 100644 index 00000000000..ceb56b4e49b --- /dev/null +++ b/.github/workflows/prune-github-container-registry.yaml @@ -0,0 +1,27 @@ +name: Prune GitHub Container Registry +on: + schedule: + - cron: '15 3 * * *' + workflow_dispatch: + +jobs: + prune-init-images: + name: Prune dd-lib-java-init OCI images + runs-on: ubuntu-latest + permissions: + contents: read + packages: write # Required to delete images + steps: + - name: Prune registry + uses: vlaurin/action-ghcr-prune@0cf7d39f88546edd31965acba78cdcb0be14d641 #v0.6.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + organization: Datadog + container: dd-trace-java/dd-lib-java-init + keep-younger-than: 7 # days + keep-last: 10 + keep-tags: | + latest_snapshot + prune-tags-regexes: | + ^[a-z0-9]{40}$ + prune-untagged: true diff --git a/.github/workflows/trivy-analysis.yml b/.github/workflows/trivy-analysis.yml deleted file mode 100644 index c14ccd9b607..00000000000 --- a/.github/workflows/trivy-analysis.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: "Trivy Security Analysis" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - -permissions: - contents: read - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - steps: - - name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # 3.6.0 - - - name: Remove old artifacts - run: | - MVN_LOCAL_REPO=$(./mvnw help:evaluate -Dexpression=settings.localRepository -q -DforceStdout) - echo "MVN_LOCAL_REPO=${MVN_LOCAL_REPO}" >> "$GITHUB_ENV" - rm -rf "${MVN_LOCAL_REPO}/com/datadoghq" - - - name: Build and publish artifacts locally - run: | - GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx2G -Xms2G'" JAVA_HOME=$JAVA_HOME_8_X64 JAVA_8_HOME=$JAVA_HOME_8_X64 JAVA_11_HOME=$JAVA_HOME_11_X64 JAVA_17_HOME=$JAVA_HOME_17_X64 JAVA_21_HOME=$JAVA_HOME_21_X64 ./gradlew clean publishToMavenLocal --build-cache --parallel --stacktrace --no-daemon --max-workers=4 - - - name: Copy published artifacts - run: | - mkdir -p ./workspace/.trivy - cp -RP "${MVN_LOCAL_REPO}/com/datadoghq" ./workspace/.trivy/ - - - name: List copied artifacts - run: | - ls -laR "./workspace/.trivy" - - - name: Run Trivy security scanner - uses: aquasecurity/trivy-action@41f05d9ecffa2ed3f1580af306000f734b733e54 # v0.11.2 - with: - scan-type: rootfs - scan-ref: './workspace/.trivy/' - format: 'sarif' - output: 'trivy-results.sarif' - severity: 'CRITICAL,HIGH' - limit-severities-for-sarif: true - - - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # 2.15 - if: always() - with: - sarif_file: 'trivy-results.sarif' diff --git a/.github/workflows/update-download-releases.yaml b/.github/workflows/update-download-releases.yaml index fbef50dd87a..cf9b2a11cb9 100644 --- a/.github/workflows/update-download-releases.yaml +++ b/.github/workflows/update-download-releases.yaml @@ -6,6 +6,8 @@ on: workflow_dispatch: jobs: update-releases: + permissions: + contents: write # Required to update releases content runs-on: ubuntu-latest steps: - name: Update download releases diff --git a/.github/workflows/update-gradle-dependencies.yaml b/.github/workflows/update-gradle-dependencies.yaml index 8e149c2e1e5..b0ec1bf6cc3 100644 --- a/.github/workflows/update-gradle-dependencies.yaml +++ b/.github/workflows/update-gradle-dependencies.yaml @@ -9,10 +9,8 @@ jobs: runs-on: ubuntu-latest name: Update Gradle dependencies permissions: - # Commit and push changes to a new branch - contents: write - # Create a pull request - pull-requests: write + contents: write # Required to commit and push changes to a new branch + pull-requests: write # Required to create a pull request steps: - name: Checkout repository uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # 4.1.6 diff --git a/.github/workflows/update-issues-on-release.yaml b/.github/workflows/update-issues-on-release.yaml index 2cf103ee62a..3c223d9056e 100644 --- a/.github/workflows/update-issues-on-release.yaml +++ b/.github/workflows/update-issues-on-release.yaml @@ -10,6 +10,8 @@ on: jobs: update_issues: + permissions: + issues: write # Required to update issues runs-on: ubuntu-latest steps: - name: Get milestone for release