-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[allow-insecure] Allow insecure packages with --allow-insecure flag (#…
…1265) ## Summary This allows installing insecure packages using the `--allow-insecure` flag: `devbox add nodejs@16 --allow-insecure` This saves the allow insecure state to lock file. If user tries to do add/shell/run/install and there are insecure pacakges that are not in marked in lock file, they will see an error indicating they should use flag. I used flag (instead of prompt) to limit the size of this already massive PR. TODO (in follow up): * When installing an insecure package, ask the user if they want to allow it, update the devbox.json, and install it. ## How was it tested? ```bash devbox add nodejs@16 devbox add nodejs@16 --allow-insecure devbox run run_test # edited lockfile to remove allow_insecure devbox run run_test # error devbox install # error devbox shell # error ``` See examples/insecure
- Loading branch information
1 parent
89b6055
commit 95ee457
Showing
20 changed files
with
316 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
"nixpkgs": { | ||
"commit": "3364b5b117f65fe1ce65a3cdd5612a078a3b31e3" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"packages": [ | ||
"nodejs@16" | ||
], | ||
"shell": { | ||
"init_hook": [ | ||
"echo 'Welcome to devbox!' > /dev/null" | ||
], | ||
"scripts": { | ||
"run_test": [ | ||
"node --version" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"lockfile_version": "1", | ||
"packages": { | ||
"nodejs@16": { | ||
"allow_insecure": true, | ||
"last_modified": "2023-06-29T16:20:38Z", | ||
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#nodejs_16", | ||
"source": "devbox-search", | ||
"version": "16.20.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package nix | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func EvalPackageName(path string) (string, error) { | ||
cmd := command("eval", "--raw", path+".name") | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(out), nil | ||
} | ||
|
||
// PackageIsInsecure is a fun little nix eval that maybe works. | ||
func PackageIsInsecure(path string) bool { | ||
cmd := command("eval", path+".meta.insecure") | ||
out, err := cmd.Output() | ||
if err != nil { | ||
// We can't know for sure, but probably not. | ||
return false | ||
} | ||
var insecure bool | ||
if err := json.Unmarshal(out, &insecure); err != nil { | ||
// We can't know for sure, but probably not. | ||
return false | ||
} | ||
return insecure | ||
} | ||
|
||
func PackageKnownVulnerabilities(path string) []string { | ||
cmd := command("eval", path+".meta.knownVulnerabilities") | ||
out, err := cmd.Output() | ||
if err != nil { | ||
// We can't know for sure, but probably not. | ||
return nil | ||
} | ||
var vulnerabilities []string | ||
if err := json.Unmarshal(out, &vulnerabilities); err != nil { | ||
// We can't know for sure, but probably not. | ||
return nil | ||
} | ||
return vulnerabilities | ||
} | ||
|
||
func AllowInsecurePackages() { | ||
os.Setenv("NIXPKGS_ALLOW_INSECURE", "1") | ||
} | ||
|
||
func IsInsecureAllowed() bool { | ||
allowed, _ := strconv.ParseBool(os.Getenv("NIXPKGS_ALLOW_INSECURE")) | ||
return allowed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.