Skip to content

Commit 61d2348

Browse files
Merge pull request #103 from pluralsh/mjg/eng-179-add-way-to-prevent-recipes-from-being
Don't allow restricted bundles to be installed in cloud shell
2 parents c0a428e + 22efad6 commit 61d2348

6 files changed

Lines changed: 21 additions & 4 deletions

File tree

cmd/plural/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func doBuild(client *api.Client, installation *api.Installation, force bool) err
132132
fmt.Printf("Building workspace for %s\n", repoName)
133133

134134
if !wkspace.Configured(repoName) {
135-
return fmt.Errorf("You have not locally configured %s but have it registered as an installation, either delete it in app.plural.sh or install it locally via a bundle in `plural bundle list %s`", repoName, repoName)
135+
return fmt.Errorf("You have not locally configured %s but have it registered as an installation in our api, either delete it in app.plural.sh or install it locally via a bundle in `plural bundle list %s`", repoName, repoName)
136136
}
137137

138138
workspace, err := wkspace.New(client, installation)

pkg/api/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ type Recipe struct {
168168
Name string
169169
Provider string
170170
Description string
171+
Restricted bool
171172
Tests []*RecipeTest
172173
Repository *Repository
173174
RecipeSections []*RecipeSection
@@ -486,6 +487,7 @@ const RecipeFragment = `
486487
id
487488
name
488489
description
490+
restricted
489491
provider
490492
tests {
491493
type

pkg/api/recipes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type RecipeInput struct {
99
Name string
1010
Description string
1111
Provider string
12+
Restricted bool
1213
Tests []RecipeTestInput `yaml:"tests",json:"tests,omitempty"`
1314
Sections []RecipeSectionInput
1415
Dependencies []DependencyInput

pkg/bundle/installer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bundle
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/inancgumus/screen"
78
"github.com/pluralsh/plural/pkg/api"
@@ -17,6 +18,10 @@ func Install(repo, name string, refresh bool) error {
1718
return err
1819
}
1920

21+
if recipe.Restricted && os.Getenv("CLOUD_SHELL") == "1" {
22+
return fmt.Errorf("Cannot install this bundle in cloud shell, this is often because it requires a file locally available on your machine like a git ssh key")
23+
}
24+
2025
path := manifest.ContextPath()
2126
context, err := manifest.ReadContext(path)
2227
if err != nil {

pkg/bundle/tests/git.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func authMethod(args map[string]*ContextValue) (transport.AuthMethod, error) {
5151
passphrase = passArg.Val.(string)
5252
}
5353

54-
user, _, _, _ := git.UrlComponents(url)
54+
user, _, _, _, err := git.UrlComponents(url)
55+
if err != nil {
56+
return nil, err
57+
}
5558
return git.SSHAuth(user, pk, passphrase)
5659
}

pkg/utils/git/auth.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package git
22

33
import (
4+
"fmt"
45
"regexp"
56

67
"github.com/go-git/go-git/v5/plumbing/transport"
@@ -13,9 +14,14 @@ var (
1314
scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})(?:\/|:))?(?P<path>[^\\].*\/[^\\].*)$`)
1415
)
1516

16-
func UrlComponents(url string) (user, host, port, path string) {
17+
func UrlComponents(url string) (user, host, port, path string, err error) {
1718
m := scpLikeUrlRegExp.FindStringSubmatch(url)
18-
return m[1], m[2], m[3], m[4]
19+
if len(m) < 5 {
20+
err = fmt.Errorf("%s is not a valid git ssh url", url)
21+
return
22+
}
23+
24+
return m[1], m[2], m[3], m[4], nil
1925
}
2026

2127
func BasicAuth(user, password string) (transport.AuthMethod, error) {

0 commit comments

Comments
 (0)