Skip to content

Commit e6adc93

Browse files
committed
Reimplement in Python
Primarily to facilitate better error handling.
1 parent fb79faf commit e6adc93

File tree

7 files changed

+263
-123
lines changed

7 files changed

+263
-123
lines changed

.github/workflows/linter.yaml

+39-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,45 @@ on:
1212

1313
permissions:
1414
contents: read
15-
statuses: write
1615

1716
jobs:
18-
lint:
17+
python:
18+
name: Python
19+
runs-on: ${{ matrix.os }}
20+
21+
strategy:
22+
matrix:
23+
os:
24+
- ubuntu-20.04
25+
- ubuntu-22.04
26+
27+
steps:
28+
- name: Check out repository
29+
uses: actions/checkout@v4
30+
31+
- name: Setup Python virtualenv
32+
run: |
33+
python3 -m venv .venv
34+
.venv/bin/pip install --upgrade pip setuptools
35+
.venv/bin/pip install ruff mypy types-requests
36+
37+
- name: Check ruff formating
38+
run: .venv/bin/ruff format --diff vault_oidc_ssh_cert_action.py
39+
40+
- name: Check ruff linting
41+
run: .venv/bin/ruff check vault_oidc_ssh_cert_action.py
42+
43+
- name: Check type hints
44+
run: .venv/bin/mypy --strict vault_oidc_ssh_cert_action.py
45+
46+
super:
1947
name: Super-Linter
2048
runs-on: ubuntu-latest
2149

50+
permissions:
51+
contents: read
52+
statuses: write
53+
2254
steps:
2355
- name: Checkout
2456
uses: actions/checkout@v4
@@ -29,6 +61,10 @@ jobs:
2961
uses: super-linter/super-linter/slim@v6
3062
env:
3163
VALIDATE_ALL_CODEBASE: true
32-
VALIDATE_SHELL_SHFMT: false
64+
VALIDATE_PYTHON_BLACK: false
65+
VALIDATE_PYTHON_FLAKE8: false
66+
VALIDATE_PYTHON_ISORT: false
67+
VALIDATE_PYTHON_MYPY: false
68+
VALIDATE_PYTHON_PYLINT: false
3369
DEFAULT_BRANCH: main
3470
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*~
22
\#*#
33
.#*
4+
5+
*.pyc
6+
.venv/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Generate SSH client certificate
2020
if: github.ref == 'refs/heads/main'
2121
id: ssh_cert
22-
uses: andreaso/vault-oidc-ssh-cert-action@v0.10
22+
uses: andreaso/vault-oidc-ssh-cert-action@v0.11
2323
with:
2424
vault_server: https://vault.example.com:8200
2525
oidc_backend_path: github-oidc

action.yaml

+12-45
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,26 @@ inputs:
2727
outputs:
2828
cert_path:
2929
description: Full path to the generated SSH certificate
30-
value: ${{ steps.generator.outputs.cert_path }}
30+
value: ${{ steps.run_action.outputs.cert_path }}
3131
key_path:
3232
description: Full path to the corresponding private SSH key
33-
value: ${{ steps.generator.outputs.key_path }}
33+
value: ${{ steps.run_action.outputs.key_path }}
3434

3535
runs:
3636
using: composite
3737
steps:
38-
- name: Determine JWT audience
39-
id: determine
40-
run: |
41-
import os
42-
from urllib.parse import urlparse
43-
aud = os.environ["JWT_AUDIENCE"].strip()
44-
if not aud:
45-
url = os.environ["VAULT_SERVER"]
46-
fqdn = urlparse(url).netloc.split(":")[0]
47-
aud = fqdn
48-
with open(os.environ["GITHUB_OUTPUT"], "a") as ghof:
49-
ghof.write(f"audience={aud}\n")
38+
- name: Run Action
39+
id: run_action
5040
shell: python
41+
run: |
42+
import vault_oidc_ssh_cert_action
43+
vault_oidc_ssh_cert_action.run()
5144
env:
45+
PYTHONPATH: ${{ github.action_path }}
5246
JWT_AUDIENCE: ${{ inputs.jwt_audience }}
53-
VAULT_SERVER: ${{ inputs.vault_server }}
54-
55-
- name: Use GitHub OIDC to authenticate towards Vault
56-
id: vault_auth
57-
shell: bash
58-
run: "${ACTION_PATH}/github-vault-auth"
59-
env:
60-
ACTION_PATH: ${{ github.action_path }}
61-
AUDIENCE: ${{ steps.determine.outputs.audience }}
62-
BACKEND: ${{ inputs.oidc_backend_path }}
63-
ROLE: ${{ inputs.oidc_role }}
64-
VAULT_SERVER: ${{ inputs.vault_server }}
65-
66-
- name: Generate and sign SSH client certificate
67-
id: generator
68-
shell: bash
69-
run: "${ACTION_PATH}/generate-and-sign"
70-
env:
71-
ACTION_PATH: ${{ github.action_path }}
72-
VAULT_SERVER: ${{ inputs.vault_server }}
73-
VAULT_TOKEN: ${{ steps.vault_auth.outputs.vault_token }}
74-
SSH_BACKEND: ${{ inputs.ssh_backend_path }}
47+
OIDC_BACKEND_PATH: ${{ inputs.oidc_backend_path }}
48+
OIDC_ROLE: ${{ inputs.oidc_role }}
49+
SSH_BACKEND_PATH: ${{ inputs.ssh_backend_path }}
7550
SSH_ROLE: ${{ inputs.ssh_role }}
76-
TMPDIR: ${{ runner.temp }}
77-
78-
- name: Revoke Vault token
79-
if: success() || steps.generator.conclusion == 'failure'
80-
shell: bash
81-
run: |
82-
curl --fail --silent --show-error --tlsv1.3 --header "X-Vault-Token: ${VAULT_TOKEN}" --data "" "${VAULT_SERVER%/}/v1/auth/token/revoke-self"
83-
env:
8451
VAULT_SERVER: ${{ inputs.vault_server }}
85-
VAULT_TOKEN: ${{ steps.vault_auth.outputs.vault_token }}
52+
TMPDIR: ${{ runner.temp }}

generate-and-sign

-39
This file was deleted.

github-vault-auth

-35
This file was deleted.

0 commit comments

Comments
 (0)