Skip to content

Commit

Permalink
Make ghasum update -force update existing checksums that are incorrect
Browse files Browse the repository at this point in the history
Update the implementation of the `ghasum update` command to update any
existing sums that are incorrect IF the `-force` flag is used. Here,
"existing sums" refers to entries in the sumfile for which the whole ID
matches before and after the update. This supports updating such entries
natively (i.e. without having to manually edit the sumfile), which may
be necessary if the incident has been reviewed and deemed acceptable.

The CLI help message as well as the specification text has been updated
accordingly.
  • Loading branch information
ericcornelissen committed Jul 31, 2024
1 parent a3b2e42 commit 4fb902a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
9 changes: 5 additions & 4 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ before and releases the lock. In short, updating will only add new and remove
old checksums from an existing sumfile.

With the `-force` flag the process will ignore errors in the sumfile and fix
those while updating. If the sumfile version can still be determined from
sumfile it will be used, otherwise the latest available version is used instead.
This option is disabled by default to avoid unknowingly fixing syntax errors in
a sumfile, which is an important fact to know about from a security perspective.
those while updating. It will also update existing checksums that are incorrect.
If the sumfile version can still be determined from sumfile it will be used,
otherwise the latest available version is used instead. This option is disabled
by default to avoid unknowingly fixing syntax or other errors in a sumfile,
which is an important fact to know about from a security perspective.

This process does not verify any of the checksums currently in the sumfile.

Expand Down
4 changes: 2 additions & 2 deletions cmd/ghasum/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ The available flags are:
looks up repositories it needs.
Defaults to a directory named .ghasum in the user's home directory.
-force
Force updating the gha.sum file, ignoring errors and fixing them in the
process.
Force updating the gha.sum file, ignoring syntax errors and fixing them
in the process. This also fixes any existing checksums that are wrong.
-no-cache
Disable the use of the cache. Makes the -cache flag ineffective.
-no-evict
Expand Down
12 changes: 7 additions & 5 deletions internal/ghasum/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ func Update(cfg *Config, force bool) error {
return err
}

for i, entry := range checksums {
for _, oldEntry := range oldChecksums {
if slices.Equal(entry.ID, oldEntry.ID) {
checksums[i] = oldEntry
break
if !force {
for i, entry := range checksums {
for _, oldEntry := range oldChecksums {
if slices.Equal(entry.ID, oldEntry.ID) {
checksums[i] = oldEntry
break
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions testdata/update/force.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ stdout 'Ok'
! stderr .
cmp no-version/.github/workflows/gha.sum .want/gha.sum

# Invalid existing sum
exec ghasum update -cache .cache/ -force invalid-sum/
stdout 'Ok'
! stderr .
cmp invalid-sum/.github/workflows/gha.sum .want/gha.sum

-- duplicate/.github/workflows/gha.sum --
version 1

Expand Down Expand Up @@ -118,6 +124,21 @@ actions/[email protected] GGAV+/JnlPt41B9iINyvcX5z6a4ue+NblmwiDNVORz0=
name: Example workflow
on: [push]

jobs:
example:
name: example
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/[email protected]
-- invalid-sum/.github/workflows/gha.sum --
version 1

actions/[email protected] GGAV+/JnlPt41B9iINyvcX5z6a4ue+NblmwiDNVORz0=
-- invalid-sum/.github/workflows/workflow.yml --
name: Example workflow
on: [push]

jobs:
example:
name: example
Expand Down

0 comments on commit 4fb902a

Please sign in to comment.