Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Simplify workflow security checks

Manav Rathiee16f0287ffd
diff --git a/.github/scripts/check_workflow_security.rb b/.github/scripts/check_workflow_security.rb
index 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}")
end
def trigger_names(workflow)
@@ -72,13 +46,13 @@ def uses_values(node)
end
end
-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_TRIGGERS
unpinned_actions = uses_values(workflow).each_with_object(Set.new) do |uses, actions|
action, ref = uses.match(USES_REF)&.captures
next 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).sort
trigger_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}"
end
end
failed = 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 failed
unless trigger_violations.empty?
puts
- puts "New privileged triggers:"
+ puts "Privileged triggers:"
trigger_violations.each { |violation| puts "- #{violation}" }
end
unless unpinned_violations.empty?
puts
- puts "New unpinned third-party actions:"
+ puts "Unpinned external actions:"
unpinned_violations.each { |violation| puts "- #{violation}" }
end
puts
puts "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 1
diff --git a/.github/workflows/auth-build.yml b/.github/workflows/auth-build.yml
index 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.0
with:
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.0
with:
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.yml
index 9f120fb497..b7deebd7d2 100644
--- a/.github/workflows/desktop-lint.yml
+++ b/.github/workflows/desktop-lint.yml
@@ -16,7 +16,8 @@ jobs:
run:
working-directory: desktop
steps:
- - uses: actions/checkout@v6
+ - name: Checkout
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup node and enable npm caching
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
diff --git a/.github/workflows/docs-deploy-redirect.yml b/.github/workflows/docs-deploy-redirect.yml
index 1efe30d8ea..26d646e05c 100644
--- a/.github/workflows/docs-deploy-redirect.yml
+++ b/.github/workflows/docs-deploy-redirect.yml
@@ -16,7 +16,8 @@ jobs:
environment: production
steps:
- - uses: actions/checkout@v6
+ - name: Checkout
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Deploy redirect to help.ente.io
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml
index e9b5438867..8a0cf70949 100644
--- a/.github/workflows/docs-deploy.yml
+++ b/.github/workflows/docs-deploy.yml
@@ -21,9 +21,11 @@ jobs:
working-directory: docs
steps:
- - 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.0
with:
node-version: 24
cache: "npm"
diff --git a/.github/workflows/docs-verify-build.yml b/.github/workflows/docs-verify-build.yml
index 4130fef256..bd9cb11bc9 100644
--- a/.github/workflows/docs-verify-build.yml
+++ b/.github/workflows/docs-verify-build.yml
@@ -22,9 +22,11 @@ jobs:
working-directory: docs
steps:
- - 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.0
with:
node-version: 24
cache: "npm"
diff --git a/.github/workflows/infra-deploy-staff.yml b/.github/workflows/infra-deploy-staff.yml
index 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/staff
steps:
- - uses: actions/checkout@v6
+ - name: Checkout
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup node and enable npm caching
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
diff --git a/.github/workflows/rust-e2e-test.yml b/.github/workflows/rust-e2e-test.yml
index 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/cli
steps:
- - 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.0
with:
go-version-file: server/go.mod
- - uses: actions/setup-node@v6
+ - name: Setup node
+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
@@ -50,7 +53,8 @@ jobs:
timeout-minutes: 30
steps:
- - uses: actions/checkout@v6
+ - name: Checkout
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Run Docker E2E suite
env:
diff --git a/.github/workflows/rust-lint.yml b/.github/workflows/rust-lint.yml
index 3b365edb5f..7ecaacef9b 100644
--- a/.github/workflows/rust-lint.yml
+++ b/.github/workflows/rust-lint.yml
@@ -23,7 +23,8 @@ jobs:
run:
working-directory: rust
steps:
- - uses: actions/checkout@v6
+ - name: Checkout
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Linux dependencies
run: |
diff --git a/.github/workflows/workflow-security-checks.yml b/.github/workflows/workflow-security-checks.yml
index 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 PR
uses: 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