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: sanitize-command #403

Merged
merged 2 commits into from
Jan 27, 2025
Merged

feat: sanitize-command #403

merged 2 commits into from
Jan 27, 2025

Conversation

RaduPetreTarean
Copy link
Contributor

This PR introduces a new sanitize command to remove sensitive information from versioned OpenAPI specs before distribution.

Given a directory of compiled specs (one subfolder per version), the command loads each spec.yaml, filters out configurable extensions, headers, or entire paths, and saves the sanitized spec to a specified output directory.

vervet sanitize \
  --compiled-path ./internal/rest/api/versions \
  --out ./sanitized \
  --exclude-extension '^x-internal$' \
  --exclude-header '^X-Secret$' \
  --exclude-path '/internal'

This will read all spec.yaml files under each version subfolder, remove fields matching the exclusion criteria, and write sanitized openapi.yaml files to the ./sanitized directory.

@RaduPetreTarean RaduPetreTarean requested a review from a team as a code owner January 22, 2025 14:30
@gablaxian
Copy link
Contributor

--exclude-extension '^x-internal$' \
--exclude-header '^X-Secret$' \
--exclude-path '/internal'

Are these required? These seem unnecessary for this iteration if so, and make the command more complicated.

Usage: "Output directory for sanitized versions",
Value: "sanitized",
Required: false,
},
Copy link

Choose a reason for hiding this comment

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

I think compiled-path and out will remain the same most of the time. How about we add a DEFAULT for each and only pass the flags when we want the path and out to be different.

This could also apply to the other flags as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the out could be inferred from the compiled-path, i wanted to keep the utility away from the actual projects .vervet file such that it can be used by anyone on a simple directory of compiled specs by using the go run utility or similar

@RaduPetreTarean
Copy link
Contributor Author

--exclude-extension '^x-internal$' \
--exclude-header '^X-Secret$' \
--exclude-path '/internal'

Are these required? These seem unnecessary for this iteration if so, and make the command more complicated.

It allows the user to define which extensions/headers/paths etc he wants to strip out without us being explicit which ones. We could change this to be loaded from a separate config but the user will still have to define which ones as we cannot assume internal structure

Value: "sanitized",
Required: false,
},
&cli.StringSliceFlag{
Copy link
Contributor

Choose a reason for hiding this comment

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

should add this config to the config file? in the sanitise block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you propose adding a new sanitize block in .vervet? This could be weird as we already have the merge config with the exclude pattern doing the same thing, i wanted this utility to be separate from the project configuration so it can be run anywhere on any folder of compiled specs

@RaduPetreTarean RaduPetreTarean merged commit 4d8c2c2 into main Jan 27, 2025
12 checks passed
@RaduPetreTarean RaduPetreTarean deleted the feat/sanitize-command branch January 27, 2025 08:37
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.

4 participants