From 99538f3e0cd9bfcdb25cb9c4c784578fccc101a1 Mon Sep 17 00:00:00 2001 From: Javier Marcos <1271349+javuto@users.noreply.github.com> Date: Sat, 6 Jun 2026 22:36:19 +0200 Subject: [PATCH] Clearer fields in the keys of the config file --- README.md | 16 ++++++++-------- cmd/osctrld/config.go | 32 ++++++++++++++++++++++++-------- cmd/osctrld/config_test.go | 36 ++++++++++++++++++++++++++++-------- cmd/osctrld/main_test.go | 8 ++++---- service/osctrld-sample.yaml | 8 ++++---- tests/osctrld-test.json | 8 ++++---- tests/osctrld-test.yaml | 8 ++++---- 7 files changed, 76 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 33a852f..6415d16 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,11 @@ Example YAML configuration: ```yaml osctrld: # osctrl enrollment secret value used to authenticate requests - secret: "thisisthesecret" + osctrlSecret: "thisisthesecret" # Local path where the osquery enrollment secret file is written or verified - secretFile: "/path/to/osquery.secret" - flags: "/path/to/osquery.flags" - cert: "/path/to/osquery.crt" + osquerySecretFile: "/path/to/osquery.secret" + osqueryFlagFile: "/path/to/osquery.flags" + osqueryCertFile: "/path/to/osquery.crt" environment: "environment_name_or_UUID" baseurl: "https://osctrl.url" insecure: false @@ -130,10 +130,10 @@ JSON configuration files are also supported. Use a `.json` extension and osctrld | Field | Description | Default | | --- | --- | --- | -| `secret` | osctrl enrollment secret value used to authenticate requests | Required for enrollment workflows | -| `secretFile` | Local path where the osquery enrollment secret file is written or verified | OS-dependent | -| `flags` | Path to the osquery flags file | OS-dependent | -| `cert` | Path to the osquery TLS certificate file | OS-dependent | +| `osctrlSecret` | osctrl enrollment secret value used to authenticate requests | Required for enrollment workflows | +| `osquerySecretFile` | Local path where the osquery enrollment secret file is written or verified | OS-dependent | +| `osqueryFlagFile` | Path to the osquery flags file | OS-dependent | +| `osqueryCertFile` | Path to the osquery TLS certificate file | OS-dependent | | `enrollScript` | Path to the enroll script | OS-dependent | | `removeScript` | Path to the remove script | OS-dependent | | `osquery` | Path to the osquery installation directory | OS-dependent | diff --git a/cmd/osctrld/config.go b/cmd/osctrld/config.go index fc50989..37032d0 100644 --- a/cmd/osctrld/config.go +++ b/cmd/osctrld/config.go @@ -12,10 +12,10 @@ const ( // Configuration holds all configuration values for osctrld. // Supports both YAML (default) and JSON config files. type Configuration struct { - OsctrlSecret string `json:"secret" yaml:"secret" mapstructure:"secret"` - OsquerySecretFile string `json:"secretFile" yaml:"secretFile" mapstructure:"secretFile"` - OsqueryFlagFile string `json:"flags" yaml:"flags" mapstructure:"flags"` - OsqueryCertFile string `json:"cert" yaml:"cert" mapstructure:"cert"` + OsctrlSecret string `json:"osctrlSecret" yaml:"osctrlSecret" mapstructure:"osctrlSecret"` + OsquerySecretFile string `json:"osquerySecretFile" yaml:"osquerySecretFile" mapstructure:"osquerySecretFile"` + OsqueryFlagFile string `json:"osqueryFlagFile" yaml:"osqueryFlagFile" mapstructure:"osqueryFlagFile"` + OsqueryCertFile string `json:"osqueryCertFile" yaml:"osqueryCertFile" mapstructure:"osqueryCertFile"` EnrollScript string `json:"enrollScript" yaml:"enrollScript" mapstructure:"enrollScript"` RemoveScript string `json:"removeScript" yaml:"removeScript" mapstructure:"removeScript"` OsqueryPath string `json:"osquery" yaml:"osquery" mapstructure:"osquery"` @@ -32,11 +32,11 @@ type Configuration struct { func defaultConfigurationYAML() string { return `osctrld: # osctrl enrollment secret value used to authenticate requests - secret: "replace-with-osctrl-enrollment-secret" + osctrlSecret: "replace-with-osctrl-enrollment-secret" # Local path where the osquery enrollment secret file is written or verified - secretFile: "/path/to/osquery.secret" - flags: "/path/to/osquery.flags" - cert: "/path/to/osctrl.crt" + osquerySecretFile: "/path/to/osquery.secret" + osqueryFlagFile: "/path/to/osquery.flags" + osqueryCertFile: "/path/to/osctrl.crt" enrollScript: "/path/to/osctrld-enroll.sh" removeScript: "/path/to/osctrld-remove.sh" osquery: "/path/to/osquery/" @@ -62,5 +62,21 @@ func loadConfiguration(file string, verbose bool) (Configuration, error) { if err := configRaw.Unmarshal(&cfg); err != nil { return cfg, err } + applyLegacyConfigurationFields(configRaw, &cfg) return cfg, nil } + +func applyLegacyConfigurationFields(configRaw *viper.Viper, cfg *Configuration) { + if cfg.OsctrlSecret == "" { + cfg.OsctrlSecret = configRaw.GetString("secret") + } + if cfg.OsquerySecretFile == "" { + cfg.OsquerySecretFile = configRaw.GetString("secretFile") + } + if cfg.OsqueryFlagFile == "" { + cfg.OsqueryFlagFile = configRaw.GetString("flags") + } + if cfg.OsqueryCertFile == "" { + cfg.OsqueryCertFile = configRaw.GetString("cert") + } +} diff --git a/cmd/osctrld/config_test.go b/cmd/osctrld/config_test.go index 0564f45..8a02b13 100644 --- a/cmd/osctrld/config_test.go +++ b/cmd/osctrld/config_test.go @@ -18,10 +18,10 @@ func TestLoadConfigurationJSON(t *testing.T) { configPath := filepath.Join(dir, "osctrld-test.json") configData := []byte(`{ "osctrld": { - "secret": "test-secret", - "secretFile": "/tmp/osquery.secret", - "flags": "/tmp/osquery.flags", - "cert": "/tmp/osctrl.crt", + "osctrlSecret": "test-secret", + "osquerySecretFile": "/tmp/osquery.secret", + "osqueryFlagFile": "/tmp/osquery.flags", + "osqueryCertFile": "/tmp/osctrl.crt", "environment": "dev", "baseurl": "https://localhost:9000", "insecure": true, @@ -49,10 +49,10 @@ func TestLoadConfigurationYAML(t *testing.T) { dir := t.TempDir() configPath := filepath.Join(dir, "osctrld-test.yaml") configData := []byte(`osctrld: - secret: "test-secret" - secretFile: "/tmp/osquery.secret" - flags: "/tmp/osquery.flags" - cert: "/tmp/osctrl.crt" + osctrlSecret: "test-secret" + osquerySecretFile: "/tmp/osquery.secret" + osqueryFlagFile: "/tmp/osquery.flags" + osqueryCertFile: "/tmp/osctrl.crt" environment: "dev" baseurl: "https://localhost:9000" insecure: true @@ -80,3 +80,23 @@ func TestLoadConfigurationYAML(t *testing.T) { assert.Equal(t, 30, cfg.Interval) assert.Equal(t, "/tmp/extensions/", cfg.ExtensionsDir) } + +func TestLoadConfigurationLegacySecretFields(t *testing.T) { + dir := t.TempDir() + configPath := filepath.Join(dir, "osctrld-legacy.yaml") + configData := []byte(`osctrld: + secret: "legacy-secret" + secretFile: "/tmp/legacy.secret" + flags: "/tmp/legacy.flags" + cert: "/tmp/legacy.crt" +`) + err := os.WriteFile(configPath, configData, 0644) + assert.NoError(t, err) + + cfg, err := loadConfiguration(configPath, false) + assert.NoError(t, err) + assert.Equal(t, "legacy-secret", cfg.OsctrlSecret) + assert.Equal(t, "/tmp/legacy.secret", cfg.OsquerySecretFile) + assert.Equal(t, "/tmp/legacy.flags", cfg.OsqueryFlagFile) + assert.Equal(t, "/tmp/legacy.crt", cfg.OsqueryCertFile) +} diff --git a/cmd/osctrld/main_test.go b/cmd/osctrld/main_test.go index cc38413..fbdeb7d 100644 --- a/cmd/osctrld/main_test.go +++ b/cmd/osctrld/main_test.go @@ -42,10 +42,10 @@ func TestDefaultConfigCommandWritesLoadableYAML(t *testing.T) { output := stdout.String() assert.True(t, strings.HasPrefix(output, "osctrld:\n")) - assert.Contains(t, output, `secret: "replace-with-osctrl-enrollment-secret"`) - assert.Contains(t, output, `secretFile: "/path/to/osquery.secret"`) - assert.Contains(t, output, `flags: "/path/to/osquery.flags"`) - assert.Contains(t, output, `cert: "/path/to/osctrl.crt"`) + assert.Contains(t, output, `osctrlSecret: "replace-with-osctrl-enrollment-secret"`) + assert.Contains(t, output, `osquerySecretFile: "/path/to/osquery.secret"`) + assert.Contains(t, output, `osqueryFlagFile: "/path/to/osquery.flags"`) + assert.Contains(t, output, `osqueryCertFile: "/path/to/osctrl.crt"`) assert.Contains(t, output, `enrollScript: "/path/to/osctrld-enroll.sh"`) assert.Contains(t, output, `removeScript: "/path/to/osctrld-remove.sh"`) assert.Contains(t, output, `osquery: "/path/to/osquery/"`) diff --git a/service/osctrld-sample.yaml b/service/osctrld-sample.yaml index 316eda3..11c3d5a 100644 --- a/service/osctrld-sample.yaml +++ b/service/osctrld-sample.yaml @@ -1,10 +1,10 @@ osctrld: # osctrl enrollment secret value used to authenticate requests - secret: "thisisthesecret" + osctrlSecret: "thisisthesecret" # Local path where the osquery enrollment secret file is written or verified - secretFile: "/path/to/osquery.secret" - flags: "/path/to/osquery.flags" - cert: "/path/to/osquery.crt" + osquerySecretFile: "/path/to/osquery.secret" + osqueryFlagFile: "/path/to/osquery.flags" + osqueryCertFile: "/path/to/osquery.crt" environment: "environment_name_or_UUID" baseurl: "https://osctrl.url" insecure: false diff --git a/tests/osctrld-test.json b/tests/osctrld-test.json index 968f3fb..16cf4af 100644 --- a/tests/osctrld-test.json +++ b/tests/osctrld-test.json @@ -1,9 +1,9 @@ { "osctrld": { - "secret": "T0ie_hWRh72l6YmUdGEbiQFrGheuiDzGCeR3l-1IIH4_7jKgSroT8CLsxBveNZkx", - "secretFile": "/Users/javier/Github/osctrl/tmp/osctrl.secret", - "flags": "/Users/javier/Github/osctrl/tmp/osctrl-uuid.flags", - "cert": "/Users/javier/Github/osctrl/osctrl.crt", + "osctrlSecret": "T0ie_hWRh72l6YmUdGEbiQFrGheuiDzGCeR3l-1IIH4_7jKgSroT8CLsxBveNZkx", + "osquerySecretFile": "/Users/javier/Github/osctrl/tmp/osctrl.secret", + "osqueryFlagFile": "/Users/javier/Github/osctrl/tmp/osctrl-uuid.flags", + "osqueryCertFile": "/Users/javier/Github/osctrl/osctrl.crt", "environment": "dev", "baseurl": "https://localhost:9000", "insecure": true, diff --git a/tests/osctrld-test.yaml b/tests/osctrld-test.yaml index 1f8ca64..e03d141 100644 --- a/tests/osctrld-test.yaml +++ b/tests/osctrld-test.yaml @@ -1,8 +1,8 @@ osctrld: - secret: "T0ie_hWRh72l6YmUdGEbiQFrGheuiDzGCeR3l-1IIH4_7jKgSroT8CLsxBveNZkx" - secretFile: "/Users/javier/Github/osctrl/tmp/osctrl.secret" - flags: "/Users/javier/Github/osctrl/tmp/osctrl-uuid.flags" - cert: "/Users/javier/Github/osctrl/osctrl.crt" + osctrlSecret: "T0ie_hWRh72l6YmUdGEbiQFrGheuiDzGCeR3l-1IIH4_7jKgSroT8CLsxBveNZkx" + osquerySecretFile: "/Users/javier/Github/osctrl/tmp/osctrl.secret" + osqueryFlagFile: "/Users/javier/Github/osctrl/tmp/osctrl-uuid.flags" + osqueryCertFile: "/Users/javier/Github/osctrl/osctrl.crt" environment: "dev" baseurl: "https://localhost:9000" insecure: true