Skip to content

all: secrets cannot contain $$ or ${SOMETEXT} #188377

Closed
@efd6

Description

Relates:

This was identified while working on a customer issue with the ti_threatconnect integration. In that issue we were seeing 400 status codes coming back from API queries. After tracking down the cause, it is seen to come from variable expansion when taking the provided config and rendering it for beats. The secret in question had an instance of the substring $$ which was being interpreted as a $-escaped $.

This causes confusion for users and is not ideal.

To reproduce this.

  1. Start a stack with elastic-package.

  2. Add the ThreatConnect integration with the Elastic-Agent (elastic-package) as the agent with the following config.
    Screenshot from 2024-04-24 09-17-25

  3. Save and deploy.

  4. Collect diagnostics from the agent and examine the pre-config.yaml file for the package installation.

    inputs:
        - data_stream:
            namespace: default
          id: cel-threatconnect-dd614c67-bb84-47de-b23e-93c5f3ce6753
          meta:
            package:
                name: ti_threatconnect
                version: 0.4.0
          name: ti_threatconnect-1
          package_policy_id: dd614c67-bb84-47de-b23e-93c5f3ce6753
          revision: 1
          streams:
            - config_version: 2
              data_stream:
                dataset: ti_threatconnect.indicator
                type: logs
              fields:
                _conf:
                    ioc_expiration_duration: 90d
              fields_under_root: true
              id: cel-ti_threatconnect.indicator-dd614c67-bb84-47de-b23e-93c5f3ce6753
              interval: 24h
              program: |
    <snip>
             publisher_pipeline.disable_host: true
              redact:
                fields:
                    - secret_key
              resource.ssl: null
              resource.timeout: 2m
              resource.url: https://example.com
              state:
                access_id: user
                batch: 5000
                counter: 0
                event_list:
                    - associatedGroups
                    - associatedIndicators
                    - attributes
                    - securityLabels
                    - sightings
                    - tags
                    - threatAssess
                initial_interval: 168h
                secret_key: 1$$2$$$$3$$$$$$4
                want_more: false
              tags:
                - forwarded
                - threatconnect-indicator
          type: cel
          use_output: default
    

    Examine the corresponding components/cel-default/beat-rendered-config.yml file.

    inputs:
        - config_version: 2
          data_stream:
            dataset: ti_threatconnect.indicator
            type: logs
          fields:
            _conf:
                ioc_expiration_duration: 90d
          fields_under_root: true
          id: cel-ti_threatconnect.indicator-dd614c67-bb84-47de-b23e-93c5f3ce6753
          index: logs-ti_threatconnect.indicator-default
          interval: 24h
          processors:
            - add_fields:
                fields:
                    input_id: cel-threatconnect-dd614c67-bb84-47de-b23e-93c5f3ce6753
                target: '@metadata'
            - add_fields:
                fields:
                    dataset: ti_threatconnect.indicator
                    namespace: default
                    type: logs
                target: data_stream
            - add_fields:
                fields:
                    dataset: ti_threatconnect.indicator
                target: event
            - add_fields:
                fields:
                    stream_id: cel-ti_threatconnect.indicator-dd614c67-bb84-47de-b23e-93c5f3ce6753
                target: '@metadata'
            - add_fields:
                fields:
                    id: 07d963cd-5e9a-4ef1-a3b7-f4c3776c0389
                    snapshot: false
                    version: 8.13.0
                target: elastic_agent
            - add_fields:
                fields:
                    id: 07d963cd-5e9a-4ef1-a3b7-f4c3776c0389
                target: agent
          program: |
    <snip>
          publisher_pipeline:
            disable_host: true
          redact:
            fields:
                - secret_key
          resource:
            ssl: null
            timeout: 2m
            url: https://example.com
          state:
            access_id: user
            batch: 5000
            counter: 0
            event_list:
                - associatedGroups
                - associatedIndicators
                - attributes
                - securityLabels
                - sightings
                - tags
                - threatAssess
            initial_interval: 168h
            secret_key: 1$2$$3$$$4
            want_more: false
          tags:
            - forwarded
            - threatconnect-indicator
          type: cel
    

    Note that the secret_key has had each of the $$ resolved to $. This results in failure to authenticate to the API. This is confusing for customers who have values that include these sequences.

    The change is a result of variable expansion when the beats config is rendered and would also be expected to result in changes if the secret (or other field) included syntax that would be expected to expand, for example ${NOT_A_VAR}.
    Screenshot from 2024-04-24 09-31-19
    This results in no error, but also no component being run
    Screenshot from 2024-04-24 09-32-36
    and no components in the diags.
    Screenshot from 2024-04-24 09-34-39
    The input shows up in the pre-config.yaml, but nothing is present in the computed-config.yaml.

    agent:
        download:
            sourceURI: https://artifacts.elastic.co/downloads/
        features: null
        monitoring:
            enabled: false
            logs: false
            metrics: false
        protection:
            enabled: false
            signing_key: <REDACTED>
            uninstall_token_hash: <REDACTED>
    fleet:
        hosts:
            - https://fleet-server:8220
    host:
        id: 8259e024976a406e8a54cdbffeb84fec
    id: elastic-agent-managed-ep
    inputs: []
    output_permissions:
        default:
            _elastic_agent_checks:
                cluster:
                    - monitor
            _elastic_agent_monitoring:
                indices: []
            642d500a-11a1-4f61-b28b-e8bd927a7c1f:
                indices:
                    - names:
                        - logs-ti_threatconnect.indicator-default
                      privileges:
                        - auto_configure
                        - create_doc
    outputs:
    <snip>
    

Related issues: elastic/elastic-agent#2177 elastic/elastic-agent#2261 elastic/beats#35260

Metadata

Assignees

Labels

Team:FleetTeam label for Observability Data Collection Fleet teambugFixes for quality problems that affect the customer experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions