Skip to content
Merged
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 |
Expand Down
32 changes: 24 additions & 8 deletions cmd/osctrld/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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/"
Expand All @@ -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")
}
}
36 changes: 28 additions & 8 deletions cmd/osctrld/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions cmd/osctrld/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"`)
Expand Down
8 changes: 4 additions & 4 deletions service/osctrld-sample.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/osctrld-test.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/osctrld-test.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading