├── .github └── workflows │ ├── build.yml │ └── codeql-analysis.yml ├── .gitignore ├── LICENSE ├── README.md ├── azure-pipelines.yml ├── buildAndReleaseTask ├── .eslintrc.json ├── index.ts ├── package-lock.json ├── package.json ├── task.json ├── tsconfig.json └── writeprovenance.ts ├── examples └── build.provenance ├── images └── extension-icon.png ├── renovate.json └── vss-extension.json /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | env: 4 | NODE_VERSION: 16 5 | 6 | on: 7 | push: 8 | branches: 9 | - main 10 | pull_request: 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 17 | 18 | - name: Set up Node.js ${{ env.NODE_VERSION }} 19 | uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 20 | with: 21 | node-version: ${{ env.NODE_VERSION }} 22 | cache: "npm" 23 | cache-dependency-path: buildAndReleaseTask/package-lock.json 24 | 25 | - name: Install packages 26 | run: npm ci 27 | working-directory: buildAndReleaseTask 28 | 29 | - name: Run lint 30 | run: npm run lint 31 | working-directory: buildAndReleaseTask 32 | 33 | - name: Run build 34 | run: npm run build 35 | working-directory: buildAndReleaseTask 36 | 37 | - name: Run smoke test 38 | # This is a very basic smoke test that imitates the env that an agent runs in 39 | working-directory: buildAndReleaseTask 40 | env: 41 | BUILD_BUILDID: 001 42 | BUILD_DEFINITIONNAME: Azure DevOps Demo CI 43 | BUILD_REPOSITORY_PROVIDER: Git 44 | BUILD_REPOSITORY_URI: https://github.com/slsa-framework/azure-devops-demo 45 | BUILD_SOURCEVERSION: dfcb922ec99fb35bbe408926ce2a745bf922f09b 46 | INPUT_ARTIFACTPATH: ../images 47 | SYSTEM_TEAMFOUNDATIONCOLLECTIONURI: https://github.com/slsa-framework/ 48 | SYSTEM_TEAMPROJECT: azure-devops-demo 49 | run: node index.js 50 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "main" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "main" ] 20 | schedule: 21 | - cron: '30 0 * * 2' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # node modules 2 | node_modules/ 3 | 4 | # compiled ado extension js code 5 | *.js 6 | *.vsix 7 | .taskkey 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SLSA Azure DevOps Demo 2 | 3 | A proof-of-concept SLSA provenance generator for Azure DevOps Pipelines. 4 | 5 | ## Background 6 | 7 | [SLSA](https://github.com/slsa-framework/slsa) is a framework intended to codify and promote secure software supply-chain practices. SLSA helps trace software artifacts (e.g. binaries) back to the build and source control systems that produced them using in-toto's [Attestation](https://github.com/in-toto/attestation/blob/main/spec/README.md) metadata format. 8 | 9 | ## Description 10 | 11 | This proof-of-concept Azure DevOps Pipeline Extension demonstrates an initial SLSA integration conformant with SLSA Level 1. This provenance can be uploaded to the native artifact store or to any other artifact repository. 12 | 13 | While there are no integrity guarantees on the produced provenance at L1, publishing artifact provenance in a common format opens up opportunities for automated analysis and auditing. Additionally, moving build definitions into source control and onto well-supported, secure build systems represents a marked improvement from the ecosystem's current state. 14 | 15 | ### Security and Support 16 | 17 | This is demo repo and is not intended to be used in production contexts. As such, we cannot make any commitments of future support. 18 | 19 | ### YAML Pipeline Example 20 | 21 | Below is sample YAML to insert into your build or release pipeline. 22 | 23 | ``` 24 | steps: 25 | - task: gattjoe.SLSAProvenanceGenerator.custom-build-release-task.SLSAProvenanceGenerator@0 26 | displayName: 'SLSA Provenance Generator' 27 | inputs: 28 | artifactPath: dist 29 | ``` 30 | 31 | ### Results 32 | 33 | The provenance is generated and output to stdout for the task. Additionally, Azure DevOps will publish an immutable artifact titled "build.provenance". 34 | 35 | ### Agent Requirements 36 | 37 | The extension has been updated to use Node 16. As a consequence, the minimum agent version supported is 2.206.1 per [this](https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/migrateNode16.md) guidance. -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Starter pipeline 2 | # Start with a minimal pipeline that you can customize to build and deploy your code. 3 | # Add steps that build, run tests, deploy, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | - main 8 | 9 | pool: 10 | vmImage: ubuntu-latest 11 | 12 | steps: 13 | # traditionally you would build your code here and generate an artifact 14 | - script: echo "onion, tomato, jalapeno, cilantro, lime, salt" > salsa.txt 15 | displayName: Build artifact 16 | 17 | # TODO: Move the task to the slsa-framework project. 18 | - task: gattjoe.SLSAProvenanceGenerator.custom-build-release-task.SLSAProvenanceGenerator@0 19 | displayName: Generate provenance 20 | inputs: 21 | artifactPath: salsa.txt -------------------------------------------------------------------------------- /buildAndReleaseTask/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es2021": true 6 | }, 7 | "extends": [ 8 | "eslint:recommended", 9 | "plugin:@typescript-eslint/recommended", 10 | "plugin:security/recommended" 11 | ], 12 | "parser": "@typescript-eslint/parser", 13 | "parserOptions": { 14 | "ecmaVersion": 12 15 | }, 16 | "plugins": [ 17 | "@typescript-eslint", 18 | "@microsoft/sdl", 19 | "node", 20 | "security" 21 | ], 22 | "rules": { 23 | "@microsoft/sdl/no-unsafe-alloc": "error", 24 | "node/no-deprecated-api": "error" 25 | } 26 | } -------------------------------------------------------------------------------- /buildAndReleaseTask/index.ts: -------------------------------------------------------------------------------- 1 | import tl = require('azure-pipelines-task-lib'); 2 | import * as wp from './writeprovenance'; 3 | import * as crypto from 'crypto'; 4 | import * as fs from 'fs'; 5 | import * as path from 'path'; 6 | 7 | // Array for storing list of artifacts to hash 8 | let arrayOfFiles: Array; 9 | // Create dictionary type for artifact and digest to be used to populate the subject 10 | const subjectData = new Map(); 11 | 12 | /** 13 | * Get Agent.TempDirectory which is a temp folder that is cleaned after each pipeline job. 14 | * This is where we will store the build.provenance output file. 15 | */ 16 | const tempPath: string = tl.getVariable('Agent.TempDirectory'); 17 | 18 | 19 | async function run() { 20 | try { 21 | tl.setResourcePath(path.join(__dirname, 'task.json')); 22 | 23 | // Get path to artifact 24 | const artifactPath: string = tl.getInput('artifactPath', true)!; // eslint-disable-line @typescript-eslint/no-non-null-assertion 25 | 26 | // ADO documentation on pre-defined variables for Azure Pipelines 27 | // https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables 28 | // https://docs.microsoft.com/en-us/azure/devops/pipelines/process/run-number 29 | const buildId: string = tl.getVariable('Build.BuildId'); 30 | const buildDefinitionName: string = tl.getVariable('Build.DefinitionName'); 31 | const buildSourceVersion: string = tl.getVariable('Build.SourceVersion'); 32 | const buildRepositoryProvider: string = tl.getVariable('Build.Repository.Provider'); 33 | const buildRepositoryUri: string = tl.getVariable('Build.Repository.Uri'); 34 | const teamFoundationCollectionUri: string = tl.getVariable('System.TeamFoundationCollectionUri'); 35 | const teamProject: string = tl.getVariable('System.TeamProject'); 36 | 37 | // Determine the SPDX Download Location 38 | // https://spdx.github.io/spdx-spec/3-package-information/#37-package-download-location 39 | let vcsType = ''; 40 | 41 | if (buildRepositoryProvider === 'Git' || buildRepositoryProvider === 'GitHub' || buildRepositoryProvider === 'TfsGit') { 42 | vcsType = 'git+https'; 43 | } else if (buildRepositoryProvider === 'TfsVersionControl') { 44 | vcsType = 'tfvc+https'; 45 | } else if (buildRepositoryProvider === 'Svn') { 46 | vcsType = 'svn+https'; 47 | } 48 | else { 49 | // 50 | tl.setResult(tl.TaskResult.Skipped, (`${buildRepositoryUri}: VCS type unknown, expecting: git, svn, or tfvc.`)); 51 | } 52 | 53 | 54 | // Prepare the artifact data 55 | const artifactSubjectData: Map = await prepareSubjectData(artifactPath); 56 | 57 | const foo: Array = await wp.writeArtifactData(artifactSubjectData); 58 | 59 | const builderId = (`${teamFoundationCollectionUri}${teamProject}/Attestations`); 60 | const buildInvocationId = (`${teamFoundationCollectionUri}${teamProject}/_build/${buildId}`); 61 | const materialsUri = (`${vcsType}+${buildRepositoryUri}`); 62 | const createJson: string = await wp.writeArtifactJson(foo, builderId, buildInvocationId, materialsUri, buildSourceVersion, buildDefinitionName); 63 | console.log(createJson); 64 | 65 | try { 66 | /* eslint-disable-next-line security/detect-non-literal-fs-filename -- Safe as no value holds user input */ 67 | fs.writeFile(path.join(tempPath + '/build.provenance'), createJson, (err) => { 68 | if (!err) { 69 | console.log('done'); 70 | } 71 | }); 72 | } catch (err) { 73 | if (err instanceof Error) { 74 | tl.setResult(tl.TaskResult.Failed, err.message); 75 | } else { 76 | console.log('Unexpected error', err); 77 | } 78 | return; 79 | } 80 | 81 | console.log('##vso[artifact.upload containerfolder=SLSALevel1;artifactname=build.provenance]' + (path.join(tempPath + '/build.provenance'))); 82 | 83 | tl.setResult(tl.TaskResult.Succeeded, "Job succeeded.", true) 84 | 85 | } 86 | catch (err) { 87 | 88 | if (err instanceof Error) { 89 | tl.setResult(tl.TaskResult.Failed, err.message); 90 | } else { 91 | console.log('Unexpected error', err); 92 | } 93 | return; 94 | } 95 | } 96 | 97 | /* 98 | * Prepare artifact data by creating a key/value dictionary of artifact name and sha256 digest. 99 | * @artifactPath: User supplied input 100 | */ 101 | async function prepareSubjectData(artifactPath: string): Promise> { 102 | 103 | let subject = new Map(); 104 | 105 | try { 106 | // Validate artifactPath exists 107 | if (tl.exist(artifactPath)) { 108 | // Check to see if the artifactPath is a file 109 | const file: boolean = await is_file(artifactPath); 110 | if (file) { 111 | // This is where i will call out to the functionality 112 | // that will itemize and hash the file 113 | tl.debug('prepareSubjectData: ' + `${artifactPath}` + ' is a single artifact.'); 114 | 115 | subject = await buildSubjectData(artifactPath); 116 | 117 | return subject; 118 | 119 | } else { 120 | 121 | // The artifactPath was a folder, which means we have 122 | // to iterate through everything in it and build a BOM. 123 | // TODO: recursively search the path given if additional folders exist 124 | tl.debug('prepareSubjectData: ' + `${artifactPath}` + ' contains multiple artifacts.') 125 | 126 | try { 127 | /* eslint-disable-next-line security/detect-non-literal-fs-filename -- The ADO agent is responsible for sanitizing this beyond the agent working directory */ 128 | arrayOfFiles = fs.readdirSync(artifactPath); 129 | 130 | } catch (err) { 131 | 132 | console.log('prepareSubjectData: ' + err); 133 | } 134 | 135 | for (const item of arrayOfFiles) { 136 | // Get path to file 137 | const pathToFile: string = path.resolve(artifactPath, item); 138 | const file: boolean = await is_file(pathToFile); 139 | 140 | if (file) { 141 | subject = await buildSubjectData(pathToFile); 142 | } 143 | } 144 | 145 | return subject; 146 | } 147 | } else { 148 | // A bad file or directory was supplied 149 | throw new Error('prepareSubjectData: Invalid Artifact path.'); 150 | } 151 | 152 | } catch (err) { 153 | 154 | throw new Error('prepareSubjectData: ' + err); 155 | 156 | } 157 | } 158 | 159 | /* 160 | * Check to see if supplied object is a file 161 | * @fileCandidate: string 162 | */ 163 | async function is_file(fileCandidate: string): Promise { 164 | 165 | try { 166 | /* eslint-disable-next-line security/detect-non-literal-fs-filename -- Safe as we are checking if it is a file or not */ 167 | const stats: fs.Stats = fs.statSync(fileCandidate); 168 | 169 | return stats.isFile(); 170 | 171 | } catch (err) { 172 | 173 | throw new Error('is_file: ' + err); 174 | } 175 | } 176 | 177 | /* 178 | * Build name and hash map of the artifacts 179 | * @artifact: string 180 | */ 181 | async function buildSubjectData(artifact: string): Promise> { 182 | 183 | try { 184 | 185 | // Read the data from the artifact 186 | /* eslint-disable-next-line security/detect-non-literal-fs-filename -- Safe as the file contents are hashed and not returned to the user */ 187 | const fileBuffer = fs.readFileSync(artifact); 188 | // Hash the data 189 | const artifactHash = crypto.createHash('sha256'); 190 | artifactHash.update(fileBuffer); 191 | // Extract the filename from its UNC path 192 | const artifactName: string = path.basename(artifact); 193 | // Populate the results 194 | subjectData.set(artifactName, artifactHash.digest('hex')); 195 | 196 | return subjectData; 197 | 198 | } catch (err) { 199 | 200 | throw new Error('buildSubjectData: ' + err); 201 | } 202 | } 203 | 204 | run(); -------------------------------------------------------------------------------- /buildAndReleaseTask/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "provenancegenerator", 3 | "version": "0.0.0", 4 | "description": "A proof-of-concept SLSA provenance generator for Azure DevOps Pipelines.", 5 | "main": "index.js", 6 | "author": "gattjoe", 7 | "license": "Apache-2.0", 8 | "scripts": { 9 | "build": "tsc", 10 | "lint": "eslint . --ext .ts" 11 | }, 12 | "dependencies": { 13 | "azure-pipelines-task-lib": "4.1.0" 14 | }, 15 | "devDependencies": { 16 | "@microsoft/eslint-plugin-sdl": "0.2.0", 17 | "@tsconfig/node16-strictest": "1.0.3", 18 | "@types/node": "16.11.49", 19 | "@types/q": "1.5.5", 20 | "@types/uuid": "8.3.4", 21 | "@typescript-eslint/eslint-plugin": "5.36.1", 22 | "@typescript-eslint/parser": "5.36.1", 23 | "eslint": "8.23.0", 24 | "eslint-plugin-node": "11.1.0", 25 | "eslint-plugin-security": "1.5.0" 26 | } 27 | } -------------------------------------------------------------------------------- /buildAndReleaseTask/task.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/Microsoft/azure-pipelines-task-lib/master/tasks.schema.json", 3 | "id": "f93613b8-82ab-4d6a-afac-573ac2426406", 4 | "name": "SLSAProvenanceGenerator", 5 | "friendlyName": "SLSA Provenance Generator", 6 | "description": "A proof-of-concept SLSA provenance generator for Azure DevOps Pipelines.", 7 | "helpMarkDown": "File an issue at https://github.com/slsa-framework/azure-devops-demo/issues for support.", 8 | "category": "Utility", 9 | "author": "Joe Gatt", 10 | "version": { 11 | "Major": 0, 12 | "Minor": 32, 13 | "Patch": 0 14 | }, 15 | "runsOn": [ 16 | "Agent", 17 | "MachineGroup" 18 | ], 19 | "inputs": [ 20 | { 21 | "name": "artifactPath", 22 | "type": "filePath", 23 | "label": "Artifact Path", 24 | "defaultValue": "", 25 | "required": true, 26 | "helpMarkDown": "Path to build artifact or directory of build artifacts" 27 | } 28 | ], 29 | "visibility": [ 30 | "Build", 31 | "Release" 32 | ], 33 | "minimumAgentVersion": "2.206.1", 34 | "execution": { 35 | "Node16": { 36 | "target": "index.js" 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /buildAndReleaseTask/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/@tsconfig/node16-strictest/tsconfig.json" 3 | } -------------------------------------------------------------------------------- /buildAndReleaseTask/writeprovenance.ts: -------------------------------------------------------------------------------- 1 | 2 | // custom type for subject 3 | export type hash = { 4 | sha256: string 5 | } 6 | // custom type for subject artifact data 7 | export type subjectArtifact = { 8 | name: string; 9 | digest: hash; 10 | } 11 | 12 | const subjectJson: Array = [] 13 | 14 | 15 | /* Format the subject data 16 | * @subjectData: Map of artifact name and sha256 digest 17 | */ 18 | export async function writeArtifactData (subjectData: Map): Promise> { 19 | 20 | try { 21 | // Iterate through the subjectData 22 | subjectData.forEach((hash, subject) => 23 | 24 | // Write the subject data 25 | subjectJson.push({name: subject, digest: { sha256: hash}}) 26 | 27 | ) 28 | 29 | return subjectJson; 30 | 31 | } catch (err) { 32 | 33 | throw new Error('writeArtifactData: ' + err); 34 | } 35 | } 36 | 37 | 38 | export async function writeArtifactJson (subjectJson: Array, 39 | builderId: string, 40 | buildInvocationId: string, 41 | materialsUri: string, 42 | buildSourceVersion: string, 43 | buildDefinitionName: string): Promise { 44 | 45 | try { 46 | 47 | const buildJson = { 48 | "_type": "https://in-toto.io/Statement/v0.1", 49 | "subject": subjectJson, 50 | "predicateType": "https://slsa.dev/provenance/v0.1", 51 | "predicate": { 52 | "builder": { 53 | "id": builderId 54 | }, 55 | "metadata": { 56 | "buildInvocationId": buildInvocationId, 57 | "completeness": { 58 | "arguments": true, 59 | "environment": false, 60 | "materials": false 61 | }, 62 | "reproducible": false, 63 | "buildFinishedOn": new Date() 64 | }, 65 | "recipe": { 66 | "type": "https://dev.azure.com/Attestations/SLSAProvenanceGenerator@0", 67 | "definedInMaterial": 0, 68 | "entryPoint": buildDefinitionName, 69 | "arguments": null, 70 | "environment": null 71 | }, 72 | "materials": [ 73 | { 74 | "uri": materialsUri, 75 | "digest": { 76 | "sha1": buildSourceVersion 77 | } 78 | } 79 | ] 80 | } 81 | } 82 | 83 | const json = JSON.stringify(buildJson, null, 4); 84 | 85 | return json; 86 | 87 | } catch (err) { 88 | 89 | throw new Error('writeArtifactJson: ' + err); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /examples/build.provenance: -------------------------------------------------------------------------------- 1 | { 2 | "_type": "https://in-toto.io/Statement/v0.1", 3 | "subject": [ 4 | { 5 | "name": "ocsp-checker-1.8.2.tar.gz", 6 | "digest": { 7 | "sha256": "a7ee92a6be222de773c0ec4075703308aea5280fbfadb5e25ecea4acabd500c0" 8 | } 9 | }, 10 | { 11 | "name": "ocsp_checker-1.8.2-py3-none-any.whl", 12 | "digest": { 13 | "sha256": "3749a23dd1702efb9512faf4deaf1bb0452aece799ba21d40d3273b62c8c6095" 14 | } 15 | } 16 | ], 17 | "predicateType": "https://slsa.dev/provenance/v0.1", 18 | "predicate": { 19 | "builder": { 20 | "id": "https://dev.azure.com/gattjoe/OCSPChecker/Attestations" 21 | }, 22 | "metadata": { 23 | "buildInvocationId": "https://dev.azure.com/gattjoe/OCSPChecker/_build/228", 24 | "completeness": { 25 | "arguments": true, 26 | "environment": false, 27 | "materials": false 28 | }, 29 | "reproducible": false, 30 | "buildFinishedOn": "2021-08-06T16:54:22.465Z" 31 | }, 32 | "recipe": { 33 | "type": "https://dev.azure.com/Attestations/SLSAProvenanceGenerator@0", 34 | "definedInMaterial": 0, 35 | "entryPoint": "OCSPChecker-CI", 36 | "arguments": null, 37 | "environment": null 38 | }, 39 | "materials": [ 40 | { 41 | "uri": "git+https://github.com/gattjoe/OCSPChecker", 42 | "digest": { 43 | "sha1": "dfcb922ec99fb35bbe408926ce2a745bf922f09b" 44 | } 45 | } 46 | ] 47 | } 48 | } -------------------------------------------------------------------------------- /images/extension-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slsa-framework/azure-devops-demo/008e517ab00e95b1480dc9882939f557181b26e5/images/extension-icon.png -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ], 6 | "ignoreDeps": [ 7 | "@microsoft/eslint-plugin-sdl", 8 | "@tsconfig/node16-strictest", 9 | "@types/node", 10 | "@types/q", 11 | "@types/uuid", 12 | "@typescript-eslint/eslint-plugin", 13 | "@typescript-eslint/parser", 14 | "eslint", 15 | "eslint-plugin-node", 16 | "eslint-plugin-security" 17 | ] 18 | } -------------------------------------------------------------------------------- /vss-extension.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": 1, 3 | "id": "build-release-task", 4 | "name": "SLSA Provenance Generator", 5 | "version": "0.32.0", 6 | "publisher": "gattjoe", 7 | "targets": [ 8 | { 9 | "id": "Microsoft.VisualStudio.Services" 10 | } 11 | ], 12 | "tags": [ 13 | "Security", 14 | "Azure Pipelines", 15 | "Azure DevOps Extensions", 16 | "Software Supply Chain Analysis", 17 | "SLSA" 18 | ], 19 | "description": "SLSA Provenance Generator", 20 | "categories": [ 21 | "Azure Pipelines" 22 | ], 23 | "files": [ 24 | { 25 | "path": "buildAndReleaseTask" 26 | }, 27 | { 28 | "path": "images", "addressable": true 29 | } 30 | ], 31 | "links": { 32 | "support": { 33 | "uri": "mailto:gattjoseph@hotmail.com" 34 | }, 35 | "issues": { 36 | "uri": "https://github.com/slsa-framework/azure-devops-demo/issues" 37 | } 38 | }, 39 | "repository": { 40 | "type": "git", 41 | "uri": "https://github.com/slsa-framework/azure-devops-demo" 42 | }, 43 | "icons": { 44 | "default": "images/extension-icon.png" 45 | }, 46 | "content": { 47 | "details": { 48 | "path": "README.md" 49 | }, 50 | "license": { 51 | "path": "LICENSE" 52 | } 53 | }, 54 | "contributions": [ 55 | { 56 | "id": "custom-build-release-task", 57 | "type": "ms.vss-distributed-task.task", 58 | "targets": [ 59 | "ms.vss-distributed-task.tasks" 60 | ], 61 | "properties": { 62 | "name": "buildAndReleaseTask" 63 | } 64 | } 65 | ] 66 | } --------------------------------------------------------------------------------