Skip to content

[Bug] elasticstack_fleet_integration_policy update removes osquery_manager packs (input-level config not preserved) #5480

Open

Description

@supu2

Describe the bug
Osquery packs assigned to an agent policy in Kibana (Osquery > Packs) are stored by Kibana in the osquery_manager package policy under inputs[].config.osquery.value.packs. elasticstack_fleet_integration_policy does not model input-level config, and when it updates the package policy it sends the inputs without that config. As a result every pack is removed from the agent policy.

Kibana still shows the pack as assigned to the policy (the pack saved object's policy_ids is unchanged), but agents no longer receive or run any scheduled pack query. Live queries keep working, so the problem is silent: scheduled results just stop.

In our case a routine terraform apply upgraded integration_version from the latest-version data source (osquery_manager 1.34.0 -> 1.35.1). The Fleet policy revision created by that update had an empty packs object. The revision before it had 4 packs.

To Reproduce
Steps to reproduce the behavior:

  1. TF configuration used:
data "elasticstack_fleet_integration" "osquery" {
  name = "osquery_manager"
}

resource "elasticstack_fleet_integration_policy" "osquery" {
  name                = "example-osquery"
  namespace           = "default"
  agent_policy_id     = elasticstack_fleet_agent_policy.example.policy_id
  integration_name    = "osquery_manager"
  integration_version = data.elasticstack_fleet_integration.osquery.version
  inputs = {
    "osquery_manager-osquery" = {
      enabled = true
      streams = {
        "osquery_manager.action.responses" = { enabled = true, vars = jsonencode({}) }
        "osquery_manager.result"           = { enabled = true, vars = jsonencode({}) }
      }
    }
  }
}
  1. TF operations to execute:
    • terraform apply to create the integration policy.
    • In Kibana, create an Osquery pack and assign it to the agent policy. GET /api/fleet/package_policies/<id> now shows the pack under inputs[0].config.osquery.value.packs.
    • Trigger any update of the resource, e.g. a newer osquery_manager package version (or set integration_version explicitly), then terraform apply.
  2. See the error: terraform apply succeeds with no error, but GET /api/fleet/package_policies/<id> now returns inputs[0].config without osquery.value.packs. Agents log no Scheduled query 'pack_...' lines after the policy change, and pack results stop.

Expected behavior
Updating the integration policy keeps input-level config that Terraform does not manage, the same way Fleet's own integration upgrade in Kibana keeps the packs. Alternatively, input-level config could be exposed as an (optional/computed) attribute so it can be preserved or ignored.

Current workaround: lifecycle { ignore_changes = all } on the osquery_manager integration policy, and upgrade the integration from the Fleet UI instead of from Terraform.

Debug output
Not captured during the affected apply. Happy to reproduce with TF_LOG=trace and attach it if needed.

Screenshots
N/A

Versions (please complete the following information):

  • OS: Linux
  • Terraform Version: 1.5.7
  • Provider version: v0.16.6
  • Elasticsearch Version: 9.5.5 (Kibana 9.5.5, Elastic Agent 9.5.5, osquery_manager 1.34.0 -> 1.35.1)

Additional context

  • Fleet policy revision history (.fleet-policies) showed the packs going from 4 entries to none in exactly the revision where Terraform upgraded osquery_manager. Upgrades of the other integrations in the same apply (auditd, windows, system) had no visible side effect.
  • Saving the pack again in Kibana writes it back into the package policy, so the packs come back until the next Terraform update.
  • Related: kibana#255381 (Kibana's own upgrade path is expected to carry packs over to the upgraded policy). Possibly related to how internal/fleet/integration_policy builds the update request body from inputs only.

Activity

  1. added
    needs-reproduction
    triaged
    on Nov 5, 2026
  2. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

    Thanks for the detailed bug report! I have added the needs-reproduction label to this issue.

    This looks like a reproducible bug: the report includes a Terraform configuration, clear reproduction steps, and a description of the observed vs. expected behaviour (input-level config for osquery_manager packs being dropped on update). It has been queued for the reproducer-factory pipeline, which will attempt to confirm the behaviour and create a minimal reproduction case.

    If this has been misclassified or there is additional context to add, please leave a comment so a maintainer can adjust the label manually.

  3. aydasraf commented on Nov 5, 2026

    @aydasraf
    Contributor

    We hit the same root cause with the Elastic APM integration, with a much louder impact than Osquery packs, so adding it here as a second reproduction.

    What happened

    When the APM integration is created, Kibana's APM plugin stores two API keys (owned by kibana_system, "Source map read access" and "Agent Configuration read access") in the APM input config:

    inputs[0].config["apm-server"].value.rum.source_mapping.elasticsearch.api_key
    inputs[0].config["apm-server"].value.agent.config.elasticsearch.api_key
    

    We adopted our existing APM integration policy into Terraform (elasticstack_fleet_integration_policy, apm 9.4.2). The first apply sent PUT /api/fleet/package_policies/<id> (simplified format), and the resulting Fleet policy revision no longer contained either key. The input id also changed from <package-policy-id> to apm-apmserver-<package-policy-id>. APM Server then fell back to the Fleet output API key, which cannot read the APM system indices:

    failed to sync sourcemaps metadata: fetcher unavailable: 403 Forbidden:
    action [indices:data/read/search] is unauthorized for API key id [...] of user [elastic/fleet-server]
    on indices [.apm-source-map], this action is granted by the index privileges [read,all]
    

    RUM source mapping dropped from ~40% of errors mapped to 0% within the same minute as the Terraform apply, on every APM Server instance, in both of our environments. Central agent configuration is affected the same way. Nothing in the plan showed the change, and no value of vars can bring the keys back because they live in config, not vars.

    Minimal reproduction (Kibana 9.4.2, provider 0.16.6)

    1. Create an APM integration policy with the resource (inputs = { "apmserver-apm" = { enabled = true, vars = jsonencode({ host = "0.0.0.0:8200", url = "http://0.0.0.0:8200", capture_personal_data = true }) } }).
    2. GET /api/fleet/package_policies/<id>: both API keys are present in inputs[0].config["apm-server"].value.
    3. Change capture_personal_data to false and apply.
    4. GET again: the var is updated, both API keys are gone.

    The same thing happens with a raw PUT ?format=simplified call, so the provider can't avoid it by changing what it sends in the simplified body. A typed (non-simplified) PUT carrying config does keep it.

    I've opened #5481 with a fix: it snapshots input and stream config via a typed GET before the simplified update and, if the update dropped anything, writes it back with one typed update (version + inputs only). It includes acceptance tests for both a generic out-of-band config and this APM case.

  4. added
    phase-specification
    on Nov 5, 2026
  5. added
    bug
    on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-reproductionphase-specificationtriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions