-
Notifications
You must be signed in to change notification settings - Fork 9
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
Auditing timescaledb #565
base: master
Are you sure you want to change the base?
Auditing timescaledb #565
Changes from 2 commits
d15abec
8ef8209
a7e61ab
31e7b87
3962930
bf8b8a8
ed9716d
2dc5c22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,11 +287,19 @@ func init() { | |
rootCmd.Flags().StringP("masterdata-certkeypath", "", "", "the tls certificate key to talk to the masterdata-api") | ||
|
||
rootCmd.Flags().Bool("auditing-enabled", false, "enable auditing") | ||
rootCmd.Flags().String("auditing-url", "http://localhost:7700", "url of the auditing service") | ||
rootCmd.Flags().String("auditing-api-key", "secret", "api key for the auditing service") | ||
rootCmd.Flags().String("auditing-index-prefix", "auditing", "auditing index prefix") | ||
rootCmd.Flags().String("auditing-index-interval", "@daily", "auditing index creation interval, can be one of @hourly|@daily|@monthly") | ||
rootCmd.Flags().Int64("auditing-keep", 14, "the amount of indexes to keep until cleanup") | ||
|
||
rootCmd.Flags().String("auditing-meili-url", "http://localhost:7700", "url of the auditing service") | ||
rootCmd.Flags().String("auditing-meili-api-key", "secret", "api key for the auditing service") | ||
rootCmd.Flags().String("auditing-meili-index-prefix", "auditing", "auditing index prefix") | ||
rootCmd.Flags().String("auditing-meili-index-interval", "@daily", "auditing index creation interval, can be one of @hourly|@daily|@monthly") | ||
rootCmd.Flags().Int64("auditing-meili-keep", 14, "the amount of indexes to keep until cleanup") | ||
Comment on lines
+291
to
+295
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to remove the support for meilisearch completely instead of adding the complexity of supporting multiple auditing backends There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we will have introduce multiple backends though if FI-TS wants to have Splunk connected. But maybe also we want to introduce the buffer service as well, which we were discussing as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my opinion, metal-api should only have one auditing implementation, if other parties are interested in other auditing backends, then this should be solved at a later layer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think this should be done but it comes with quite a lot of work and maybe it's acceptable to introduce this beforehand and then switch to the dedicated auditing layer because in production we see too many issues with Meilisearch currently. :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could live with small steps towards the final solution as well |
||
|
||
rootCmd.Flags().String("auditing-timescaledb-host", "", "host of the auditing service") | ||
rootCmd.Flags().String("auditing-timescaledb-port", "", "port of the auditing service") | ||
rootCmd.Flags().String("auditing-timescaledb-db", "", "database name of the auditing service") | ||
rootCmd.Flags().String("auditing-timescaledb-user", "", "user for the auditing service") | ||
rootCmd.Flags().String("auditing-timescaledb-password", "", "password for the auditing service") | ||
rootCmd.Flags().String("auditing-timescaledb-retention", "", "the time until audit traces are cleaned up") | ||
|
||
rootCmd.Flags().String("headscale-addr", "", "address of headscale server") | ||
rootCmd.Flags().String("headscale-cp-addr", "", "address of headscale control plane") | ||
|
@@ -691,7 +699,7 @@ func initAuth(lg *slog.Logger) security.UserGetter { | |
return security.NewCreds(auths...) | ||
} | ||
|
||
func initRestServices(audit auditing.Auditing, withauth bool, ipmiSuperUser metal.MachineIPMISuperUser) *restfulspec.Config { | ||
func initRestServices(audit []auditing.Auditing, withauth bool, ipmiSuperUser metal.MachineIPMISuperUser) *restfulspec.Config { | ||
service.BasePath = viper.GetString("base-path") | ||
if !strings.HasPrefix(service.BasePath, "/") || !strings.HasSuffix(service.BasePath, "/") { | ||
log.Fatal("base path must start and end with a slash") | ||
|
@@ -757,7 +765,7 @@ func initRestServices(audit auditing.Auditing, withauth bool, ipmiSuperUser meta | |
releaseVersion = pointer.Pointer(viper.GetString("release-version")) | ||
} | ||
|
||
restful.DefaultContainer.Add(service.NewAudit(logger.WithGroup("audit-service"), audit)) | ||
restful.DefaultContainer.Add(service.NewAudit(logger.WithGroup("audit-service"), pointer.FirstOrZero(audit))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there there some documentation about this behavior of only using the first auditing backend as source for the search? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet... also not sure if it's correct to do this. Probably this should be somehow configurable. |
||
restful.DefaultContainer.Add(service.NewPartition(logger.WithGroup("partition-service"), ds, nsqer)) | ||
restful.DefaultContainer.Add(service.NewImage(logger.WithGroup("image-service"), ds)) | ||
restful.DefaultContainer.Add(service.NewSize(logger.WithGroup("size-service"), ds, mdc)) | ||
|
@@ -790,8 +798,8 @@ func initRestServices(audit auditing.Auditing, withauth bool, ipmiSuperUser meta | |
restful.DefaultContainer.Filter(ensurer.EnsureAllowedTenantFilter) | ||
} | ||
|
||
if audit != nil { | ||
httpFilter, err := auditing.HttpFilter(audit, logger.WithGroup("audit-middleware")) | ||
for _, backend := range audit { | ||
httpFilter, err := auditing.HttpFilter(backend, logger.WithGroup("audit-middleware")) | ||
if err != nil { | ||
log.Fatalf("unable to create http filter for auditing: %s", err) | ||
} | ||
|
@@ -908,23 +916,54 @@ func evaluateVPNConnected() error { | |
} | ||
|
||
// might return (nil, nil) if auditing is disabled! | ||
func createAuditingClient(log *slog.Logger) (auditing.Auditing, error) { | ||
func createAuditingClient(log *slog.Logger) ([]auditing.Auditing, error) { | ||
isEnabled := viper.GetBool("auditing-enabled") | ||
if !isEnabled { | ||
log.Warn("auditing is disabled, can be enabled by setting --auditing-enabled=true") | ||
return nil, nil | ||
} | ||
|
||
c := auditing.Config{ | ||
Component: "metal-api", | ||
URL: viper.GetString("auditing-url"), | ||
APIKey: viper.GetString("auditing-api-key"), | ||
IndexPrefix: viper.GetString("auditing-index-prefix"), | ||
RotationInterval: auditing.Interval(viper.GetString("auditing-index-interval")), | ||
Keep: viper.GetInt64("auditing-keep"), | ||
Log: log, //FIXME | ||
} | ||
return auditing.New(c) | ||
Component: "metal-api", | ||
Log: log, | ||
} | ||
|
||
var backends []auditing.Auditing | ||
|
||
if viper.IsSet("auditing-timescaledb-host") { | ||
backend, err := auditing.NewTimescaleDB(c, auditing.TimescaleDbConfig{ | ||
Host: viper.GetString("auditing-timescaledb-host"), | ||
Port: viper.GetString("auditing-timescaledb-port"), | ||
DB: viper.GetString("auditing-timescaledb-db"), | ||
User: viper.GetString("auditing-timescaledb-user"), | ||
Password: viper.GetString("auditing-timescaledb-password"), | ||
Retention: viper.GetString("auditing-timescaledb-retention"), | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
backends = append(backends, backend) | ||
} | ||
|
||
if viper.IsSet("auditing-meili-api-key") { | ||
backend, err := auditing.NewMeilisearch(c, auditing.MeilisearchConfig{ | ||
URL: viper.GetString("auditing-meili-url"), | ||
APIKey: viper.GetString("auditing-meili-api-key"), | ||
IndexPrefix: viper.GetString("auditing-meili-index-prefix"), | ||
RotationInterval: auditing.Interval(viper.GetString("auditing-meili-index-interval")), | ||
Keep: viper.GetInt64("auditing-meili-keep"), | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
backends = append(backends, backend) | ||
} | ||
|
||
return backends, nil | ||
} | ||
|
||
func run() error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we need an if statement to skip not enabled backends. See https://github.com/metal-stack/metal-roles/pull/310/files#diff-81777600d83d4794dafee8e817a4b696b9c1a05fe38798329235b2ec72537cd1R229