Skip to content

Commit 197746d

Browse files
xrmxtrentm
andauthored
Add testing against fips docker image (#2209)
* Add testing against fips docker image Schedule a weekly run for running a portion of the test suite inside a fips enabled container image. Co-authored-by: Trent Mick <[email protected]> --------- Co-authored-by: Trent Mick <[email protected]>
1 parent 6f521ec commit 197746d

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

.ci/.matrix_framework_fips.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# this is a limited list of matrix builds to be used for PRs
2+
# see .matrix_framework_full.yml for a full list
3+
FRAMEWORK:
4+
- none
5+
- django-5.0
6+
- flask-3.0
7+
- jinja2-3
8+
- opentelemetry-newest
9+
- opentracing-newest
10+
- twisted-newest
11+
- celery-5-flask-2
12+
- celery-5-django-5
13+
- requests-newest
14+
- psutil-newest
15+
- gevent-newest
16+
- aiohttp-newest
17+
- tornado-newest
18+
- starlette-newest
19+
- graphene-2
20+
- httpx-newest
21+
- httplib2-newest
22+
- prometheus_client-newest
23+
- sanic-newest

.ci/.matrix_python_fips.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VERSION:
2+
- python-3.12

.github/workflows/test-fips.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
# run test suite inside a FIPS 140 container
3+
name: test-fips
4+
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: '0 4 * * 1'
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
create-matrix:
15+
runs-on: ubuntu-24.04
16+
outputs:
17+
matrix: ${{ steps.generate.outputs.matrix }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- id: generate
21+
uses: elastic/oblt-actions/version-framework@v1
22+
with:
23+
versions-file: .ci/.matrix_python_fips.yml
24+
frameworks-file: .ci/.matrix_framework_fips.yml
25+
26+
test-fips:
27+
needs: create-matrix
28+
runs-on: ubuntu-24.04
29+
# https://docs.github.com/en/actions/writing-workflows/choosing-where-your-workflow-runs/running-jobs-in-a-container
30+
# docker run -it --rm --name fipsy docker.elastic.co/wolfi/python-fips:3.12
31+
container:
32+
image: docker.elastic.co/wolfi/python-fips:3.12-dev
33+
options: --user root
34+
credentials:
35+
username: ${{ secrets.ELASTIC_DOCKER_USERNAME }}
36+
password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }}
37+
timeout-minutes: 30
38+
strategy:
39+
fail-fast: false
40+
max-parallel: 10
41+
matrix: ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
42+
steps:
43+
- uses: actions/checkout@v4
44+
- name: check that python has fips mode enabled
45+
run: |
46+
python3 -c 'import _hashlib; assert _hashlib.get_fips_mode() == 1'
47+
- name: install run_tests.sh requirements
48+
run: apk add netcat-openbsd tzdata
49+
- name: Run tests
50+
run: ./tests/scripts/run_tests.sh
51+
env:
52+
FRAMEWORK: ${{ matrix.framework }}
53+
54+
notify-on-failure:
55+
if: always()
56+
runs-on: ubuntu-24.04
57+
needs: test-fips
58+
steps:
59+
- id: check
60+
uses: elastic/oblt-actions/check-dependent-jobs@v1
61+
with:
62+
jobs: ${{ toJSON(needs) }}
63+
- name: Notify in Slack
64+
if: steps.check.outputs.status == 'failure'
65+
uses: elastic/oblt-actions/slack/notify-result@v1
66+
with:
67+
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
68+
status: ${{ steps.check.outputs.status }}
69+
channel-id: "#apm-agent-python"

tests/config/tests.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ def test_file_is_readable_validator_not_a_file(tmpdir):
278278
assert "is not a file" in e.value.args[0]
279279

280280

281-
@pytest.mark.skipif(platform.system() == "Windows", reason="os.access() doesn't seem to work as we expect on Windows")
281+
@pytest.mark.skipif(
282+
platform.system() == "Windows" or os.getuid() == 0,
283+
reason="os.access() doesn't seem to work as we expect on Windows and test will fail as root user",
284+
)
282285
def test_file_is_readable_validator_not_readable(tmpdir):
283286
p = tmpdir.join("nonreadable")
284287
p.write("")

0 commit comments

Comments
 (0)