Skip to content

Commit 86e92ba

Browse files
authored
Fixed permissions on gaia created folders and pipelines. (#190)
* Fixed permissions on gaia created folders and pipelines. * Ran go mod tidy and handling errors * removed error handling lol
1 parent e766c3d commit 86e92ba

12 files changed

+33
-16
lines changed

gaia.go

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ const (
136136

137137
// WorkerRegisterKey is the used key for worker registration secret
138138
WorkerRegisterKey = "WORKER_REGISTER_KEY"
139+
140+
// ExecutablePermission is the permission used for gaia created executables.
141+
ExecutablePermission = 0700
139142
)
140143

141144
// User is the user object

handlers/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
ignoredVaultKeys []string
3232
)
3333

34-
// InitHandlers initializes(registers) all handlers
34+
// InitHandlers initializes(registers) all handlers.
3535
func InitHandlers(e *echo.Echo) error {
3636
// Define prefix
3737
p := "/api/" + gaia.APIVersion + "/"

handlers/pipeline_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ Xbs5AQIEIzWnmQIFAOEml+E=
129129
})
130130
hostConfig := "github.comom,1.2.3.4 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
131131
knownHostsLocation := filepath.Join(dataDir, ".known_hosts")
132-
ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), 0766)
132+
err := ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), gaia.ExecutablePermission)
133+
if err != nil {
134+
t.Fatal(err)
135+
}
133136
os.Setenv("SSH_KNOWN_HOSTS", knownHostsLocation)
134137
repoURL := "github.com:gaia-pipeline/pipeline-test"
135138
gr := gaia.GitRepo{
@@ -818,7 +821,7 @@ func TestPipelineNameAvailable(t *testing.T) {
818821
q.Add("name", "pipeline a")
819822
req.URL.RawQuery = q.Encode()
820823

821-
PipelineNameAvailable(c)
824+
_ = PipelineNameAvailable(c)
822825

823826
if rec.Code != http.StatusBadRequest {
824827
t.Fatalf("expected response code %v got %v", http.StatusBadRequest, rec.Code)

workers/agent/agent.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func (a *Agent) streamBinary(pipelineRunPB *pb.PipelineRun, pipelinePath string)
529529
}
530530

531531
// Set pipeline executable rights
532-
return os.Chmod(pipelinePath, 0766)
532+
return os.Chmod(pipelinePath, gaia.ExecutablePermission)
533533
}
534534

535535
// updateWork is function that is periodically called and it is used to

workers/pipeline/build_cpp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (b *BuildPipelineCpp) CopyBinary(p *gaia.CreatePipeline) error {
8989
}
9090

9191
// Set +x (execution right) for pipeline
92-
return os.Chmod(dest, 0766)
92+
return os.Chmod(dest, gaia.ExecutablePermission)
9393
}
9494

9595
// SavePipeline saves the current pipeline configuration.

workers/pipeline/build_golang.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (b *BuildPipelineGolang) CopyBinary(p *gaia.CreatePipeline) error {
111111
}
112112

113113
// Set +x (execution right) for pipeline
114-
return os.Chmod(dest, 0766)
114+
return os.Chmod(dest, gaia.ExecutablePermission)
115115
}
116116

117117
// SavePipeline saves the current pipeline configuration.

workers/pipeline/build_java.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (b *BuildPipelineJava) CopyBinary(p *gaia.CreatePipeline) error {
100100
}
101101

102102
// Set +x (execution right) for pipeline
103-
return os.Chmod(dest, 0766)
103+
return os.Chmod(dest, gaia.ExecutablePermission)
104104
}
105105

106106
// SavePipeline saves the current pipeline configuration.

workers/pipeline/build_nodejs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
uuid "github.com/satori/go.uuid"
1313
)
1414

15-
const nodeJSInternalCloneFolder = "jsclone"
15+
const nodeJSInternalCloneFolder = "jsclone"
1616

1717
// BuildPipelineNodeJS is the real implementation of BuildPipeline for NodeJS
1818
type BuildPipelineNodeJS struct {
@@ -99,7 +99,7 @@ func (b *BuildPipelineNodeJS) CopyBinary(p *gaia.CreatePipeline) error {
9999
}
100100

101101
// Set +x (execution right) for pipeline
102-
return os.Chmod(dest, 0766)
102+
return os.Chmod(dest, gaia.ExecutablePermission)
103103
}
104104

105105
// SavePipeline saves the current pipeline configuration.

workers/pipeline/build_python.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (b *BuildPipelinePython) CopyBinary(p *gaia.CreatePipeline) error {
131131
}
132132

133133
// Set +x (execution right) for pipeline
134-
return os.Chmod(dest, 0766)
134+
return os.Chmod(dest, gaia.ExecutablePermission)
135135
}
136136

137137
// SavePipeline saves the current pipeline configuration.

workers/pipeline/build_ruby.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (b *BuildPipelineRuby) CopyBinary(p *gaia.CreatePipeline) error {
178178
}
179179

180180
// Set +x (execution right) for pipeline
181-
return os.Chmod(dest, 0766)
181+
return os.Chmod(dest, gaia.ExecutablePermission)
182182
}
183183

184184
// SavePipeline saves the current pipeline configuration.

workers/pipeline/build_ruby_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestExecuteBuildRuby(t *testing.T) {
6767
t.Fatal(err)
6868
}
6969
libFolder := filepath.Join(tmp, "lib")
70-
if err := os.MkdirAll(libFolder, 0766); err != nil {
70+
if err := os.MkdirAll(libFolder, gaia.ExecutablePermission); err != nil {
7171
t.Fatal(err)
7272
}
7373
initFile := filepath.Join(libFolder, gemInitFile)
@@ -115,7 +115,7 @@ func TestExecuteBuildContextTimeoutRuby(t *testing.T) {
115115
}
116116
f.Close()
117117
libFolder := filepath.Join(tmp, "lib")
118-
if err = os.MkdirAll(libFolder, 0766); err != nil {
118+
if err = os.MkdirAll(libFolder, gaia.ExecutablePermission); err != nil {
119119
t.Fatal(err)
120120
}
121121
initFile := filepath.Join(libFolder, gemInitFile)

workers/pipeline/git_test.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ Xbs5AQIEIzWnmQIFAOEml+E=
118118
}
119119
hostConfig := "notgithub.comom,192.30.252.130 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
120120
knownHostsLocation := filepath.Join(tmp, ".known_hosts")
121-
ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), 0766)
121+
err := ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), gaia.ExecutablePermission)
122+
if err != nil {
123+
t.Fatal(err)
124+
}
125+
122126
os.Setenv("SSH_KNOWN_HOSTS", knownHostsLocation)
123127

124128
// always ensure that tmp folder is cleaned up
@@ -159,7 +163,11 @@ Xbs5AQIEIzWnmQIFAOEml+E=
159163
}
160164
hostConfig := "github.com,192.30.252.130 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
161165
knownHostsLocation := filepath.Join(tmp, ".known_hosts")
162-
ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), 0766)
166+
err := ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), gaia.ExecutablePermission)
167+
if err != nil {
168+
t.Fatal(err)
169+
}
170+
163171
os.Setenv("SSH_KNOWN_HOSTS", knownHostsLocation)
164172

165173
// always ensure that tmp folder is cleaned up
@@ -174,7 +182,10 @@ Xbs5AQIEIzWnmQIFAOEml+E=
174182
GlobalActivePipelines = NewActivePipelines()
175183
GlobalActivePipelines.Append(*p)
176184
hostConfig = "invalid.com,192.30.252.130 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
177-
ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), 0766)
185+
err = ioutil.WriteFile(knownHostsLocation, []byte(hostConfig), gaia.ExecutablePermission)
186+
if err != nil {
187+
t.Fatal(err)
188+
}
178189
updateAllCurrentPipelines()
179190
want := "knownhosts: key is unknown"
180191
if !strings.Contains(b.String(), want) {

0 commit comments

Comments
 (0)