Skip to content
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

docs: ssh debug integration docs #195

Merged
merged 39 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
144fb45
feat: initial ssh-debug integration
yanksyoon Dec 20, 2023
1c273f0
fix: linting and test fixes
yanksyoon Dec 20, 2023
c79969e
test: add debug info tests
yanksyoon Dec 20, 2023
ce95067
fix: relation data & tests
yanksyoon Dec 27, 2023
41d391b
test: fix unit test
yanksyoon Dec 29, 2023
b61cf74
Merge branch 'main' into feat/ssh-integration
yanksyoon Jan 4, 2024
f479b2e
Merge branch 'main' into feat/ssh-integration
yanksyoon Jan 5, 2024
950909f
feat: flush runners on relation changed
yanksyoon Jan 5, 2024
6e4cafd
Merge branch 'feat/ssh-integration' of https://github.com/canonical/g…
yanksyoon Jan 5, 2024
9301231
fix: lint
yanksyoon Jan 5, 2024
ffa7348
Merge branch 'main' into feat/ssh-integration
yanksyoon Jan 11, 2024
2317203
Merge branch 'main' into feat/ssh-integration
yanksyoon Jan 15, 2024
6993b5f
test: validate SHA fingerprint format
yanksyoon Jan 15, 2024
93c2195
fix: flush only idle runners
yanksyoon Jan 15, 2024
a20e709
fix: remove remote unit filter
yanksyoon Jan 15, 2024
612e84d
fix: use underscore for env vars
yanksyoon Jan 15, 2024
1f734d1
Merge branch 'main' into feat/ssh-integration
yanksyoon Jan 15, 2024
32d313d
Merge branch 'main' into feat/ssh-integration
yanksyoon Jan 16, 2024
c242ca2
Merge branch 'main' of https://github.com/canonical/github-runner-ope…
yanksyoon Jan 16, 2024
ede0da3
test: tmate action test
yanksyoon Jan 16, 2024
9a65604
test: tmate action test
yanksyoon Jan 16, 2024
5e289ad
test: add ssh_debug test to workflow
yanksyoon Jan 16, 2024
2876419
test: rename relation
yanksyoon Jan 16, 2024
11fe9a1
fix: json serializable state
yanksyoon Jan 16, 2024
b3f9af6
fix: optional state serialization
yanksyoon Jan 16, 2024
b2bcf28
fix: use machine address
yanksyoon Jan 16, 2024
e28f3aa
fix: test branch naming
yanksyoon Jan 17, 2024
079a5b8
Merge branch 'main' into test/ssh-integration
yanksyoon Jan 17, 2024
aa929bc
Merge branch 'test/ssh-integration' of https://github.com/canonical/g…
yanksyoon Jan 17, 2024
c59e89c
docs: ssh-debug integration docs
yanksyoon Jan 17, 2024
50f7564
docs: add docstring to testing option values
yanksyoon Jan 17, 2024
3f4c16e
docs: integration test workflow value comment
yanksyoon Jan 17, 2024
4e605d2
Merge branch 'main' of https://github.com/canonical/github-runner-ope…
yanksyoon Jan 19, 2024
9af8ead
Merge branch 'main' into docs/ssh-debug-integration
yanksyoon Jan 19, 2024
8032108
docs: update master to main
yanksyoon Jan 20, 2024
cc18b0f
docs: improve wording
yanksyoon Jan 22, 2024
d061298
docs: parser help messages
yanksyoon Jan 22, 2024
8044dc7
Update tests/conftest.py
yanksyoon Jan 22, 2024
5c68588
Merge branch 'main' into docs/ssh-debug-integration
yanksyoon Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:

jobs:
# test option values defined at test/conftest.py are passed on via repository secret
# INTEGRATION_TEST_ARGS to operator-workflows automatically.
integration-tests-juju2:
name: Integration test with juju 2.9
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
Expand Down
12 changes: 12 additions & 0 deletions docs/explanation/ssh-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SSH Debug

SSH debugging allows a user to identify and resolve issues or errors that occur through the secure
shell (SSH) connection between a client and a server.

