Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
eff134cd
Unverified
Commit
eff134cd
authored
Jan 02, 2017
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use chmod to bypass umask on termination log file
os.Create() will obey the umask which results in the file being 0644 when injected in the container.
parent
24473417
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
4 deletions
+32
-4
os.go
pkg/kubelet/container/os.go
+7
-0
os.go
pkg/kubelet/container/testing/os.go
+5
-0
docker_manager.go
pkg/kubelet/dockertools/docker_manager.go
+10
-3
kuberuntime_container.go
pkg/kubelet/kuberuntime/kuberuntime_container.go
+10
-1
No files found.
pkg/kubelet/container/os.go
View file @
eff134cd
...
@@ -32,6 +32,7 @@ type OSInterface interface {
...
@@ -32,6 +32,7 @@ type OSInterface interface {
Remove
(
path
string
)
error
Remove
(
path
string
)
error
RemoveAll
(
path
string
)
error
RemoveAll
(
path
string
)
error
Create
(
path
string
)
(
*
os
.
File
,
error
)
Create
(
path
string
)
(
*
os
.
File
,
error
)
Chmod
(
path
string
,
perm
os
.
FileMode
)
error
Hostname
()
(
name
string
,
err
error
)
Hostname
()
(
name
string
,
err
error
)
Chtimes
(
path
string
,
atime
time
.
Time
,
mtime
time
.
Time
)
error
Chtimes
(
path
string
,
atime
time
.
Time
,
mtime
time
.
Time
)
error
Pipe
()
(
r
*
os
.
File
,
w
*
os
.
File
,
err
error
)
Pipe
()
(
r
*
os
.
File
,
w
*
os
.
File
,
err
error
)
...
@@ -73,6 +74,12 @@ func (RealOS) Create(path string) (*os.File, error) {
...
@@ -73,6 +74,12 @@ func (RealOS) Create(path string) (*os.File, error) {
return
os
.
Create
(
path
)
return
os
.
Create
(
path
)
}
}
// Chmod will change the permissions on the specified path or return
// an error.
func
(
RealOS
)
Chmod
(
path
string
,
perm
os
.
FileMode
)
error
{
return
os
.
Chmod
(
path
,
perm
)
}
// Hostname will call os.Hostname to return the hostname.
// Hostname will call os.Hostname to return the hostname.
func
(
RealOS
)
Hostname
()
(
name
string
,
err
error
)
{
func
(
RealOS
)
Hostname
()
(
name
string
,
err
error
)
{
return
os
.
Hostname
()
return
os
.
Hostname
()
...
...
pkg/kubelet/container/testing/os.go
View file @
eff134cd
...
@@ -83,6 +83,11 @@ func (FakeOS) Create(path string) (*os.File, error) {
...
@@ -83,6 +83,11 @@ func (FakeOS) Create(path string) (*os.File, error) {
return
nil
,
nil
return
nil
,
nil
}
}
// Chmod is a fake call that returns nil.
func
(
FakeOS
)
Chmod
(
path
string
,
perm
os
.
FileMode
)
error
{
return
nil
}
// Hostname is a fake call that returns nil.
// Hostname is a fake call that returns nil.
func
(
f
*
FakeOS
)
Hostname
()
(
name
string
,
err
error
)
{
func
(
f
*
FakeOS
)
Hostname
()
(
name
string
,
err
error
)
{
return
f
.
HostName
,
nil
return
f
.
HostName
,
nil
...
...
pkg/kubelet/dockertools/docker_manager.go
View file @
eff134cd
...
@@ -672,17 +672,24 @@ func (dm *DockerManager) runContainer(
...
@@ -672,17 +672,24 @@ func (dm *DockerManager) runContainer(
fs
,
err
:=
os
.
Create
(
containerLogPath
)
fs
,
err
:=
os
.
Create
(
containerLogPath
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO: Clean up the previously created dir? return the error?
// TODO: Clean up the previously created dir? return the error?
glog
.
Errorf
(
"Error on creating termination-log file %q: %v"
,
containerLogPath
,
err
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"error creating termination-log file %q: %v"
,
containerLogPath
,
err
)
)
}
else
{
}
else
{
fs
.
Close
()
// Close immediately; we're just doing a `touch` here
fs
.
Close
()
// Close immediately; we're just doing a `touch` here
b
:=
fmt
.
Sprintf
(
"%s:%s"
,
containerLogPath
,
container
.
TerminationMessagePath
)
// Chmod is needed because ioutil.WriteFile() ends up calling
// open(2) to create the file, so the final mode used is "mode &
// ~umask". But we want to make sure the specified mode is used
// in the file no matter what the umask is.
if
err
:=
os
.
Chmod
(
containerLogPath
,
0666
);
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unable to set termination-log file permissions %q: %v"
,
containerLogPath
,
err
))
}
// Have docker relabel the termination log path if SELinux is
// Have docker relabel the termination log path if SELinux is
// enabled.
// enabled.
b
:=
fmt
.
Sprintf
(
"%s:%s"
,
containerLogPath
,
container
.
TerminationMessagePath
)
if
selinux
.
SELinuxEnabled
()
{
if
selinux
.
SELinuxEnabled
()
{
b
+=
":Z"
b
+=
":Z"
}
}
binds
=
append
(
binds
,
b
)
binds
=
append
(
binds
,
b
)
}
}
}
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_container.go
View file @
eff134cd
...
@@ -272,9 +272,18 @@ func (m *kubeGenericRuntimeManager) makeMounts(opts *kubecontainer.RunContainerO
...
@@ -272,9 +272,18 @@ func (m *kubeGenericRuntimeManager) makeMounts(opts *kubecontainer.RunContainerO
containerLogPath
:=
filepath
.
Join
(
opts
.
PodContainerDir
,
cid
)
containerLogPath
:=
filepath
.
Join
(
opts
.
PodContainerDir
,
cid
)
fs
,
err
:=
m
.
osInterface
.
Create
(
containerLogPath
)
fs
,
err
:=
m
.
osInterface
.
Create
(
containerLogPath
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error on creating termination-log file %q: %v"
,
containerLogPath
,
err
)
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"error on creating termination-log file %q: %v"
,
containerLogPath
,
err
)
)
}
else
{
}
else
{
fs
.
Close
()
fs
.
Close
()
// Chmod is needed because ioutil.WriteFile() ends up calling
// open(2) to create the file, so the final mode used is "mode &
// ~umask". But we want to make sure the specified mode is used
// in the file no matter what the umask is.
if
err
:=
m
.
osInterface
.
Chmod
(
containerLogPath
,
0666
);
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unable to set termination-log file permissions %q: %v"
,
containerLogPath
,
err
))
}
selinuxRelabel
:=
selinux
.
SELinuxEnabled
()
selinuxRelabel
:=
selinux
.
SELinuxEnabled
()
volumeMounts
=
append
(
volumeMounts
,
&
runtimeapi
.
Mount
{
volumeMounts
=
append
(
volumeMounts
,
&
runtimeapi
.
Mount
{
HostPath
:
containerLogPath
,
HostPath
:
containerLogPath
,
...
...
Write
Preview
Markdown
is supported
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