Skip to content

Commit c8729c2

Browse files
authored
Merge pull request #168 from bluesliverx/main
Remove deploy key usage and instead use temporary SSH key
2 parents b76ce0f + 146f0c4 commit c8729c2

File tree

5 files changed

+68
-37
lines changed

5 files changed

+68
-37
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,10 @@ jobs:
3434
pip install -r test_requirements.txt
3535
- name: Pre-commit checks
3636
run: pre-commit run --all-files
37-
- name: Write SSH keys
38-
env:
39-
# These were generated with:
40-
# ssh-keygen -t ecdsa -m PEM ''
41-
# and then installed as a read-only deploy key on the buildrunner repository
42-
#
43-
# Since this is a public repository and the key provides the same rights that even anonymous users have,
44-
# this key is rather worthless and can be stored safely in code here. This *could* be used as a secret,
45-
# but since secrets are not available to forks, we cannot test SSH functionality in PRs which defeats
46-
# the purpose somewhat.
47-
#
48-
# Please note that for the SSH unit tests to pass on a local machine, the private key needs to be placed in ~/.ssh/buildrunner-deploy-id_rsa
49-
DEPLOY_SSH_KEY: "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACBasvUoRzAAdHZ5nFWtDR/5DQU+FWtDYNXD0xPGSdjKtwAAAJiLXobki16G\n5AAAAAtzc2gtZWQyNTUxOQAAACBasvUoRzAAdHZ5nFWtDR/5DQU+FWtDYNXD0xPGSdjKtw\nAAAEBcRwB1PEnUHF5aK6q3JYyuOlT+adQ0mcRrIxsmJiiq1Vqy9ShHMAB0dnmcVa0NH/kN\nBT4Va0Ng1cPTE8ZJ2Mq3AAAAEWJ1aWxkcnVubmVyQGFkb2JlAQIDBA==\n-----END OPENSSH PRIVATE KEY-----"
50-
DEPLOY_SSH_KEY_PUB: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFqy9ShHMAB0dnmcVa0NH/kNBT4Va0Ng1cPTE8ZJ2Mq3 buildrunner@adobe"
51-
run: |
52-
mkdir -p ~/.ssh
53-
printf -- "$DEPLOY_SSH_KEY" > ~/.ssh/buildrunner-deploy-id_rsa
54-
printf -- "$DEPLOY_SSH_KEY_PUB" > ~/.ssh/buildrunner-deploy-id_rsa.pub
55-
chmod 700 ~/.ssh
56-
chmod 600 ~/.ssh/buildrunner-deploy-*
5737
- name: Test with pytest
38+
# Create the ssh key file once for all testing
5839
run: |
40+
ssh-keygen -t ecdsa -m PEM -N '' -f /tmp/buildrunner-test-id_rsa
5941
pytest -v -m "not serial" --numprocesses=auto --junitxml=test-reports/non-serial-test-results.xml
6042
pytest -v -m "serial" --junitxml=test-reports/serial-test-results.xml
6143
python scripts/combine_xml.py test-reports/serial-test-results.xml test-reports/non-serial-test-results.xml > test-reports/test-result.xml

tests/config-files/dot-buildrunner.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ ssh-keys:
1111
aliases:
1212
- 'adobe-github'
1313
- 'adobe-dma'
14-
- file: ~/.ssh/buildrunner-deploy-id_rsa
14+
# This should match what is in the test_buildrunner_files.py file and is generated before the tests are run
15+
- file: /tmp/buildrunner-test-id_rsa
1516
aliases:
16-
- 'buildrunner-deploy'
17+
- 'buildrunner-test-ssh'
1718

1819
local-files:
1920
tests: ./tests
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Please note that for the SSH unit tests to pass on a local machine, the private key needs to be placed in ~/.ssh/buildrunner-deploy-id_rsa
2-
# Look in the .github/workflows/build.yaml file for the SSH private key
31
use-legacy-builder: False
42
steps:
53
clone:
@@ -8,12 +6,20 @@ steps:
86
FROM {{ DOCKER_REGISTRY }}/rockylinux:8.5
97
RUN yum install -y git-core openssh-clients && yum clean all
108
run:
11-
ssh-keys: ['buildrunner-deploy']
9+
# This key is generated automatically by the test runner
10+
ssh-keys: ['buildrunner-test-ssh']
11+
services:
12+
ssh-service:
13+
image: {{ DOCKER_REGISTRY }}/linuxserver/openssh-server:latest
14+
wait_for:
15+
- 2222
16+
env:
17+
# This is set in the test_buildrunner_files.py file
18+
PUBLIC_KEY: "{{ BUILDRUNNER_TEST_SSH_PUB_KEY }}"
19+
LOG_STDOUT: "true"
1220
cmds:
1321
- mkdir ~/.ssh
14-
- ssh-keyscan github.com > ~/.ssh/known_hosts
22+
- ssh-keyscan -p 2222 ssh-service > ~/.ssh/known_hosts
1523
- chmod 700 ~/.ssh
1624
- chmod 600 ~/.ssh/known_hosts
17-
# Clone into temp directory since the "buildrunner" directory may already exist
18-
- rm -rf /tmp/test-clone
19-
- git clone [email protected]:adobe/buildrunner.git /tmp/test-clone
25+
- if [ "$(ssh -p 2222 linuxserver.io@ssh-service 'whoami')" != "linuxserver.io" ]; then exit 1; fi