To enhance the security of the runner and the infrastructure behind the runner, only user ssh-keys
registered on [Authorized Keys](https://github.com/tmate-io/tmate-ssh-server/pull/93) are allowed
by default on [tmate-ssh-server charm](https://charmhub.io/tmate-ssh-server/).

Authorized keys are registered via [action-tmate](https://github.com/canonical/action-tmate/)'s
`limit-access-to-actor` feature. This feature uses GitHub users's SSH key to launch an instance
of tmate session with `-a` option, which adds the user's SSH key to `~/.ssh/authorized_keys`.
53 changes: 53 additions & 0 deletions docs/how-to/debug-with-ssh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# How to debug with ssh

The charm exposes an integration `debug-ssh` interface which can be used with
[tmate-ssh-server charm](https://charmhub.io/tmate-ssh-server/) to pre-configure runners with
environment variables to be picked up by [action-tmate](https://github.com/canonical/action-tmate/)
for automatic configuration.

## Prerequisites

To enhance the security of self-hosted runners and its infrastracture, only authorized connections
can be established. Hence, action-tmate users must have
[ssh-key registered](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
on the GitHub account.

## Deploying

Use the following command to deploy and integrate github-runner with tmate-ssh-server.

```shell
juju deploy tmate-ssh-server
juju integrate tmate-ssh-server github-runner
```

Idle runners will be flushed and restarted. Busy runners will be configured automatically on next
spawn.

## Using the action

Create a workflow that looks like the following within your workflow to enable action-tmate.

```yaml
name: SSH Debug workflow example

on: [pull_request]

jobs:
build:
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v3
- name: Setup tmate session
uses: canonical/action-tmate@main
```

The output of the action looks like the following.

```
<workflow setup logs redacted>
SSH: ssh -p 10022 <user>@<ip>
or: ssh -i <path-to-private-SSH-key> -p10022 <user>@<ip>
```

Read more about [action-tmate's usage here](https://github.com/canonical/action-tmate).
11 changes: 11 additions & 0 deletions docs/reference/integrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Integrations

### debug-ssh

_Interface_: debug-ssh
_Supported charms_: [tmate-ssh-server](https://charmhub.io/tmate-ssh-server)

Debug-ssh integration provides necessary information for runners to provide ssh reverse-proxy
applications to setup inside the runner.

Example debug-ssh integrate command: `juju integrate github-runner tmate-ssh-server`
40 changes: 32 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,35 @@

def pytest_addoption(parser: Parser):
"""Add options to pytest parser."""
parser.addoption("--path", action="store")
parser.addoption("--token", action="store")
parser.addoption("--charm-file", action="store")
parser.addoption("--token-alt", action="store")
parser.addoption("--http-proxy", action="store")
parser.addoption("--https-proxy", action="store")
parser.addoption("--no-proxy", action="store")
parser.addoption("--loop-device", action="store")
parser.addoption(
"--path",
action="store",
help="The path to repository in <org>/<repo> or <user>/<repo> format.",
)
parser.addoption("--token", action="store", help="The GitHub Personal Access Token.")
parser.addoption(
"--charm-file", action="store", help="The prebuilt github-runner-operator charm file."
)
parser.addoption(
"--token-alt", action="store", help="An alternative token to test the change of a token."
)
parser.addoption(
"--http-proxy",
action="store",
help="HTTP proxy configuration value for juju model proxy configuration.",
)
parser.addoption(
"--https-proxy",
action="store",
help="HTTPS proxy configuration value for juju model proxy configuration.",
)
parser.addoption(
"--no-proxy",
action="store",
help="No proxy configuration value for juju model proxy configuration.",
)
parser.addoption(
"--loop-device",
action="store",
help="The loop device to create shared FS for metrics logging",
)
15 changes: 12 additions & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,32 @@ def charm_file(pytestconfig: pytest.Config, loop_device: Optional[str]) -> str:
def path(pytestconfig: pytest.Config) -> str:
"""Configured path setting."""
path = pytestconfig.getoption("--path")
assert path, "Please specify the --path command line option"
assert path, (
"Please specify the --path command line option with repository "
"path of <org>/<repo> or <user>/<repo> format."
)
return path


@pytest.fixture(scope="module")
def token(pytestconfig: pytest.Config) -> str:
"""Configured token setting."""
token = pytestconfig.getoption("--token")
assert token, "Please specify the --token command line option"
assert token, (
"Please specify the --token command line option with GitHub Personal Access "
"Token value."
)
return token


@pytest.fixture(scope="module")
def token_alt(pytestconfig: pytest.Config, token: str) -> str:
"""Configured token_alt setting."""
token_alt = pytestconfig.getoption("--token-alt")
assert token_alt, "Please specify the --token-alt command line option"
assert token_alt, (
"Please specify the --token-alt command line option with GitHub Personal "
"Access Token value."
)
assert token_alt != token, "Please specify a different token for --token-alt"
return token_alt

Expand Down
Loading