Skip to content

Commit 5645113

Browse files
authored
Feature/x requirements log permission (#5238) (#5258)
* change log file default mode 0640 Signed-off-by: clyi <clyi@alauda.io>
1 parent eaee89f commit 5645113

File tree

13 files changed

+90
-5
lines changed

13 files changed

+90
-5
lines changed

cmd/controller/controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http/pprof"
99
"os"
1010
"slices"
11+
"strconv"
1112
"time"
1213

1314
v1 "k8s.io/api/authorization/v1"
@@ -46,6 +47,12 @@ func CmdMain() {
4647
util.LogFatalAndExit(err, "failed to parse config")
4748
}
4849

50+
perm, err := strconv.ParseUint(config.LogPerm, 8, 32)
51+
if err != nil {
52+
util.LogFatalAndExit(err, "failed to parse log-perm")
53+
}
54+
util.InitLogFilePerm("kube-ovn-controller", os.FileMode(perm))
55+
4956
if err := checkPermission(config); err != nil {
5057
util.LogFatalAndExit(err, "failed to check permission")
5158
}

cmd/daemon/cniserver.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"slices"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -28,7 +29,6 @@ import (
2829

2930
func main() {
3031
defer klog.Flush()
31-
3232
config := daemon.ParseFlags()
3333
klog.Info(versions.String())
3434

@@ -38,7 +38,11 @@ func main() {
3838
}
3939
return
4040
}
41-
41+
perm, err := strconv.ParseUint(config.LogPerm, 8, 32)
42+
if err != nil {
43+
util.LogFatalAndExit(err, "failed to parse log-perm")
44+
}
45+
util.InitLogFilePerm("kube-ovn-cni", os.FileMode(perm))
4246
printCaps()
4347

4448
ovs.UpdateOVSVsctlLimiter(config.OVSVsctlConcurrency)

cmd/ovn_ic_controller/ovn_ic_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package ovn_ic_controller
22

33
import (
4+
"os"
5+
"strconv"
6+
47
"k8s.io/klog/v2"
58
"kernel.org/pub/linux/libs/security/libcap/cap"
69
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
@@ -23,6 +26,12 @@ func CmdMain() {
2326
util.LogFatalAndExit(err, "failed to parse config")
2427
}
2528

29+
perm, err := strconv.ParseUint(config.LogPerm, 8, 32)
30+
if err != nil {
31+
util.LogFatalAndExit(err, "failed to parse log-perm")
32+
}
33+
util.InitLogFilePerm("kube-ovn-ic-controller", os.FileMode(perm))
34+
2635
stopCh := signals.SetupSignalHandler().Done()
2736
ctl := ovn_ic_controller.NewController(config)
2837
ctl.Run(stopCh)

cmd/ovn_monitor/ovn_monitor.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package ovn_monitor
33
import (
44
"net"
55
"net/http"
6+
"os"
7+
"strconv"
68
"time"
79

810
"k8s.io/klog/v2"
@@ -19,7 +21,6 @@ import (
1921

2022
func CmdMain() {
2123
defer klog.Flush()
22-
2324
klog.Info(versions.String())
2425

2526
currentCaps := cap.GetProc()
@@ -30,6 +31,12 @@ func CmdMain() {
3031
util.LogFatalAndExit(err, "failed to parse config")
3132
}
3233

34+
perm, err := strconv.ParseUint(config.LogPerm, 8, 32)
35+
if err != nil {
36+
util.LogFatalAndExit(err, "failed to parse log-perm")
37+
}
38+
util.InitLogFilePerm("kube-ovn-monitor", os.FileMode(perm))
39+
3340
ctrl.SetLogger(klog.NewKlogr())
3441
ctx := signals.SetupSignalHandler()
3542

cmd/pinger/pinger.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package pinger
22

33
import (
44
_ "net/http/pprof" // #nosec
5+
"os"
6+
"strconv"
57

68
"k8s.io/klog/v2"
79
"kernel.org/pub/linux/libs/security/libcap/cap"
@@ -16,7 +18,6 @@ import (
1618

1719
func CmdMain() {
1820
defer klog.Flush()
19-
2021
klog.Info(versions.String())
2122

2223
currentCaps := cap.GetProc()
@@ -27,6 +28,12 @@ func CmdMain() {
2728
util.LogFatalAndExit(err, "failed to parse config")
2829
}
2930

31+
perm, err := strconv.ParseUint(config.LogPerm, 8, 32)
32+
if err != nil {
33+
util.LogFatalAndExit(err, "failed to parse log-perm")
34+
}
35+
util.InitLogFilePerm("kube-ovn-pinger", os.FileMode(perm))
36+
3037
ctrl.SetLogger(klog.NewKlogr())
3138
ctx := signals.SetupSignalHandler()
3239
if config.Mode == "server" {

cmd/speaker/speaker.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package speaker
22

33
import (
4+
"os"
5+
"strconv"
6+
47
"k8s.io/klog/v2"
58
"kernel.org/pub/linux/libs/security/libcap/cap"
69
ctrl "sigs.k8s.io/controller-runtime"
@@ -14,7 +17,6 @@ import (
1417

1518
func CmdMain() {
1619
defer klog.Flush()
17-
1820
klog.Info(versions.String())
1921

2022
currentCaps := cap.GetProc()
@@ -25,6 +27,12 @@ func CmdMain() {
2527
util.LogFatalAndExit(err, "failed to parse config")
2628
}
2729

30+
perm, err := strconv.ParseUint(config.LogPerm, 8, 32)
31+
if err != nil {
32+
util.LogFatalAndExit(err, "failed to parse log-perm")
33+
}
34+
util.InitLogFilePerm("kube-ovn-speaker", os.FileMode(perm))
35+
2836
ctrl.SetLogger(klog.NewKlogr())
2937
ctx := signals.SetupSignalHandler()
3038
go func() {

pkg/controller/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ type Configuration struct {
115115

116116
// used to set vpc-egress-gateway image
117117
Image string
118+
119+
// used to set log file permission
120+
LogPerm string
118121
}
119122

120123
// ParseFlags parses cmd args then init kubeclient and conf
@@ -196,6 +199,8 @@ func ParseFlags() (*Configuration, error) {
196199
argBfdDetectMult = pflag.Int("detect-mult", 3, "The negotiated transmit interval, multiplied by this value, provides the Detection Time for the receiving system in Asynchronous mode.")
197200

198201
argImage = pflag.String("image", "", "The image for vpc-egress-gateway")
202+
203+
argLogPerm = pflag.String("log-perm", "640", "The permission for the log file")
199204
)
200205

201206
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
@@ -282,6 +287,7 @@ func ParseFlags() (*Configuration, error) {
282287
BfdDetectMult: *argBfdDetectMult,
283288
EnableANP: *argEnableANP,
284289
Image: *argImage,
290+
LogPerm: *argLogPerm,
285291
}
286292

287293
if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {

pkg/daemon/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type Configuration struct {
7575
EnableTProxy bool
7676
OVSVsctlConcurrency int32
7777
SetVxlanTxOff bool
78+
LogPerm string
7879
}
7980

8081
// ParseFlags will parse cmd args then init kubeClient and configuration
@@ -120,6 +121,7 @@ func ParseFlags() *Configuration {
120121
argOVSVsctlConcurrency = pflag.Int32("ovs-vsctl-concurrency", 100, "concurrency limit of ovs-vsctl")
121122
argEnableOVNIPSec = pflag.Bool("enable-ovn-ipsec", false, "Whether to enable ovn ipsec")
122123
argSetVxlanTxOff = pflag.Bool("set-vxlan-tx-off", false, "Whether to set vxlan_sys_4789 tx off")
124+
argLogPerm = pflag.String("log-perm", "640", "The permission for the log file")
123125
)
124126

125127
// mute info log for ipset lib
@@ -181,6 +183,7 @@ func ParseFlags() *Configuration {
181183
EnableTProxy: *argEnableTProxy,
182184
OVSVsctlConcurrency: *argOVSVsctlConcurrency,
183185
SetVxlanTxOff: *argSetVxlanTxOff,
186+
LogPerm: *argLogPerm,
184187
}
185188
return config
186189
}

pkg/ovn_ic_controller/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Configuration struct {
3232
NodeSwitch string
3333
ClusterRouter string
3434
NodeSwitchCIDR string
35+
LogPerm string
3536
}
3637

3738
func ParseFlags() (*Configuration, error) {
@@ -48,6 +49,7 @@ func ParseFlags() (*Configuration, error) {
4849
argClusterRouter = pflag.String("cluster-router", util.DefaultVpc, "The router name for cluster router")
4950
argNodeSwitch = pflag.String("node-switch", "join", "The name of node gateway switch which help node to access pod network")
5051
argNodeSwitchCIDR = pflag.String("node-switch-cidr", "100.64.0.0/16", "The cidr for node switch")
52+
argLogPerm = pflag.String("log-perm", "640", "The permission for the log file")
5153
)
5254

5355
klogFlags := flag.NewFlagSet("klog", flag.ContinueOnError)
@@ -88,6 +90,7 @@ func ParseFlags() (*Configuration, error) {
8890
ClusterRouter: *argClusterRouter,
8991
NodeSwitch: *argNodeSwitch,
9092
NodeSwitchCIDR: *argNodeSwitchCIDR,
93+
LogPerm: *argLogPerm,
9194
}
9295

9396
if err := config.initKubeClient(); err != nil {

pkg/ovnmonitor/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Configuration struct {
4545
EnableMetrics bool
4646
SecureServing bool
4747
MetricsPort int32
48+
LogPerm string
4849
}
4950

5051
// ParseFlags get parameters information.
@@ -88,6 +89,8 @@ func ParseFlags() (*Configuration, error) {
8889
argServiceVswitchdFilePidPath = pflag.String("service.vswitchd.file.pid.path", "/var/run/openvswitch/ovs-vswitchd.pid", "OVS vswitchd daemon process id file.")
8990
argServiceNorthdFileLogPath = pflag.String("service.ovn.northd.file.log.path", "/var/log/ovn/ovn-northd.log", "OVN northd daemon log file.")
9091
argServiceNorthdFilePidPath = pflag.String("service.ovn.northd.file.pid.path", "/var/run/ovn/ovn-northd.pid", "OVN northd daemon process id file.")
92+
93+
argLogPerm = pflag.String("log-perm", "640", "The permission for the log file")
9194
)
9295

9396
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
@@ -144,6 +147,7 @@ func ParseFlags() (*Configuration, error) {
144147
EnableMetrics: *argEnableMetrics,
145148
SecureServing: *argSecureServing,
146149
MetricsPort: *argMetricsPort,
150+
LogPerm: *argLogPerm,
147151
}
148152

149153
klog.Infof("ovn monitor config is %+v", config)

0 commit comments

Comments
 (0)