Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17c94592d9
|
No files matched your search
@@ -55,6 +55,7 @@ jobs:
|
||||
python3 tests/test_voyage_profile.py
|
||||
python3 tests/test_next_native.py
|
||||
python3 tests/test_auxiliary_workflows.py
|
||||
python3 tests/test_qbit_codeql.py
|
||||
python3 tests/test_intellij_plugin.py
|
||||
python3 tests/test_workflow_lint.py
|
||||
python3 tests/test_business_e2e.py
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
name: QBit CodeQL
|
||||
'on':
|
||||
workflow_call:
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
security-events: write
|
||||
packages: read
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze branch source
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Select languages present in this checkout
|
||||
id: languages
|
||||
run: |
|
||||
python3 <<'PY'
|
||||
import os
|
||||
from pathlib import PurePosixPath
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
files = subprocess.check_output(['git', 'ls-files', '-z']).decode('utf-8').split('\0')
|
||||
extensions = {PurePosixPath(name).suffix.lower() for name in files if name}
|
||||
languages = []
|
||||
if extensions & {'.java', '.kt', '.kts'}:
|
||||
languages.append('java-kotlin')
|
||||
if extensions & {'.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'}:
|
||||
languages.append('javascript-typescript')
|
||||
if '.py' in extensions:
|
||||
languages.append('python')
|
||||
if any((name.startswith('.github/workflows/') and PurePosixPath(name).suffix in {'.yml', '.yaml'})
|
||||
or PurePosixPath(name).name in {'action.yml', 'action.yaml'} for name in files if name):
|
||||
languages.append('actions')
|
||||
if not languages:
|
||||
sys.exit('No supported source in this branch; classify placeholders before enabling QBit scanning')
|
||||
build_mode = 'autobuild' if extensions & {'.kt', '.kts'} else 'none'
|
||||
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as output:
|
||||
output.write('languages=' + ','.join(languages) + '\n')
|
||||
output.write('build-mode=' + build_mode + '\n')
|
||||
PY
|
||||
- uses: actions/setup-java@v4
|
||||
if: steps.languages.outputs.build-mode == 'autobuild'
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ steps.languages.outputs.languages }}
|
||||
build-mode: ${{ steps.languages.outputs.build-mode }}
|
||||
- name: Build Kotlin sources
|
||||
if: steps.languages.outputs.build-mode == 'autobuild'
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
- name: Analyze source
|
||||
uses: github/codeql-action/analyze@v4
|
||||
@@ -64,6 +64,7 @@ test-pipelines: pack
|
||||
python3 tests/test_voyage_profile.py
|
||||
python3 tests/test_next_native.py
|
||||
python3 tests/test_auxiliary_workflows.py
|
||||
python3 tests/test_qbit_codeql.py
|
||||
python3 tests/test_intellij_plugin.py
|
||||
python3 tests/test_workflow_lint.py
|
||||
python3 tests/test_business_e2e.py
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Shared QBit source scanning
|
||||
|
||||
Generate the thin caller with `python3 src/scripts/generate_auxiliary_workflow.py qbit-codeql --ref <immutable-worker-sha>`.
|
||||
The reusable worker selects supported languages from tracked files in the actual checked-out branch. Historical Java branches therefore do not request an absent Actions database. Java, JavaScript/TypeScript, Python and Actions share one job; Kotlin selects an actual build instead of silently omitting Kotlin from no-build Java analysis.
|
||||
|
||||
The caller scans pull requests, main/develop/release/hotfix pushes and weekly, cancels superseded PR scans, and contains no scan implementation. Set `codeql_worker_sha` in the estate enforcement policy to require the exact canonical caller independently of other native worker pins. Existing default-setup repositories remain unchanged until migrated.
|
||||
|
||||
Roll out to both active default and maintained branches. Verify the worker on representative branch contents and preserve existing query coverage before replacing GitHub default setup; do not run duplicate default and advanced scanners permanently. Default setup cannot select languages independently for historical branches. A branch with no supported application or workflow source is a placeholder to classify, not a passing application scan.
|
||||
|
||||
Local tests execute the embedded language-selection step against real git indexes, including absent Actions, untracked generated files, mixed source, Kotlin and placeholders. Hosted CodeQL database creation and SARIF upload must also pass before claiming rollout completion.
|
||||
|
||||
References: [GitHub setup types](https://docs.github.com/en/code-security/concepts/code-scanning/setup-types) and [CodeQL build modes](https://docs.github.com/en/code-security/reference/code-scanning/codeql/build-options-for-compiled-languages).
|
||||
@@ -263,7 +263,7 @@
|
||||
},
|
||||
"concurrency": {
|
||||
"group": "e2e-${{ github.ref }}",
|
||||
"cancel-in-progress": "${{ github.event_name == 'pull_request' }}"
|
||||
"cancel-in-progress": "${{ github.event_name == 'pull_request' }}"
|
||||
},
|
||||
"jobs": {
|
||||
"validate": {
|
||||
@@ -427,5 +427,45 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"qbit-codeql": {
|
||||
"repository": null,
|
||||
"profile": "qbit",
|
||||
"path": ".github/workflows/codeql.yml",
|
||||
"caller": {
|
||||
"name": "CodeQL",
|
||||
"on": {
|
||||
"push": {
|
||||
"branches": [
|
||||
"main",
|
||||
"develop",
|
||||
"release/**",
|
||||
"hotfix/**"
|
||||
]
|
||||
},
|
||||
"pull_request": {},
|
||||
"schedule": [
|
||||
{
|
||||
"cron": "41 16 * * 0"
|
||||
}
|
||||
],
|
||||
"workflow_dispatch": {}
|
||||
},
|
||||
"permissions": {
|
||||
"contents": "read",
|
||||
"actions": "read",
|
||||
"security-events": "write",
|
||||
"packages": "read"
|
||||
},
|
||||
"concurrency": {
|
||||
"group": "codeql-${{ github.event.pull_request.number || github.ref }}",
|
||||
"cancel-in-progress": "${{ github.event_name == 'pull_request' }}"
|
||||
},
|
||||
"jobs": {
|
||||
"analyze": {
|
||||
"uses": "QRun-IO/qqq-orb/.github/workflows/qbit-codeql.yml@WORKER_SHA"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,21 @@ class Snapshot:
|
||||
|
||||
|
||||
class AuditTests(unittest.TestCase):
|
||||
def test_qbit_scanner_policy_requires_exact_canonical_worker(self):
|
||||
entry = dict(ENTRY, name='qbit-help', nameWithOwner='QRun-IO/qbit-help')
|
||||
manifest = {'profile': 'qbit', 'orb_version': VERSION, 'default_branch': 'develop',
|
||||
'publish': {'snapshot': False, 'release_candidate': False, 'release': False}}
|
||||
files = {'.qqq-ci.yml': audit.generator.yaml.safe_dump(manifest),
|
||||
'.circleci/config.yml': audit.generator.yaml.safe_dump(audit.standard.canonical_caller('qbit', VERSION))}
|
||||
policy = dict(POLICY, codeql_worker_sha='b' * 40)
|
||||
report = audit.audit(entry, Snapshot(files), VERSION, SHA, policy)
|
||||
self.assertTrue(any(f['code'] == 'missing_native_maintenance_bridge' for f in report['findings']))
|
||||
files['.github/workflows/codeql.yml'] = audit.generator.yaml.safe_dump(audit.auxiliary.canonical('qbit-codeql', 'b' * 40), sort_keys=False)
|
||||
self.assertEqual([], audit.audit(entry, Snapshot(files), VERSION, SHA, policy)['findings'])
|
||||
files['.github/workflows/codeql.yml'] = files['.github/workflows/codeql.yml'].replace('b' * 40, 'a' * 40)
|
||||
report = audit.audit(entry, Snapshot(files), VERSION, SHA, policy)
|
||||
self.assertTrue(any(f['code'] == 'native_maintenance_bridge_drift' for f in report['findings']))
|
||||
|
||||
def test_live_snapshot_reads_requested_branch_and_keeps_default_identity(self):
|
||||
entry = dict(ENTRY, sourceBranch='release/1.2')
|
||||
replies = [{'default_branch': 'develop', 'archived': False}, {'sha': SHA},
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import yaml
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
|
||||
class BranchLanguages(unittest.TestCase):
|
||||
def select(self, tracked, untracked=()):
|
||||
worker = yaml.safe_load((ROOT / '.github/workflows/qbit-codeql.yml').read_text())
|
||||
script = next(s['run'] for s in worker['jobs']['analyze']['steps'] if s.get('id') == 'languages')
|
||||
script = script.split("python3 <<'PY'\n", 1)[1].rsplit('\nPY', 1)[0]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
subprocess.run(['git', 'init', '-q', directory], check=True)
|
||||
for name in (*tracked, *untracked):
|
||||
path = root / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text('fixture')
|
||||
if tracked:
|
||||
subprocess.run(['git', 'add', '--', *tracked], cwd=root, check=True)
|
||||
output = root / 'outputs'
|
||||
result = subprocess.run([sys.executable, '-c', script], cwd=root,
|
||||
env={**os.environ, 'GITHUB_OUTPUT': str(output)}, capture_output=True, text=True)
|
||||
return result, output.read_text() if output.exists() else ''
|
||||
|
||||
def test_historical_java_branch_does_not_scan_absent_actions(self):
|
||||
result, output = self.select(['src/Example.java'])
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertIn('languages=java-kotlin\n', output)
|
||||
self.assertIn('build-mode=none\n', output)
|
||||
|
||||
def test_current_branch_preserves_all_present_supported_languages(self):
|
||||
result, output = self.select(['src/Example.java', '.github/workflows/ci.yaml', 'web/app.tsx', 'tools/check.py'])
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertIn('languages=java-kotlin,javascript-typescript,python,actions\n', output)
|
||||
|
||||
def test_kotlin_requires_a_build(self):
|
||||
result, output = self.select(['src/Example.kt', '.github/workflows/ci.yml'])
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertIn('build-mode=autobuild\n', output)
|
||||
|
||||
def test_untracked_files_do_not_select_languages(self):
|
||||
result, output = self.select(['src/Example.java'], ['web/generated.js', '.github/workflows/untracked.yml'])
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertIn('languages=java-kotlin\n', output)
|
||||
|
||||
def test_placeholder_fails_explicitly(self):
|
||||
result, output = self.select(['README.md'])
|
||||
self.assertNotEqual(0, result.returncode)
|
||||
self.assertIn('No supported source', result.stderr)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -233,17 +233,22 @@ def audit(entry, snapshot, version, worker_sha, policy):
|
||||
if other != path and 'qbit-release-rc.yml@' in snapshot.read(other):
|
||||
finding('duplicate_rc_bridge', other)
|
||||
for kind, definition in auxiliary.BRIDGES.items():
|
||||
if definition['repository'] != entry['nameWithOwner']:
|
||||
bridge_sha = worker_sha
|
||||
if kind == 'qbit-codeql':
|
||||
if profile != 'qbit' or 'codeql_worker_sha' not in policy:
|
||||
continue
|
||||
bridge_sha = policy['codeql_worker_sha']
|
||||
elif definition['repository'] != entry['nameWithOwner']:
|
||||
continue
|
||||
path = definition['path']
|
||||
raw = snapshot.read(path)
|
||||
if raw is None:
|
||||
finding('missing_native_maintenance_bridge', path)
|
||||
continue
|
||||
if not re.fullmatch(r'[0-9a-f]{40}', worker_sha or ''):
|
||||
if not re.fullmatch(r'[0-9a-f]{40}', bridge_sha or ''):
|
||||
finding('native_pin_policy_missing', path)
|
||||
continue
|
||||
expected = generator.yaml.safe_dump(auxiliary.canonical(kind, worker_sha), sort_keys=False)
|
||||
expected = generator.yaml.safe_dump(auxiliary.canonical(kind, bridge_sha), sort_keys=False)
|
||||
if raw != expected:
|
||||
finding('native_maintenance_bridge_drift', path)
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user