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

feat: extend and improve API #28

Merged
merged 10 commits into from
Sep 14, 2023
Merged

feat: extend and improve API #28

merged 10 commits into from
Sep 14, 2023

Conversation

ramizpolic
Copy link
Member

@ramizpolic ramizpolic commented Sep 8, 2023

Overview

This PR extends the API and adds support for advanced capabilities including bootstrapping, querying, and templating.

Example

## Defines how the secrets will be synced
sync:
  ## 1. Usage: Sync key from ref
  - secretRef:
      key: /source/credentials/username
    target: # If not specified, will be synced under the same key
      key: /target/example-1

  ## 2. Usage: Sync all keys from query
  - secretQuery:
      path: /source/credentials
      key:
        regexp: .*
    target: # If not specified, all keys will be synced under the same path
      keyPrefix: /target/example-2/

  ## 3. Usage: Sync key from ref with templating
  - secretRef:
      key: /source/credentials/password
    target:
      key: /target/example-3

    # Template defines how the secret will be synced to dest store.
    # Either "rawData" or "data" should be specified, not both.
    template:
      rawData: '{{ .Data }}'   # Save as raw (accepts multiline string)
      data:                    # Save as map (accepts nested values)
        example: '{{ .Data }}'

  ## 4. Usage: Sync all keys from query with templating
  - secretQuery:
      path: /source/credentials
      key:
        regexp: .*
    target:
      keyPrefix: /target/example-4/
    template:
      rawData: 'SECRET-PREFIX-{{ .Data }}'

  ## 5. Usage: Sync single key from query with templating
  - secretQuery:
      path: /source/credentials/query-data/
      key:
        regexp: (username|password)
    target:
      key: /target/example-5

    template:
      data:
        user: '{{ .Data.username }}'
        pass: '{{ .Data.password }}'

  ## 6. Usage: Sync single key from multiple sources with templating
  - secretSources:
    - name: username # Username mapping, available as ".Data.username"
      secretRef:
        key: /source/credentials/username

    - name: password # Password mapping, available as ".Data.password"
      secretRef:
        key: /source/credentials/password

    - name: dynamic_query # Query mapping, available as "Data.dynamic_query.<key>"
      secretQuery:
        path: /source/credentials
        key:
          regexp: .*

    target:
      key: /target/example-6

    template:
      data:
        username: '{{ .Data.username }}'
        password: '{{ .Data.password }}'
        userpass: '{{ .Data.dynamic_query.username }}/{{ .Data.dynamic_query.password }}'

Features

  • Sync secret from reference, query, or combined into a single secret
  • Sync secrets from query to multiple secrets
  • Template secret values before sending them to the targeted secret store
  • Simplifies API (removes unused Permissions, improves naming conventions, simplifies docs)

TODO

  • Better validation
  • Handle encoding/decoding
  • Extend API to support
    • key collisions (trying to update the same key)
    • missing values (accessing dynamic query results)
    • syncing items from a (source) matrix
    • syncing constants (e.g. secrets from ENV)

@ramizpolic ramizpolic force-pushed the feat/update-api branch 2 times, most recently from d69fc7e to d60e2ad Compare September 9, 2023 00:26
@ramizpolic ramizpolic changed the title feat: simplify and improve API feat: extend and improve API Sep 9, 2023
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
@ramizpolic ramizpolic marked this pull request as ready for review September 14, 2023 13:33
@ramizpolic ramizpolic requested a review from a team as a code owner September 14, 2023 13:33
@ramizpolic ramizpolic requested review from sagikazarmark and removed request for a team September 14, 2023 13:33
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Signed-off-by: Ramiz Polic <ramiz.polic@hotmail.com>
Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

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

LGTM

@ramizpolic ramizpolic merged commit e0549ab into main Sep 14, 2023
12 checks passed
@ramizpolic ramizpolic deleted the feat/update-api branch September 14, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants