-
Notifications
You must be signed in to change notification settings - Fork 233
tests: add script to update FIPS image in test-fips
workflow
#4736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7339a0f
chore: update fips image sha
david-luna 1ec0115
chore: update fips sha
david-luna 0ce3cd6
chore: remove old sha
david-luna 33b2c6b
chore: update dependabot config for docker
david-luna 92159f7
chore: add script and update image sha
david-luna e006d1e
chore: revert dependabot change
david-luna 7e409b5
chore: fix dependabot syntax
david-luna c49d4a5
Merge branch 'main' into luna-fips-image-fix
david-luna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* Copyright Elasticsearch B.V. and other contributors where applicable. | ||
* Licensed under the BSD 2-Clause License; you may not use this file except in | ||
* compliance with the BSD 2-Clause License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Update the wolfi image for testing with FIPS in the `test-fips.yml` workflow file. | ||
// Assumes docker daemon is installed and running | ||
// | ||
// Usage: | ||
// node dev-utils/update-fips-image.js | ||
|
||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const TOP = path.resolve(__dirname, '..'); | ||
const file = path.resolve(TOP, '.github', 'workflows', 'test-fips.yml'); | ||
|
||
// ---- mainline | ||
|
||
function main() { | ||
// We should replace any reference to the fips image in the yml | ||
// file. It's easy to detect since it has the form | ||
// ``` | ||
// image: docker.elastic.co/wolfi/chainguard-base-fips:latest@sha256:SHA_VALUE | ||
// ``` | ||
// So checking for a substring maybe is enough. We will replace that line for a | ||
// new one. | ||
const imageRef = 'docker.elastic.co/wolfi/chainguard-base-fips:latest'; | ||
|
||
// Get the latest and extract the SHA | ||
const out = execSync(`docker image pull ${imageRef}`, { encoding: 'utf-8' }); | ||
let sha256; | ||
for (const line of out.split('\n')) { | ||
if (line.startsWith('Digest: ')) { | ||
sha256 = line.slice(8); | ||
} | ||
} | ||
console.log('Latest FIPS image sha256 is', sha256); | ||
|
||
// Read the file content and replace any reference to the FIPS image | ||
const content = fs.readFileSync(file, { encoding: 'utf-8' }).split('\n'); | ||
const search = `image: ${imageRef}@sha256:`; | ||
let shouldUpdate = false; | ||
|
||
for (let i = 0; i < content.length; i++) { | ||
const line = content[i]; | ||
const isImageLine = line.indexOf(search) !== -1; | ||
const isShaOutdated = isImageLine && line.indexOf(sha256) === -1; | ||
|
||
if (isImageLine && isShaOutdated) { | ||
console.log('Found FIPS image with outdated sha256. Updating'); | ||
shouldUpdate = true; | ||
content[i] = line.replace(/image:.+/, `image: ${imageRef}@${sha256}`); | ||
} | ||
} | ||
|
||
if (shouldUpdate) { | ||
fs.writeFileSync(file, content.join('\n'), { encoding: 'utf-8' }); | ||
} else { | ||
console.log('No outdated FIPS images found.'); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
main(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could perhaps use this command to resolve the digest without installing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea. I merged this PR to get an updated sha and stop the failures of the.
test-fips.yml
workflow. But I'll do a follow up PR to change use this command and run it periodically with a cron expression.