-
Notifications
You must be signed in to change notification settings - Fork 114
Add Configuration for SCALIBR #1034
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -62,10 +62,12 @@ const ( | |
|
|
||
| prodEndpoint = "{zone}-osconfig.googleapis.com.:443" | ||
|
|
||
| osInventoryEnabledDefault = false | ||
| guestPoliciesEnabledDefault = false | ||
| taskNotificationEnabledDefault = false | ||
| debugEnabledDefault = false | ||
| osInventoryEnabledDefault = false | ||
| guestPoliciesEnabledDefault = false | ||
| taskNotificationEnabledDefault = false | ||
| debugEnabledDefault = false | ||
| extendedInventoryEnabledDefault = false | ||
| extendedInventoryCollectionIntervalDefault = 10 | ||
|
|
||
| oldConfigDirLinux = "/etc/osconfig" | ||
| cacheDirLinux = "/var/lib/google_osconfig_agent" | ||
|
|
@@ -122,25 +124,28 @@ var ( | |
| ) | ||
|
|
||
| type config struct { | ||
| aptRepoFilePath string | ||
| instanceName string | ||
| instanceZone string | ||
| projectID string | ||
| svcEndpoint string | ||
| googetRepoFilePath string | ||
| zypperRepoFilePath string | ||
| yumRepoFilePath string | ||
| instanceID string | ||
| universeDomain string | ||
| numericProjectID int64 | ||
| osConfigPollInterval int | ||
| debugEnabled bool | ||
| taskNotificationEnabled bool | ||
| guestPoliciesEnabled bool | ||
| osInventoryEnabled bool | ||
| scalibrLinuxEnabled bool | ||
| guestAttributesEnabled bool | ||
| traceGetInventory bool | ||
| aptRepoFilePath string | ||
| instanceName string | ||
| instanceZone string | ||
| projectID string | ||
| svcEndpoint string | ||
| googetRepoFilePath string | ||
| zypperRepoFilePath string | ||
| yumRepoFilePath string | ||
| instanceID string | ||
| universeDomain string | ||
| numericProjectID int64 | ||
| osConfigPollInterval int | ||
| debugEnabled bool | ||
| taskNotificationEnabled bool | ||
| guestPoliciesEnabled bool | ||
| osInventoryEnabled bool | ||
| scalibrLinuxEnabled bool | ||
| guestAttributesEnabled bool | ||
| traceGetInventory bool | ||
| extendedInventoryEnabled bool | ||
| extendedInventoryCollectionInterval int | ||
|
Contributor
Author
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 this field necessary, or could we reuse the existing osConfigPollInterval ticker instead of adding a new interval configuration? Since we discussed merging the results of extended and legacy scans, it makes sense for them to run simultaneously.
Contributor
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. That's a good point, it seems that we can reuse the existing ticker
Contributor
Author
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. removed it |
||
| extendedInventoryExtractorsAllowed []string | ||
| } | ||
|
|
||
| func (c *config) parseFeatures(features string, enabled bool) { | ||
|
|
@@ -196,6 +201,17 @@ func parseBool(s string) bool { | |
| return enabled | ||
| } | ||
|
|
||
| func parseSlice(s string) []string { | ||
| var slice []string | ||
| for _, item := range strings.Split(s, ",") { | ||
| item = strings.TrimSpace(item) | ||
| if item != "" { | ||
| slice = append(slice, item) | ||
| } | ||
| } | ||
| return slice | ||
| } | ||
|
|
||
| type metadataJSON struct { | ||
| Instance instanceJSON | ||
| Project projectJSON | ||
|
|
@@ -220,32 +236,37 @@ type universeJSON struct { | |
| } | ||
|
|
||
| type attributesJSON struct { | ||
| PollIntervalOld *json.Number `json:"os-config-poll-interval"` | ||
| PollInterval *json.Number `json:"osconfig-poll-interval"` | ||
| InventoryEnabledOld string `json:"os-inventory-enabled"` | ||
| InventoryEnabled string `json:"enable-os-inventory"` | ||
| PreReleaseFeaturesOld string `json:"os-config-enabled-prerelease-features"` | ||
| PreReleaseFeatures string `json:"osconfig-enabled-prerelease-features"` | ||
| DebugEnabledOld string `json:"enable-os-config-debug"` | ||
| LogLevel string `json:"osconfig-log-level"` | ||
| OSConfigEndpointOld string `json:"os-config-endpoint"` | ||
| OSConfigEndpoint string `json:"osconfig-endpoint"` | ||
| OSConfigEnabled string `json:"enable-osconfig"` | ||
| DisabledFeatures string `json:"osconfig-disabled-features"` | ||
| EnableGuestAttributes string `json:"enable-guest-attributes"` | ||
| TraceGetInventory string `json:"trace-get-inventory"` | ||
| ScalibrLinuxEnabled string `json:"enable-scalibr-linux"` | ||
| PollIntervalOld *json.Number `json:"os-config-poll-interval"` | ||
| PollInterval *json.Number `json:"osconfig-poll-interval"` | ||
| InventoryEnabledOld string `json:"os-inventory-enabled"` | ||
| InventoryEnabled string `json:"enable-os-inventory"` | ||
| PreReleaseFeaturesOld string `json:"os-config-enabled-prerelease-features"` | ||
| PreReleaseFeatures string `json:"osconfig-enabled-prerelease-features"` | ||
| DebugEnabledOld string `json:"enable-os-config-debug"` | ||
| LogLevel string `json:"osconfig-log-level"` | ||
| OSConfigEndpointOld string `json:"os-config-endpoint"` | ||
| OSConfigEndpoint string `json:"osconfig-endpoint"` | ||
| OSConfigEnabled string `json:"enable-osconfig"` | ||
| DisabledFeatures string `json:"osconfig-disabled-features"` | ||
| EnableGuestAttributes string `json:"enable-guest-attributes"` | ||
| TraceGetInventory string `json:"trace-get-inventory"` | ||
| ScalibrLinuxEnabled string `json:"enable-scalibr-linux"` | ||
| ExtendedInventoryEnabled string `json:"osconfig-extended-inventory-enabled"` | ||
| ExtendedInventoryCollectionInterval *json.Number `json:"osconfig-extended-inventory-collection-interval"` | ||
| ExtendedInventoryExtractorsAllowed string `json:"osconfig-extended-inventory-extractors-allowed"` | ||
| } | ||
|
|
||
| func createConfigFromMetadata(md metadataJSON) *config { | ||
| old := getAgentConfig() | ||
| c := &config{ | ||
| osInventoryEnabled: osInventoryEnabledDefault, | ||
| guestPoliciesEnabled: guestPoliciesEnabledDefault, | ||
| taskNotificationEnabled: taskNotificationEnabledDefault, | ||
| debugEnabled: debugEnabledDefault, | ||
| svcEndpoint: prodEndpoint, | ||
| osConfigPollInterval: osConfigPollIntervalDefault, | ||
| osInventoryEnabled: osInventoryEnabledDefault, | ||
| guestPoliciesEnabled: guestPoliciesEnabledDefault, | ||
| taskNotificationEnabled: taskNotificationEnabledDefault, | ||
| debugEnabled: debugEnabledDefault, | ||
| svcEndpoint: prodEndpoint, | ||
| osConfigPollInterval: osConfigPollIntervalDefault, | ||
| extendedInventoryEnabled: extendedInventoryEnabledDefault, | ||
| extendedInventoryCollectionInterval: extendedInventoryCollectionIntervalDefault, | ||
|
|
||
| googetRepoFilePath: googetRepoFilePath, | ||
| zypperRepoFilePath: zypperRepoFilePath, | ||
|
|
@@ -374,10 +395,41 @@ func createConfigFromMetadata(md metadataJSON) *config { | |
| setScalibrEnablement(md, c) | ||
| setSVCEndpoint(md, c) | ||
| setTraceGetInventory(md, c) | ||
| setExtendedInventory(md, c) | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| func setExtendedInventory(md metadataJSON, c *config) { | ||
| projectSettings := md.Project.Attributes | ||
| instanceSettings := md.Instance.Attributes | ||
|
|
||
| if projectSettings.ExtendedInventoryEnabled != "" { | ||
| c.extendedInventoryEnabled = parseBool(projectSettings.ExtendedInventoryEnabled) | ||
| } | ||
| if instanceSettings.ExtendedInventoryEnabled != "" { | ||
| c.extendedInventoryEnabled = parseBool(instanceSettings.ExtendedInventoryEnabled) | ||
| } | ||
|
|
||
| if projectSettings.ExtendedInventoryCollectionInterval != nil { | ||
| if val, err := projectSettings.ExtendedInventoryCollectionInterval.Int64(); err == nil { | ||
| c.extendedInventoryCollectionInterval = int(val) | ||
| } | ||
| } | ||
| if instanceSettings.ExtendedInventoryCollectionInterval != nil { | ||
| if val, err := instanceSettings.ExtendedInventoryCollectionInterval.Int64(); err == nil { | ||
| c.extendedInventoryCollectionInterval = int(val) | ||
| } | ||
| } | ||
|
|
||
| if projectSettings.ExtendedInventoryExtractorsAllowed != "" { | ||
| c.extendedInventoryExtractorsAllowed = parseSlice(projectSettings.ExtendedInventoryExtractorsAllowed) | ||
| } | ||
| if instanceSettings.ExtendedInventoryExtractorsAllowed != "" { | ||
| c.extendedInventoryExtractorsAllowed = parseSlice(instanceSettings.ExtendedInventoryExtractorsAllowed) | ||
| } | ||
| } | ||
|
|
||
| func setScalibrEnablement(md metadataJSON, c *config) { | ||
| projectSetting := md.Project.Attributes.ScalibrLinuxEnabled | ||
| instanceSetting := md.Instance.Attributes.ScalibrLinuxEnabled | ||
|
|
@@ -601,6 +653,21 @@ func TraceGetInventory() bool { | |
| return getAgentConfig().traceGetInventory | ||
| } | ||
|
|
||
| // ExtendedInventoryEnabled indicates whether extended inventory collection should be enabled. | ||
| func ExtendedInventoryEnabled() bool { | ||
| return getAgentConfig().extendedInventoryEnabled | ||
| } | ||
|
|
||
| // ExtendedInventoryCollectionInterval returns the frequency for extended inventory collection. | ||
| func ExtendedInventoryCollectionInterval() time.Duration { | ||
| return time.Duration(getAgentConfig().extendedInventoryCollectionInterval) * time.Minute | ||
| } | ||
|
|
||
| // ExtendedInventoryExtractorsAllowed returns the allowed extractors for extended inventory. | ||
| func ExtendedInventoryExtractorsAllowed() []string { | ||
| return getAgentConfig().extendedInventoryExtractorsAllowed | ||
| } | ||
|
|
||
| // ZypperRepoDir is the location of the zypper repo files. | ||
| func ZypperRepoDir() string { | ||
| return zypperRepoDir | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
If we're updating the SCALIBR flow, am I right in understanding that we can drop scalibrLinuxEnabled and rely on extendedInventoryEnabled for both linux and windows?
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.
No,
scalibrLinuxEnabledis a flag to enable extraction usingosv-scalibrandextendedInventoryEnabledis used to enable extraction with extended set of extractors (other than currently supported).Uh oh!
There was an error while loading. Please reload this page.
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.
please correct me if i'm wrong. if we have scalibrLinuxEnabled = true - we just start to use current default extractors ("os/cos", "os/dpkg", "os/rpm"). with additional extendedInventoryEnabled = true we start to use other extractors by default, language extractors for example. and extendedInventoryExtractorsAllowed is used to filter those additionally activated extractors. @petercieslak is that correct?
my other theory - extendedInventoryExtractorsAllowed must be non-empty to use any additional extractors with extendedInventoryEnabled, otherwise will be no effect.
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.
The first description is correct, with scalibrLinuxEnabled we use the default extractors. Additionally extendedInventoryEnabled allows us to use extendedInventoryExtractorsAllowed in the extraction process. The extendedInventoryExtractorsAllowed don't have to be non-empty - if that's the case we just use the default extractors.