Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
252ac1e1
Commit
252ac1e1
authored
4 years ago
by
Michael Schurter
Browse files
Options
Download
Email Patches
Plain Diff
e2e: test template path interpolation
parent
5b83ca0b
Branches unavailable
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.4.0-rc.1
v1.4.0-beta.1
v1.3.8
v1.3.7
v1.3.6
v1.3.5
v1.3.4
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc.1
v1.3.0-beta.1
v1.2.15
v1.2.14
v1.2.13
v1.2.12
v1.2.11
v1.2.10
v1.2.9
v1.2.8
v1.2.7
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc1
v1.2.0-beta1
v1.1.18
v1.1.17
v1.1.16
v1.1.15
v1.1.14
v1.1.13
v1.1.12
v1.1.11
v1.1.10
v1.1.9
v1.1.8
v1.1.7
v1.1.6
v1.1.5
v1.1.4
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.1.0-rc1
v1.1.0-beta1
v1.0.18
v1.0.17
v1.0.16
v1.0.15
v1.0.14
v1.0.13
v1.0.12
v1.0.11
v1.0.10
v1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
v1.0.0-rc1
nightly
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
e2e/consultemplate/consultemplate.go
+64
-0
e2e/consultemplate/consultemplate.go
e2e/consultemplate/input/bad_template_paths.nomad
+37
-0
e2e/consultemplate/input/bad_template_paths.nomad
e2e/consultemplate/input/template_paths.nomad
+37
-0
e2e/consultemplate/input/template_paths.nomad
with
138 additions
and
0 deletions
+138
-0
e2e/consultemplate/consultemplate.go
+
64
-
0
View file @
252ac1e1
...
...
@@ -7,10 +7,13 @@ import (
"time"
capi
"github.com/hashicorp/consul/api"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/e2e/e2eutil"
e2e
"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/e2e/framework"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/jobspec"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
)
...
...
@@ -223,6 +226,67 @@ job: {{ env "NOMAD_JOB_NAME" }}
}
}
// TestTemplatePathInterpolation_Ok asserts that NOMAD_*_DIR variables are
// properly interpolated into template source and destination paths without
// being treated as escaping.
func
(
tc
*
ConsulTemplateTest
)
TestTemplatePathInterpolation_Ok
(
f
*
framework
.
F
)
{
jobID
:=
"template-paths-"
+
uuid
.
Generate
()[
:
8
]
tc
.
jobIDs
=
append
(
tc
.
jobIDs
,
jobID
)
allocStubs
:=
e2eutil
.
RegisterAndWaitForAllocs
(
f
.
T
(),
tc
.
Nomad
(),
"consultemplate/input/template_paths.nomad"
,
jobID
,
""
)
f
.
Len
(
allocStubs
,
1
)
allocID
:=
allocStubs
[
0
]
.
ID
e2eutil
.
WaitForAllocRunning
(
f
.
T
(),
tc
.
Nomad
(),
allocID
)
f
.
NoError
(
waitForTemplateRender
(
allocID
,
"task/secrets/foo/dst"
,
func
(
out
string
)
bool
{
return
len
(
out
)
>
0
},
nil
),
"expected file to have contents"
)
}
// TestTemplatePathInterpolation_Bad asserts that template.source paths are not
// allowed to escape the sandbox directory tree by default.
func
(
tc
*
ConsulTemplateTest
)
TestTemplatePathInterpolation_Bad
(
f
*
framework
.
F
)
{
wc
:=
&
e2e
.
WaitConfig
{}
interval
,
retries
:=
wc
.
OrDefault
()
jobID
:=
"bad-template-paths-"
+
uuid
.
Generate
()[
:
8
]
tc
.
jobIDs
=
append
(
tc
.
jobIDs
,
jobID
)
allocStubs
:=
e2eutil
.
RegisterAndWaitForAllocs
(
f
.
T
(),
tc
.
Nomad
(),
"consultemplate/input/bad_template_paths.nomad"
,
jobID
,
""
)
f
.
Len
(
allocStubs
,
1
)
allocID
:=
allocStubs
[
0
]
.
ID
// Wait for alloc to fail
var
err
error
var
alloc
*
api
.
Allocation
testutil
.
WaitForResultRetries
(
retries
,
func
()
(
bool
,
error
)
{
time
.
Sleep
(
interval
)
alloc
,
_
,
err
=
tc
.
Nomad
()
.
Allocations
()
.
Info
(
allocID
,
nil
)
if
err
!=
nil
{
return
false
,
err
}
return
alloc
.
ClientStatus
==
structs
.
AllocClientStatusFailed
,
fmt
.
Errorf
(
"expected status failed, but was: %s"
,
alloc
.
ClientStatus
)
},
func
(
err
error
)
{
f
.
T
()
.
Fatalf
(
"failed to wait on alloc: %v"
,
err
)
})
// Assert the "source escapes" error occurred to prevent false
// positives.
found
:=
false
for
_
,
event
:=
range
alloc
.
TaskStates
[
"task"
]
.
Events
{
if
strings
.
Contains
(
event
.
DisplayMessage
,
"template source path escapes alloc directory"
)
{
found
=
true
break
}
}
f
.
True
(
found
,
"alloc failed but NOT due to expected source path escape error"
)
}
// waitForTemplateRender is a helper that grabs a file via alloc fs
// and tests it for
func
waitForTemplateRender
(
allocID
,
path
string
,
test
func
(
string
)
bool
,
wc
*
e2e
.
WaitConfig
)
error
{
...
...
This diff is collapsed.
Click to expand it.
e2e/consultemplate/input/bad_template_paths.nomad
0 → 100644
+
37
-
0
View file @
252ac1e1
job
"bad-template-paths"
{
datacenters
=
[
"dc1"
,
"dc2"
]
constraint
{
attribute
=
"${attr.kernel.name}"
value
=
"linux"
}
group
"template-paths"
{
restart
{
attempts
=
0
mode
=
"fail"
}
task
"task"
{
driver
=
"docker"
config
{
image
=
"busybox:1"
command
=
"/bin/sh"
args
=
[
"-c"
,
"sleep 300"
]
}
template
{
source
=
"/etc/passwd"
destination
=
"${NOMAD_SECRETS_DIR}/foo/dst"
}
resources
{
cpu
=
128
memory
=
64
}
}
}
}
This diff is collapsed.
Click to expand it.
e2e/consultemplate/input/template_paths.nomad
0 → 100644
+
37
-
0
View file @
252ac1e1
job
"template-paths"
{
datacenters
=
[
"dc1"
,
"dc2"
]
constraint
{
attribute
=
"${attr.kernel.name}"
value
=
"linux"
}
group
"template-paths"
{
task
"task"
{
driver
=
"docker"
config
{
image
=
"busybox:1"
command
=
"/bin/sh"
args
=
[
"-c"
,
"sleep 300"
]
}
artifact
{
source
=
"https://google.com"
destination
=
"local/foo/src"
}
template
{
source
=
"${NOMAD_TASK_DIR}/foo/src"
destination
=
"${NOMAD_SECRETS_DIR}/foo/dst"
}
resources
{
cpu
=
128
memory
=
64
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help