Skip to content

Commit da0cde9

Browse files
authored
Merge pull request #78 from chmeliik/network-isolation
image build: implement --hermetic
2 parents 6e1604c + c77c517 commit da0cde9

File tree

15 files changed

+1160
-16
lines changed

15 files changed

+1160
-16
lines changed

cmd/internal.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/konflux-ci/konflux-build-cli/cmd/internal"
7+
)
8+
9+
var internalCmdGroup = &cobra.Command{
10+
Use: "internal",
11+
Short: "Internal subcommands, not intended for direct use",
12+
Hidden: true,
13+
}
14+
15+
func init() {
16+
internalCmdGroup.AddCommand(internal.InUserNamespaceCmd)
17+
}

cmd/internal/in_user_namespace.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package internal
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/konflux-ci/konflux-build-cli/pkg/commands"
7+
l "github.com/konflux-ci/konflux-build-cli/pkg/logger"
8+
)
9+
10+
var InUserNamespaceCmd = &cobra.Command{
11+
Use: "in-user-namespace [flags] command [args...]",
12+
Short: "Run a command inside an externally created user namespace",
13+
Long: `Run a command inside an externally created user namespace
14+
(e.g. by unshare or 'buildah unshare').
15+
16+
Flags must come before the command. Everything after the first
17+
non-flag argument (or after --) is passed to the command as-is.`,
18+
Example: ` buildah unshare -- unshare --net -- konflux-build-cli internal in-user-namespace --loopback-up -- buildah build .`,
19+
Args: cobra.ArbitraryArgs,
20+
Run: func(cmd *cobra.Command, args []string) {
21+
loopbackUp, _ := cmd.Flags().GetBool("loopback-up")
22+
if err := commands.RunInUserNamespace(loopbackUp, args); err != nil {
23+
l.Logger.Fatal(err)
24+
}
25+
},
26+
}
27+
28+
func init() {
29+
InUserNamespaceCmd.Flags().SetInterspersed(false)
30+
InUserNamespaceCmd.Flags().Bool("loopback-up", false, "Bring up the loopback interface before executing the command")
31+
}

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ func init() {
5151
rootCmd.AddCommand(imageCmd)
5252
rootCmd.AddCommand(PrefetchDependenciesCmd)
5353
rootCmd.AddCommand(configCmd)
54+
rootCmd.AddCommand(internalCmdGroup)
5455
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/opencontainers/image-spec v1.1.1
1313
github.com/sirupsen/logrus v1.9.3
1414
github.com/spf13/cobra v1.9.1
15+
github.com/vishvananda/netlink v1.3.1
1516
gopkg.in/ini.v1 v1.67.1
1617
k8s.io/api v0.35.0
1718
k8s.io/apimachinery v0.35.0
@@ -47,6 +48,7 @@ require (
4748
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
4849
github.com/spf13/pflag v1.0.9 // indirect
4950
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 // indirect
51+
github.com/vishvananda/netns v0.0.5 // indirect
5052
github.com/x448/float16 v0.8.4 // indirect
5153
go.yaml.in/yaml/v2 v2.4.3 // indirect
5254
go.yaml.in/yaml/v3 v3.0.4 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
118118
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
119119
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 h1:7I5c2Ig/5FgqkYOh/N87NzoyI9U15qUPXhDD8uCupv8=
120120
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4/go.mod h1:278M4p8WsNh3n4a1eqiFcV2FGk7wE5fwUpUom9mK9lE=
121+
github.com/vishvananda/netlink v1.3.1 h1:3AEMt62VKqz90r0tmNhog0r/PpWKmrEShJU0wJW6bV0=
122+
github.com/vishvananda/netlink v1.3.1/go.mod h1:ARtKouGSTGchR8aMwmkzC0qiNPrrWO5JS/XMVl45+b4=
123+
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
124+
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
121125
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
122126
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
123127
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -150,6 +154,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
150154
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
151155
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
152156
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
157+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
158+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
153159
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
154160
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
155161
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=

0 commit comments

Comments
 (0)