π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Simplify workflow security checks
Manav Rathiee16f0287ffd
diff --git a/.github/scripts/check_workflow_security.rb b/.github/scripts/check_workflow_security.rbindex 605cd88ab3..8407b5c57c 100644--- a/.github/scripts/check_workflow_security.rb+++ b/.github/scripts/check_workflow_security.rb@@ -1,6 +1,5 @@#!/usr/bin/env ruby-require "open3"require "set"require "yaml"@@ -16,38 +15,13 @@ WORKFLOW_PATH = %r{\A\.github/workflows/.*\.ya?ml\z}USES_REF = %r{\A([A-Za-z0-9._-]+/[A-Za-z0-9._-]+(?:/[A-Za-z0-9._/-]+)?)@(\S+)\z}FULL_SHA = /\A[0-9a-fA-F]{40}\z/-def git(*args)- stdout, stderr, status = Open3.capture3("git", *args)- return stdout if status.success?-- abort(stderr.empty? ? "git #{args.join(' ')} failed" : stderr)-end--def blob(revision, path)- stdout, _stderr, status = Open3.capture3("git", "show", "#{revision}:#{path}")- status.success? ? stdout : ""-end--def workflow_changes(base, head)- git("diff", "--name-status", "--find-renames", "--diff-filter=AMR", "#{base}...#{head}")- .lines- .each_with_object([]) do |line, changes|- status, path, new_path = line.chomp.split("\t")- head_path = status.start_with?("R") ? new_path : path- next unless head_path.match?(WORKFLOW_PATH)-- base_path = status.start_with?("R") && path.match?(WORKFLOW_PATH) ? path : head_path- changes << { base: base_path, head: head_path }- end-end--def workflow_yaml(revision, path)+def workflow_yaml(path)YAML.safe_load(- blob(revision, path),+ File.read(path),aliases: true,) || {}rescue Psych::Exception => e- abort("Failed to parse workflow YAML in #{revision}:#{path}: #{e.message}")+ abort("Failed to parse workflow YAML in #{path}: #{e.message}")enddef trigger_names(workflow)@@ -72,13 +46,13 @@ def uses_values(node)endend-def workflow_facts(revision, path)- workflow = workflow_yaml(revision, path)+def workflow_facts(path)+ workflow = workflow_yaml(path)triggers = trigger_names(workflow).to_set & SENSITIVE_TRIGGERSunpinned_actions = uses_values(workflow).each_with_object(Set.new) do |uses, actions|action, ref = uses.match(USES_REF)&.capturesnext unless action- next if action.start_with?("actions/") || ref.match?(FULL_SHA)+ next if ref.match?(FULL_SHA)actions.add("#{action}@#{ref}")end@@ -86,58 +60,44 @@ def workflow_facts(revision, path){ triggers: triggers, unpinned_actions: unpinned_actions }end-base, head = ARGV-abort("Usage: #{$PROGRAM_NAME} <base-revision> <head-revision>") unless base && head+abort("Usage: #{$PROGRAM_NAME}") unless ARGV.empty?-changes = workflow_changes(base, head)-if changes.empty?- puts "Workflow Security Checks: Passed"- puts "No workflow files changed."- exit 0-end+workflows = Dir.glob(".github/workflows/*.{yml,yaml}").grep(WORKFLOW_PATH).sorttrigger_violations = []unpinned_violations = []-changes.each do |change|- path = change[:head]- before = workflow_facts(base, change[:base])- after = workflow_facts(head, path)-- (after[:triggers] - before[:triggers]).each do |trigger|+workflows.each do |path|+ facts = workflow_facts(path)+ facts[:triggers].each do |trigger|trigger_violations << "#{path}: #{trigger}"end- (after[:unpinned_actions] - before[:unpinned_actions]).each do |action|+ facts[:unpinned_actions].each do |action|unpinned_violations << "#{path}: #{action}"endendfailed = trigger_violations.any? || unpinned_violations.any?puts "Workflow Security Checks: #{failed ? "Failed" : "Passed"}"-puts-puts "Checked workflow files:"-changes.each do |change|- rename = change[:base] == change[:head] ? "" : " (renamed from #{change[:base]})"- puts "- #{change[:head]}#{rename}"-end+puts "Checked #{workflows.length} workflow files."exit 0 unless failedunless trigger_violations.empty?puts- puts "New privileged triggers:"+ puts "Privileged triggers:"trigger_violations.each { |violation| puts "- #{violation}" }endunless unpinned_violations.empty?puts- puts "New unpinned third-party actions:"+ puts "Unpinned external actions:"unpinned_violations.each { |violation| puts "- #{violation}" }endputsputs "Fix:"-puts "- Remove newly added privileged triggers." if trigger_violations.any?-puts "- Pin third-party actions to a full 40-character commit SHA." if unpinned_violations.any?+puts "- Remove privileged triggers." if trigger_violations.any?+puts "- Pin external actions to a full 40-character commit SHA." if unpinned_violations.any?exit 1diff --git a/.github/workflows/auth-build.yml b/.github/workflows/auth-build.ymlindex 6b40d7eb9b..88547991f0 100644--- a/.github/workflows/auth-build.yml+++ b/.github/workflows/auth-build.yml@@ -399,7 +399,7 @@ jobs:shell: pwsh- name: Sign Windows payload with Trusted Signing- uses: azure/trusted-signing-action@208f8af4bf26cf2af8597424e3cb5582801523ba # v2.0.0+ uses: azure/trusted-signing-action@c7ab2a863ab5f9a846ddb8265964877ef296ee82 # v2.0.0with:azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}@@ -427,7 +427,7 @@ jobs:shell: pwsh- name: Sign Windows installer with Trusted Signing- uses: azure/trusted-signing-action@208f8af4bf26cf2af8597424e3cb5582801523ba # v2.0.0+ uses: azure/trusted-signing-action@c7ab2a863ab5f9a846ddb8265964877ef296ee82 # v2.0.0with:azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}diff --git a/.github/workflows/desktop-lint.yml b/.github/workflows/desktop-lint.ymlindex 9f120fb497..b7deebd7d2 100644--- a/.github/workflows/desktop-lint.yml+++ b/.github/workflows/desktop-lint.yml@@ -16,7 +16,8 @@ jobs:run:working-directory: desktopsteps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- name: Setup node and enable npm cachinguses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0diff --git a/.github/workflows/docs-deploy-redirect.yml b/.github/workflows/docs-deploy-redirect.ymlindex 1efe30d8ea..26d646e05c 100644--- a/.github/workflows/docs-deploy-redirect.yml+++ b/.github/workflows/docs-deploy-redirect.yml@@ -16,7 +16,8 @@ jobs:environment: productionsteps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- name: Deploy redirect to help.ente.iouses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.ymlindex e9b5438867..8a0cf70949 100644--- a/.github/workflows/docs-deploy.yml+++ b/.github/workflows/docs-deploy.yml@@ -21,9 +21,11 @@ jobs:working-directory: docssteps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- - uses: actions/setup-node@v6+ - name: Setup node and enable npm caching+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0with:node-version: 24cache: "npm"diff --git a/.github/workflows/docs-verify-build.yml b/.github/workflows/docs-verify-build.ymlindex 4130fef256..bd9cb11bc9 100644--- a/.github/workflows/docs-verify-build.yml+++ b/.github/workflows/docs-verify-build.yml@@ -22,9 +22,11 @@ jobs:working-directory: docssteps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- - uses: actions/setup-node@v6+ - name: Setup node and enable npm caching+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0with:node-version: 24cache: "npm"diff --git a/.github/workflows/infra-deploy-staff.yml b/.github/workflows/infra-deploy-staff.ymlindex c3b96fe5f5..1c348b1f1f 100644--- a/.github/workflows/infra-deploy-staff.yml+++ b/.github/workflows/infra-deploy-staff.yml@@ -21,7 +21,8 @@ jobs:working-directory: infra/staffsteps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- name: Setup node and enable npm cachinguses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0diff --git a/.github/workflows/rust-e2e-test.yml b/.github/workflows/rust-e2e-test.ymlindex fe1b02c4ae..fdbc4df889 100644--- a/.github/workflows/rust-e2e-test.yml+++ b/.github/workflows/rust-e2e-test.yml@@ -29,13 +29,16 @@ jobs:working-directory: rust/apps/clisteps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- - uses: actions/setup-go@v5+ - name: Setup go+ uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0with:go-version-file: server/go.mod- - uses: actions/setup-node@v6+ - name: Setup node+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0with:node-version: 24@@ -50,7 +53,8 @@ jobs:timeout-minutes: 30steps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- name: Run Docker E2E suiteenv:diff --git a/.github/workflows/rust-lint.yml b/.github/workflows/rust-lint.ymlindex 3b365edb5f..7ecaacef9b 100644--- a/.github/workflows/rust-lint.yml+++ b/.github/workflows/rust-lint.yml@@ -23,7 +23,8 @@ jobs:run:working-directory: ruststeps:- - uses: actions/checkout@v6+ - name: Checkout+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- name: Install Linux dependenciesrun: |diff --git a/.github/workflows/workflow-security-checks.yml b/.github/workflows/workflow-security-checks.ymlindex a89744c988..55dff107ec 100644--- a/.github/workflows/workflow-security-checks.yml+++ b/.github/workflows/workflow-security-checks.yml@@ -18,8 +18,6 @@ jobs:steps:- name: Checkout PRuses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3- with:- fetch-depth: 0- name: Run workflow security checks- run: ruby .github/scripts/check_workflow_security.rb "origin/${{ github.base_ref }}" HEAD+ run: ruby .github/scripts/check_workflow_security.rb