Skip to content
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

[fingerprint] Add converter for SHA-512 #34007

Closed
mashhurs opened this issue Jul 9, 2024 · 1 comment
Closed

[fingerprint] Add converter for SHA-512 #34007

mashhurs opened this issue Jul 9, 2024 · 1 comment
Labels
enhancement New feature or request needs triage New item requiring triage pkg/ottl

Comments

@mashhurs
Copy link
Contributor

mashhurs commented Jul 9, 2024

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

A new sha-512 ottl function/converter transforms ingested data to a hash value.

This functionality is an extension to existing sha-1, sha-256 functions and there are use cases (storing password, verifying data) where users want stronger security (comparing to sha-256) with its larger hash value.

Describe the solution you'd like

Similar to sha256, crypto/sha512 will be utilized to calculate the hash value by rejecting nil/empty args with descriptive error message(s).
The API interface look like:

SHA512(attributes["device.name"])
SHA512("name")

Describe alternatives you've considered

Maybe attributeprocessor by specifying a hash param?!

Additional context

No response

@mashhurs mashhurs added enhancement New feature or request needs triage New item requiring triage labels Jul 9, 2024
Copy link
Contributor

github-actions bot commented Jul 9, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

TylerHelmuth pushed a commit that referenced this issue Aug 6, 2024
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Adds a converter to generate SHA-512 digest. See the #34007 issue for
more details.

**Link to tracking Issue:** #34007 

**Testing:**
- Unit testing
- E2E
- Local testing
- after applying changes, build `opentelemetry-collector-contrib`: `cd
opentelemetry-collector-contrib && make otelcontribcol`
- create config folder and place following config under
`otel-transform-sha512.yaml` file:
    ```
    extensions:
      zpages:
        endpoint: 127.0.0.1:55679

    receivers:
      otlp:
        protocols:
          http:
            endpoint: 127.0.0.1:8080

    processors:
      batch:
      transform:
        log_statements:
          - context: log
            statements:
- set(attributes["string.attribute"],
SHA512(attributes["string.attribute"]))

    exporters:
      debug:
        verbosity: detailed
      elasticsearch:
        hosts: ["localhost:9200"]
        user: "elastic"
        password: "changeme"
        index: "otel-collector-sha256"

    service:
      telemetry:
        logs:
          level: debug
      pipelines:
        logs:
          receivers: [otlp]
          processors: [batch, transform]
          exporters: [elasticsearch, debug]

      extensions: [zpages]
    ```
- run otel collector: `bin/otelcontribcol_darwin_amd64
--config=config/otel-transform-sha512.yaml`
  - send data
     ```
        curl --location '127.0.0.1:8080/v1/logs' \
    --header 'Content-Type: application/json' \
    --data '{
      "resourceLogs": [
        {
          "resource": {
            "attributes": [
              {
                "key": "service.name",
                "value": {
                  "stringValue": "my.service"
                }
              }
            ]
          },
          "scopeLogs": [
            {
              "scope": {
                "name": "my.library",
                "version": "1.0.0",
                "attributes": [
                  {
                    "key": "my.scope.attribute",
                    "value": {
                      "stringValue": "some scope attribute"
                    }
                  }
                ]
              },
              "logRecords": [
                {
                  "timeUnixNano": "1544712660300000000",
                  "observedTimeUnixNano": "1544712660300000000",
                  "severityNumber": 10,
                  "severityText": "Information",
                  "traceId": "5B8EFFF798038103D269B633813FC60C",
                  "spanId": "EEE19B7EC3C1B174",
                  "body": {
                    "stringValue": "Example log record"
                  },
                  "attributes": [
                    {
                      "key": "string.attribute",
                      "value": {
                        "stringValue": "sending some data for SHA512"
                      }
                    },
                    {
                      "key": "boolean.attribute",
                      "value": {
                        "boolValue": true
                      }
                    },
                    {
                      "key": "int.attribute",
                      "value": {
                        "intValue": "10"
                      }
                    },
                    {
                      "key": "double.attribute",
                      "value": {
                        "doubleValue": 637.704
                      }
                    },
                    {
                      "key": "array.attribute",
                      "value": {
                        "arrayValue": {
                          "values": [
                            {
                              "stringValue": "many"
                            },
                            {
                              "stringValue": "values"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "key": "map.attribute",
                      "value": {
                        "kvlistValue": {
                          "values": [
                            {
                              "key": "some.map.key",
                              "value": {
                                "stringValue": "some value"
                              }
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }'
    ``` 
  - you will be able to see SHA512 value on console
    ```
    ObservedTimestamp: 2018-12-13 14:51:00.3 +0000 UTC
    Timestamp: 2018-12-13 14:51:00.3 +0000 UTC
    SeverityText: Information
    SeverityNumber: Info2(10)
    Body: Str(Example log record)
    Attributes:
-> string.attribute:
Str(6cbe75a224033d0f145fd67e02cab35ce42a10cd1aa7b7030dd74e31af97037f2020d063305bc2552d1b9e43ca15872ea248c5b236df98085c690932a7f0ea49)
         -> boolean.attribute: Bool(true)
         -> int.attribute: Int(10)
         -> double.attribute: Double(637.704)
         -> array.attribute: Slice(["many","values"])
         -> map.attribute: Map({"some.map.key":"some value"})
    Trace ID: 5b8efff798038103d269b633813fc60c
    Span ID: eee19b7ec3c1b174
    ```
**Documentation:**
- Added to OTTL readme and changelogs generated. Let me please know if I
am missing any doc references.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New item requiring triage pkg/ottl
Projects
None yet
Development

No branches or pull requests

2 participants