Skip to content

Commit dc3eeef

Browse files
authored
Support URLs in hostDir policies (#146)
* Support URLs in hostDir policies We can't just blindly allow remote URLs since they might contain symlinks leading to outside the archive. Instead, let's support specifying URLs where the remote archive can come from. Fixes #145 * Ignore Lint issue * Reverted old validation logic
1 parent 7c2c466 commit dc3eeef

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

pkg/resource/v1/host_dir_policy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ type HostDirPolicy struct {
1414
}
1515

1616
func NewHostDirPolicyFromString(s string) (HostDirPolicy, error) {
17+
if strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://") {
18+
return HostDirPolicy{
19+
PathPrefix: strings.TrimSuffix(s, ":ro"),
20+
ReadOnly: strings.HasSuffix(s, ":ro"),
21+
}, nil
22+
}
23+
1724
parts := strings.Split(s, ":")
1825

1926
if len(parts) > 2 {

pkg/resource/v1/host_dir_policy_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,14 @@ func TestHostDirPolicyString(t *testing.T) {
6161
policyRo := &v1.HostDirPolicy{PathPrefix: "/Users/ci/src", ReadOnly: true}
6262
require.EqualValues(t, "/Users/ci/src:ro", policyRo.String())
6363
}
64+
65+
func TestHTTPHostDirPolicyString(t *testing.T) {
66+
policy, err := v1.NewHostDirPolicyFromString("https://github.com/actions/runner/releases/download")
67+
require.NoError(t, err)
68+
require.EqualValues(t, v1.HostDirPolicy{
69+
PathPrefix: "https://github.com/actions/runner/releases/download",
70+
ReadOnly: false,
71+
}, policy)
72+
//nolint: lll
73+
require.True(t, policy.Validate("https://github.com/actions/runner/releases/download/v2.309.0/actions-runner-osx-arm64-2.309.0.tar.gz", false))
74+
}

0 commit comments

Comments
 (0)