Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Verify the runner's host and re-check the job it is given

f5456470d22fb7ca06197a8856ed0da7fc56fdd2 · Keenan Nemetz · 12d ago · parent edf9db6e

Verify the runner's host and re-check the job it is given

A runner executes repository code, so the instance it talks to decides what
runs on it. The client built ssh command lines with no host-key policy: a
man in the middle, or a loose known_hosts, could answer in the instance's
place and feed a runner any job it liked.

Host keys are now verified against known_hosts by default, for the
runner's control channel, for git's own clone/fetch/push and for the LFS
transfer. `--known-hosts` names a file instead of the default,
VOLE_KNOWN_HOSTS does the same for every command, and
`--insecure-host-key` / VOLE_INSECURE_HOST_KEY is the explicit override
for tests and throwaway instances, with a warning when it is used. The
options are placed before any configured ones because ssh takes the first
value for an option, so GIT_SSH_COMMAND or VOLE_SSH_COMMAND cannot
quietly turn the check off. The test package opts out once, in TestMain,
rather than every fixture learning to trust everything.

The runner also re-checks the job it leases before acting on it. The
server validated the workflow at push time, but the runner is the party
that turns the payload into paths, container arguments and scripts. Run
id, repository, attempt, commit, ref, branch, tag, workflow and job names,
image (or image-file plus its pinned digest), steps, artifact patterns,
pages path and environment are all validated; a malformed job stops the
runner with the reason instead of being built from.

The artifact and pages path rules move into ci/validate.go, so the
push-time check and the runner use one implementation rather than two
that can drift. Joining them also closes the gap the runner-side check
was for: `..`, absolute paths, `**`, globs where a directory belongs, and
control characters are refused identically on both sides.

Tests: strict-by-default and known_hosts options, the environment losing
to the explicit policy, the insecure override, and every job field
refused when it climbs out, is the wrong shape, or is missing.

ci/validate_test.go +88

@@ -0,0 +1,88 @@
1 package ci
2
3 import "testing"
4
5 func TestValidRefOnlyAcceptsBranchesAndTags(t *testing.T) {
6 t.Parallel()
7 for _, ok := range []string{
8 "refs/heads/main",
9 "refs/heads/feature/one",
10 "refs/heads/contrib/alice/patch",
11 "refs/tags/v1.0.0",
12 } {
13 if !ValidRef(ok) {
14 t.Fatalf("ValidRef(%q) = false", ok)
15 }
16 }
17 for _, bad := range []string{
18 "",
19 "main",
20 "HEAD",
21 "refs/remotes/origin/main",
22 "refs/heads/",
23 "refs/heads/../etc",
24 "refs/heads/a/../../b",
25 "refs/heads//empty",
26 "refs/heads/a..b",
27 "refs/heads/a b",
28 "refs/heads/a:b",
29 "refs/heads/a?b",
30 "refs/heads/a*b",
31 "refs/heads/a[b",
32 "refs/heads/a\\b",
33 "refs/heads/a\x00b",
34 "refs/heads/a\nb",
35 "refs/heads/a.lock",
36 "refs/heads/a.",
37 "refs/tags/a@{1}",
38 } {
39 if ValidRef(bad) {
40 t.Fatalf("ValidRef(%q) = true", bad)
41 }
42 }
43 }
44
45 func TestValidObjectID(t *testing.T) {
46 t.Parallel()
47 sha1 := "0123456789abcdef0123456789abcdef01234567"
48 sha256 := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
49 if !ValidObjectID(sha1) || !ValidObjectID(sha256) {
50 t.Fatal("a real object id was refused")
51 }
52 for _, bad := range []string{"", "abc", sha1[:39], sha1 + "0", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
53 "0123456789ABCDEF0123456789abcdef01234567"} {
54 if ValidObjectID(bad) {
55 t.Fatalf("ValidObjectID(%q) = true", bad)
56 }
57 }
58 }
59
60 func TestValidateArtifactPath(t *testing.T) {
61 t.Parallel()
62 for _, ok := range []string{"dist/*", "dist/*.tar.gz", "build/app", "a/b/c.txt"} {
63 if err := ValidateArtifactPath(ok); err != nil {
64 t.Fatalf("ValidateArtifactPath(%q) = %v", ok, err)
65 }
66 }
67 for _, bad := range []string{
68 "", "/etc/passwd", "../secret", "a/../../b", "dist/", "**/*.go", "a[b",
69 } {
70 if err := ValidateArtifactPath(bad); err == nil {
71 t.Fatalf("ValidateArtifactPath(%q) = nil", bad)
72 }
73 }
74 }
75
76 func TestValidatePagesPath(t *testing.T) {
77 t.Parallel()
78 for _, ok := range []string{"site", "dist/", "public/site"} {
79 if err := ValidatePagesPath(ok); err != nil {
80 t.Fatalf("ValidatePagesPath(%q) = %v", ok, err)
81 }
82 }
83 for _, bad := range []string{"", "/srv/site", "../site", "a/../../b", "site/*", "site:name", "site\x00"} {
84 if err := ValidatePagesPath(bad); err == nil {
85 t.Fatalf("ValidatePagesPath(%q) = nil", bad)
86 }
87 }
88 }