Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement global debugging support #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cmd/syringe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func main() {
"SYRINGE_DEBUG",
},
},
&cli.BoolFlag{
Name: "debug-global",
Usage: "Whether to enable debug logging for all Syringe clients. Useful only when dbus is enabled",
Value: false,
EnvVars: []string{
"SYRINGE_DEBUG_GLOBAL",
},
},
},
Commands: []*cli.Command{
{
Expand Down Expand Up @@ -91,7 +99,7 @@ func main() {
},
},
Before: func(cctx *cli.Context) (err error) {
if err = setupLogging(cctx.Bool("debug")); err != nil {
if err = setupLogging(cctx.Bool("debug") || cctx.Bool("debug-global")); err != nil {
return
}

Expand Down
1 change: 1 addition & 0 deletions cmd/syringe/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func serverEntrypoint(clictx *cli.Context) (err error) {
cctx.WithVaultClient(vault),
cctx.WithTemplateMap(tm),
cctx.WithSocketPaths(socketPaths),
cctx.WithGlobalDebug(clictx.Bool("debug-global")),
)

if clictx.Bool("dbus") {
Expand Down
11 changes: 11 additions & 0 deletions cmd/syringe/update_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ func updateEntrypoint(clictx *cli.Context) (err error) {
runtime.GOMAXPROCS(1)
ctx := clictx.Context

// Reconfigure logger according to debug value via dbus service
// We need dbus service to be available in update mode anyway
if debug, derr := dbus.GetGlobalDebug(ctx); derr != nil {
zap.L().Debug("unable to get global debug flag", zap.Error(err))
} if debug && !(clictx.Bool("debug") || clictx.Bool("global-debug")) {
if err = setupLogging(true); err != nil {
return
}
zap.L().Debug("global debugging enabled")
}

if os.Getuid() != 0 && os.Geteuid() != 0 {
zap.L().Error("effective uid is not 0, very likely unable to update credentials", zap.Int("uid", os.Getuid()), zap.Int("euid", os.Geteuid()))
}
Expand Down
11 changes: 11 additions & 0 deletions internal/ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ func SocketPaths(ctx context.Context) (v []string) {
v = ctx.Value(socketPath).([]string)
return
}

func WithGlobalDebug(gd bool) ContextValueFunc {
return func(ctx context.Context) context.Context {
return context.WithValue(ctx, globalDebug, gd)
}
}

func GlobalDebug(ctx context.Context) (v bool) {
v = ctx.Value(globalDebug).(bool)
return
}
1 change: 1 addition & 0 deletions internal/ctx/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var (
credentialReqUnit contextValue = "ctx:cru"
credentialReqCred contextValue = "ctx:crc"
socketPath contextValue = "ctx:sp"
globalDebug contextValue = "ctx:gd"
)
21 changes: 21 additions & 0 deletions internal/dbus/syringe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,24 @@ func GetServiceSocketPaths(ctx context.Context) (socketPaths map[string]bool, er

return
}

func GetGlobalDebug(ctx context.Context) (debug bool, err error) {
var conn *dbus.Conn

if conn, err = dbus.ConnectSystemBus(); err != nil {
err = fmt.Errorf("failed to establish dbus connection: %w", err)
return
}
defer conn.Close()

var globalDebugValue dbus.Variant
obj := conn.Object(intf, objPath)
err = obj.CallWithContext(ctx, "ee.zentria.syringe1.Syringe.GetGlobalDebug", 0).Store(&globalDebugValue)
if err != nil {
err = fmt.Errorf("failed to call GetGlobalDebug: %w", err)
return
}

debug = globalDebugValue.Value().(bool)
return
}
10 changes: 10 additions & 0 deletions internal/dbus/syringe_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const intro = introspect.IntrospectDeclarationString + `
<doc:doc><doc:summary>Path to the Unix sockets where Syringe is currently listening on</doc:summary></doc:doc>
</arg>
</method>
<method name="GetGlobalDebug">
<arg direction="out" type="b">
<doc:doc><doc:summary>Whether global debugging is enabled</doc:summary></doc:doc>
</arg>
</method>
</interface>
` + introspect.IntrospectDataString + `
</node>
Expand All @@ -39,6 +44,11 @@ func (s *syringeService) GetSocketPaths() (v []string, err *dbus.Error) {
return
}

func (s *syringeService) GetGlobalDebug() (v bool, err *dbus.Error) {
v = cctx.GlobalDebug(s.ctx)
return
}

func RegisterSyringeService(ctx context.Context) (err error) {
var conn *dbus.Conn

Expand Down