151 lines
9.6 KiB
YAML
151 lines
9.6 KiB
YAML
name: DataStack Docker Build CI
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
security_probe_only:
|
|
description: Inspect locked security dependencies on disposable runner only
|
|
type: boolean
|
|
required: false
|
|
default: false
|
|
|
|
jobs:
|
|
docker-build:
|
|
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.security_probe_only != 'true' }}
|
|
runs-on: ubuntu-latest
|
|
container: node:22-alpine
|
|
timeout-minutes: 45
|
|
steps:
|
|
- name: CI-07 provision Docker Buildx CLI
|
|
run: |
|
|
set -eu
|
|
apk add --no-cache git docker-cli docker-cli-buildx docker-cli-compose
|
|
docker --version
|
|
docker buildx version
|
|
docker compose version
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
github-server-url: https://dev.ivib.cc
|
|
- name: CI-07 inspect daemon and validate Compose without starting services
|
|
run: |
|
|
set -eu
|
|
docker info --format 'Driver={{.Driver}} Root={{.DockerRootDir}}'
|
|
df -h .
|
|
docker compose -f docker/docker-compose.yml config --no-interpolate --quiet
|
|
echo DATASTACK_COMPOSE_CONFIG_PASS
|
|
- name: CI-07 isolated BuildKit all three images (no deployment)
|
|
run: |
|
|
set -eu
|
|
builder="datastack-p03-${GITHUB_RUN_ID:-0}-${GITHUB_RUN_ATTEMPT:-1}"
|
|
tag="datastack-p03-${GITHUB_SHA:-local}"
|
|
cleanup() { docker buildx rm --force "$builder" >/dev/null 2>&1 || true; }
|
|
trap cleanup EXIT
|
|
docker buildx create --name "$builder" --driver docker-container --use
|
|
docker buildx inspect "$builder" --bootstrap
|
|
docker buildx build --builder "$builder" --progress=plain --no-cache --load -f docker/Dockerfile.server -t "$tag-ingestion" .
|
|
docker buildx build --builder "$builder" --progress=plain --no-cache --load -f docker/Dockerfile.web -t "$tag-web" .
|
|
docker buildx build --builder "$builder" --progress=plain --no-cache --load -f docker/Dockerfile.proxy -t "$tag-proxy" .
|
|
docker image inspect "$tag-ingestion" "$tag-web" "$tag-proxy" >/dev/null
|
|
echo DATASTACK_THREE_IMAGES_BUILD_PASS
|
|
|
|
security-backport-source-probe:
|
|
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.security_probe_only == 'true' }}
|
|
runs-on: ubuntu-latest
|
|
container: node:22-alpine
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Install Git for trusted Gitea checkout
|
|
run: apk add --no-cache git ca-certificates
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
github-server-url: https://dev.ivib.cc
|
|
persist-credentials: false
|
|
- name: Security backport applicability and behavioral proof
|
|
run: |
|
|
set -eu
|
|
npm ci --omit=dev --ignore-scripts --no-audit --no-fund
|
|
node <<'NODE'
|
|
const fs = require('node:fs'), crypto = require('node:crypto'), assert = require('node:assert/strict');
|
|
const targets = {
|
|
'node_modules/got/dist/source/request-as-event-emitter.js': '20056793d1233ae2b503c1f3c63fcd17a595d58cc52ab59ecf751c4b5d3f6e11',
|
|
'node_modules/glob/dist/commonjs/walker.js': '1138ced9d5429681a1740af32d13391a38184a3376d1d9d56eea64b7a43274a1',
|
|
'node_modules/onezip/node_modules/glob/dist/commonjs/walker.js': '4eca6e1f2fd9c9ef7469977a12c7e9bd6503bc7a9257ccdc8e79b346ec34fccd',
|
|
'node_modules/glob/node_modules/minimatch/dist/commonjs/index.js': 'a958a41536f57484cc427a03a10a6a094eb062a004c58261add4dbb6dd77bbda',
|
|
'node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js': 'd224f71f20d7c206fcc5b7e9f747324c7698345a0b2c28d717dd9cf698306783',
|
|
'node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js': '34e07cdaeb5c2df273758ba60d8630008571ac350b5fde134ced0bba7948a6d7',
|
|
'node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js': '34e07cdaeb5c2df273758ba60d8630008571ac350b5fde134ced0bba7948a6d7',
|
|
};
|
|
for (const [path, expected] of Object.entries(targets)) {
|
|
const current = crypto.createHash('sha256').update(fs.readFileSync(path)).digest('hex');
|
|
assert.equal(current, expected, 'locked package integrity mismatch: '+path);
|
|
}
|
|
console.log('SECURITY_ORIGINAL_INSTALLED_SOURCE_INTEGRITY_PASS',Object.keys(targets).length);
|
|
NODE
|
|
for p in patches/cloudcmd-got-security.patch patches/cloudcmd-glob-security.patch patches/cloudcmd-minimatch-security.patch patches/cloudcmd-file-type-security.patch; do
|
|
git apply --check "$p"
|
|
git apply "$p"
|
|
git apply --reverse --check "$p"
|
|
echo SECURITY_PATCH_APPLIED "$p"
|
|
done
|
|
node --check node_modules/got/dist/source/request-as-event-emitter.js
|
|
node --check node_modules/glob/dist/commonjs/walker.js
|
|
node --check node_modules/glob/dist/esm/walker.js
|
|
node --check node_modules/glob/node_modules/minimatch/dist/commonjs/index.js
|
|
node --check node_modules/glob/node_modules/minimatch/dist/esm/index.js
|
|
node --check node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js
|
|
node --check node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/esm/index.js
|
|
node --check node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js
|
|
node --check node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js
|
|
node <<'NODE'
|
|
const assert = require('node:assert/strict');
|
|
const fs=require('node:fs'), os=require('node:os'), path=require('node:path'), http=require('node:http'), cp=require('node:child_process');
|
|
async function main(){
|
|
const got = require('./node_modules/got');
|
|
const server=http.createServer((req,res)=>{
|
|
if(req.url==='/unix')return res.writeHead(302,{location:'unix:/var/run/docker.sock:/containers/json'}).end();
|
|
if(req.url==='/hostname')return res.writeHead(302,{location:'http://unix:/var/run/docker.sock:/containers/json'}).end();
|
|
if(req.url==='/normal')return res.writeHead(302,{location:'/ok'}).end();
|
|
res.writeHead(200,{'content-type':'text/plain'}).end('ok');
|
|
});
|
|
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
|
|
const origin='http://127.0.0.1:'+server.address().port;
|
|
try {
|
|
for(const endpoint of ['/unix','/hostname']){
|
|
await assert.rejects(got(origin+endpoint),e=>e.name==='RequestError' && /Cannot redirect to UNIX socket/.test(e.message),endpoint);
|
|
}
|
|
assert.equal((await got(origin+'/normal')).body,'ok');
|
|
console.log('SECURITY_GOT_REDIRECT_BLOCK_AND_NORMAL_REDIRECT_PASS');
|
|
}finally{await new Promise(r=>server.close(r))}
|
|
for(const modulePath of ['./node_modules/glob/node_modules/minimatch','./node_modules/onezip/node_modules/glob/node_modules/minimatch']){
|
|
const {Minimatch}=require(modulePath);
|
|
const pattern=Array(12).fill('**/../a/b').join('/');
|
|
const m=new Minimatch(pattern,{optimizationLevel:2,braceExpandMax:64});
|
|
assert.ok(m.set.length<=64,'minimatch amplification exceeded cap: '+m.set.length);
|
|
assert.equal(new Minimatch('**/*.js',{optimizationLevel:2}).match('src/main.js'),true);
|
|
console.log('SECURITY_MINIMATCH_BOUNDED_AND_NORMAL_PASS',modulePath,m.set.length);
|
|
}
|
|
const glob10c=fs.readFileSync('node_modules/glob/dist/commonjs/walker.js','utf8');
|
|
const glob10e=fs.readFileSync('node_modules/glob/dist/esm/walker.js','utf8');
|
|
const glob13c=fs.readFileSync('node_modules/onezip/node_modules/glob/dist/commonjs/walker.js','utf8');
|
|
const count=s=>(s.match(/if \(this\.signal\?\.aborted\)\s+return cb\(\)/g)||[]).length;
|
|
assert.equal(count(glob10c),4);assert.equal(count(glob10e),4);assert.equal(count(glob13c),4);
|
|
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'datastack-glob-sec-'));
|
|
try {
|
|
fs.mkdirSync(path.join(dir,'nested'));fs.writeFileSync(path.join(dir,'nested','file.js'),'fixture');
|
|
const {glob}=require('./node_modules/glob');
|
|
const found=await glob('**/*.js',{cwd:dir,nodir:true});
|
|
assert.deepEqual(found,['nested/file.js']);
|
|
const ac=new AbortController();ac.abort(new Error('expected abort'));
|
|
await assert.rejects(glob('**/*',{cwd:dir,signal:ac.signal}),/abort/i);
|
|
}finally{fs.rmSync(dir,{recursive:true,force:true})}
|
|
console.log('SECURITY_GLOB_ABORT_AND_NORMAL_WALK_PASS');
|
|
for(const modulePath of ['./node_modules/join-io/node_modules/ponse/node_modules/file-type','./node_modules/restbox/node_modules/ponse/node_modules/file-type']){
|
|
const code="const f=require("+JSON.stringify(modulePath)+"); const b=Buffer.from('3026b2758e66cf11a6d9000000000000000000000000000000000000000000000000000000000000000000000000000000','hex');f.fromBuffer(b).then(r=>{if(!r||r.ext!=='asf')process.exit(1);console.log('ASF_FIX_PASS')}).catch(()=>process.exit(1));";
|
|
const child=cp.spawnSync(process.execPath,['-e',code],{cwd:process.cwd(),encoding:'utf8',timeout:5000});
|
|
assert.equal(child.status,0,'file-type ASF probe: '+child.stderr+' '+child.stdout+' '+child.error);
|
|
}
|
|
console.log('SECURITY_NESTED_FILE_TYPE_ASF_PROGRESS_PASS');
|
|
console.log('SECURITY_ALL_TARGETED_PROBES_PASS');
|
|
}
|
|
main().catch(error=>{console.error('SECURITY_BACKPORT_PROOF_FAILED',error);process.exitCode=1});
|
|
NODE
|