tests/test-files/test-ssh.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
# Please note that for the SSH unit tests to pass on a local machine, the private key needs to be placed in ~/.ssh/buildrunner-deploy-id_rsa.
2-
# Look in the .github/workflows/build.yaml file for the SSH private key.
31
steps:
4-
clone:
2+
ssh-test:
53
build:
64
dockerfile: |
75
FROM {{ DOCKER_REGISTRY }}/rockylinux:8.5
86
RUN yum install -y git-core openssh-clients && yum clean all
97
run:
10-
ssh-keys: ['buildrunner-deploy']
8+
# This key is generated automatically by the test runner
9+
ssh-keys: ['buildrunner-test-ssh']
10+
services:
11+
ssh-service:
12+
image: {{ DOCKER_REGISTRY }}/linuxserver/openssh-server:latest
13+
wait_for:
14+
- 2222
15+
env:
16+
# This is set in the test_buildrunner_files.py file
17+
PUBLIC_KEY: "{{ BUILDRUNNER_TEST_SSH_PUB_KEY }}"
18+
LOG_STDOUT: "true"
1119
cmds:
1220
- mkdir ~/.ssh
13-
- ssh-keyscan github.com > ~/.ssh/known_hosts
21+
- ssh-keyscan -p 2222 ssh-service > ~/.ssh/known_hosts
1422
- chmod 700 ~/.ssh
1523
- chmod 600 ~/.ssh/known_hosts
16-
# Clone into temp directory since the "buildrunner" directory may already exist
17-
- rm -rf /tmp/test-clone
18-
- git clone [email protected]:adobe/buildrunner.git /tmp/test-clone
24+
- if [ "$(ssh -p 2222 linuxserver.io@ssh-service 'whoami')" != "linuxserver.io" ]; then exit 1; fi

tests/test_buildrunner_files.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import os
22
import pytest
33
import platform
4+
import subprocess
45
import tempfile
6+
from pathlib import Path
57
from typing import List, Optional, Tuple
68

79
from tests import test_runner
810

11+
# This should match what is in the dot-buildrunner.yaml file
12+
TEST_SSH_KEY_FILE = "/tmp/buildrunner-test-id_rsa"
13+
914
test_dir_path = os.path.realpath(os.path.dirname(__file__))
1015
TEST_DIR = os.path.dirname(__file__)
1116
top_dir_path = os.path.realpath(os.path.dirname(test_dir_path))
@@ -18,6 +23,37 @@
1823
]
1924

2025

26+
@pytest.fixture(autouse=True, scope="session")
27+
def setup_buildrunner_test_ssh_key():
28+
key_file_path = Path(TEST_SSH_KEY_FILE)
29+
cleanup_key_file = False
30+
pub_key_file_path = Path(f"{TEST_SSH_KEY_FILE}.pub")
31+
if not key_file_path.exists():
32+
subprocess.run(
33+
[
34+
"ssh-keygen",
35+
"-t",
36+
"ecdsa",
37+
"-m",
38+
"PEM",
39+
"-N",
40+
"",
41+
"-f",
42+
TEST_SSH_KEY_FILE,
43+
],
44+
check=True,
45+
)
46+
cleanup_key_file = True
47+
# Set the public key in an environment variable to use in the test buildrunner files
48+
os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"] = pub_key_file_path.read_text().strip()
49+
yield
50+
# Cleanup
51+
del os.environ["BUILDRUNNER_TEST_SSH_PUB_KEY"]
52+
if cleanup_key_file:
53+
key_file_path.unlink()
54+
pub_key_file_path.unlink()
55+
56+
2157
def _get_test_args(file_name: str) -> Optional[List[str]]:
2258
if file_name == "test-timeout.yaml":
2359
# Set a short timeout here for the timeout test

0 commit comments

Comments
 (0)