Skip to content

feat(security/pipeline): Add Pipeline to add more possibilities to the security builder#38

Merged
42atomys merged 18 commits intomainfrom
42Atomys/factory_pipeline
Mar 7, 2022
Merged

feat(security/pipeline): Add Pipeline to add more possibilities to the security builder#38
42atomys merged 18 commits intomainfrom
42Atomys/factory_pipeline

Conversation

@42atomys
Copy link
Owner

@42atomys 42atomys commented Mar 6, 2022

Relative Issues: Resolve #22 , resolve #21, resolve #9, resolve #10, resolve #11

Describe the pull request
The current version of the security factories works in a very basic way and does not allow advanced uses like comparing several objects of different steps or allowing later the comparison of HMAC which is for example useful for the webhook of GitHub or Twitch.

For this we had to rewrite version 1 of the factory builder to add a so-called Pipeline overlay

In other words, stop me, I recoded the GitHub Actions system in one night, f***

TODO

Checklist

  • I have linked the relative issue to this pull request
  • I have made the modifications or added tests related to my PR
  • I have added/updated the documentation for my RP
  • I put my PR in Ready for Review only when all the checklist is checked

Breaking changes ?
yes

Additional context

Concrete example, actual static comparaison of an header with factory/v1.Builder

security:
  - getHeader:
      name: X-Hook-Secret
  - compareWithStaticValue:
      values: ['foo', 'bar']

New version builder with factory/v2.Pipeline

security:
- header:
    id: secretHeader
    inputs:
    - name: headerName
      valueFrom:
        envRef: HEADER
- compare:
    id: secretCompare
    inputs:
    - name: first
      value: '{{ .Outputs.secretHeader.value }}'
    - name: second
      value: 'developmentSecret'
      valueFrom:
        envRef: HOOK_SECRET

@42atomys 42atomys self-assigned this Mar 6, 2022
@42atomys 42atomys added this to the 1.0 milestone Mar 6, 2022
@42atomys
Copy link
Owner Author

42atomys commented Mar 7, 2022

Config to allow IP based on X-Forwarded-For header:

  security:
  - header:
      inputs:
      - name: headerName
        value: X-Forwarded-For
  - hasPrefix:
      inputs:
      - name: text
        value: '{{ .Outputs.header.value }}'
      - name: prefix
        values: ['127.0.0.1', '[::1]']

Config to allow IP based on RemoteAddr

  security:
  - hasPrefix:
      inputs:
      - name: text
        value: '{{ .Inputs.request.RemoteAddr }}'
      - name: prefix
        values: ['127.0.0.1', '[::1]']

Config to reject (only add inverse: true)

  security:
  - hasPrefix:
      inverse: true
      inputs:
      - name: text
        value: '{{ .Inputs.request.RemoteAddr }}'
      - name: prefix
        values: ['127.0.0.1', '[::1]']

@42atomys
Copy link
Owner Author

42atomys commented Mar 7, 2022

Webhook configuration for Github (Tested OK | Security OK)

- name: github
  entrypointUrl: /webhooks/github
  security:
  - generate_hmac_256:
      id: signature
      inputs:
      - name: payload
        value: '{{ .Inputs.payload }}'
      - name: secret
        valueFrom:
          envRef: GITHUB_WEBHOOK_SECRET 
  - header:
      id: headerSignature
      inputs:
      - name: headerName
        value: X-Hub-Signature-256
  - compare:
      inputs:
      - name: first
        value: '{{ .Outputs.headerSignature.value }}'
      - name: second
        value: 'sha256={{ .Outputs.signature.value }}'
  storage:
  - type: redis
    specs:
      host: localhost
      port: '6379'
      database: 0
      key: github

@42atomys
Copy link
Owner Author

42atomys commented Mar 7, 2022

Webhook configuration for Gitlab (Tested OK | Security OK)

- name: gitlab
  entrypointUrl: /webhooks/gitlab
  security:
  - header:
      inputs:
      - name: headerName
        value: X-Gitlab-Token
  - compare:
      inputs:
      - name: first
        value: '{{ .Outputs.header.value }}'
      - name: second
        valueFrom:
          envRef: GITLAB_WEBHOOK_TOKEN
  storage:
  - type: redis
    specs:
      host: localhost
      port: '6379'
      database: 0
      key: gitlab

@42atomys 42atomys marked this pull request as ready for review March 7, 2022 07:17
@42atomys 42atomys requested a review from rgaiffe March 7, 2022 07:17
Copy link
Collaborator

@rgaiffe rgaiffe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with few changes.

@42atomys 42atomys requested a review from rgaiffe March 7, 2022 15:21
@42atomys 42atomys merged commit 28b7cd2 into main Mar 7, 2022
@42atomys 42atomys deleted the 42Atomys/factory_pipeline branch March 7, 2022 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants