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(core): add a schema for policy files #620

Closed
wants to merge 4 commits into from

Conversation

boneskull
Copy link
Contributor

@boneskull boneskull commented Jul 13, 2023

Thought this might come in handy. Needs titles, descriptions and such.

This seems like a reasonable idea for schema versioning.

To test in VS Code, you can add this property to any policy file:

"$schema": "https://raw.githubusercontent.com/boneskull/LavaMoat/boneskull/policy-schema/packages/core/schema/lavamoat-policy.v0-0-1.schema.json"

@boneskull boneskull self-assigned this Jul 25, 2023
@boneskull boneskull requested a review from naugtur July 25, 2023 20:38
@boneskull
Copy link
Contributor Author

@naugtur I'm unsure if we're going to be adopting Endo's policy format, or if they will adopt ours, or what. Here's this, anyway. Please let me know what you think.

@boneskull boneskull changed the title [DRAFT] feat(core): add a schema for policy files feat(core): add a schema for policy files Jul 25, 2023
@boneskull boneskull marked this pull request as ready for review July 25, 2023 20:40
@boneskull boneskull added the enhancement New feature or request label Jul 25, 2023
@naugtur
Copy link
Member

naugtur commented Jul 26, 2023

@naugtur I'm unsure if we're going to be adopting Endo's policy format, or if they will adopt ours, or what. Here's this, anyway. Please let me know what you think.

I wrote policy support in Endo to be a low level representation of something powerful enough to support our current format (via translation and setup) but also many other formats.

One of the first steps on the path to rebuilding lavamoat-node on top of Endo is going to be a translation function and an attenuator to consume our current policy shape.

There's also a potential future where our policy allows specifying "network access" as a category that gets translated into what's needed.

@boneskull
Copy link
Contributor Author

boneskull commented Jul 27, 2023

@naugtur Seems like it'd be good then to formalize the policy format.

What I don't have here are things like titles and descriptions of the various properties, and that would be helpful for someone (you?) to provide so that I can fill it in:

  • Title/description of entire schema. Currently this is "LavaMoat Policy Schema"
  • Title/description of resources prop
  • Title/description of globals, builtins and packages within the resources prop
  • Title/description of resolutions property (WIP)
  • Title/description of moduleRecord property (WIP) and its properties This looks like it's part of some debugging information??

@boneskull boneskull marked this pull request as draft July 27, 2023 01:12
@boneskull
Copy link
Contributor Author

boneskull commented Jul 27, 2023

Converting back to draft. Need to implement moduleRecord and resolutions, as well as probably add some sort of validator for testing purposes. We can choose to validate at runtime later.

@naugtur
Copy link
Member

naugtur commented Aug 17, 2023

We will not normalize policy between Endo and LAvamoat as their scope differs. Endo's policy is low level, while LavaMoat is aiming to be more human readable. We're hoping to one day have the ability to put more general terms in the policy that'd get translated over to the low level policy like "network":true for better developer experience.

So there's going to be one policy format in Endo and potentially more than one format in LavaMoat

@boneskull boneskull force-pushed the boneskull/normalize-test-filenames branch 2 times, most recently from 34b2c42 to 61db1f9 Compare August 17, 2023 23:58
@boneskull boneskull force-pushed the boneskull/policy-schema branch 2 times, most recently from e61ee01 to a431b0c Compare August 18, 2023 00:18
@boneskull boneskull force-pushed the boneskull/normalize-test-filenames branch from 30d88e0 to 96c905b Compare August 21, 2023 21:45
@boneskull boneskull changed the base branch from boneskull/normalize-test-filenames to main August 21, 2023 22:50
@boneskull boneskull force-pushed the boneskull/policy-schema branch 2 times, most recently from dedde1d to fded394 Compare August 22, 2023 00:34
@boneskull boneskull marked this pull request as ready for review August 22, 2023 00:35
@boneskull boneskull requested a review from a team August 22, 2023 00:35
@boneskull
Copy link
Contributor Author

This looks OK for now.

Usually I'd want to use something like json-schema-to-typescript to generate the .d.ts, but it doesn't support patternProperties or anyOf very well, so I just handrolled it.

@boneskull boneskull force-pushed the boneskull/policy-schema branch 2 times, most recently from 92ca4a6 to 1796c2f Compare August 28, 2023 20:25
@boneskull boneskull force-pushed the boneskull/policy-schema branch 2 times, most recently from dfbef5e to 5132152 Compare September 1, 2023 22:51
@boneskull boneskull force-pushed the boneskull/policy-schema branch 4 times, most recently from 0a8d5c1 to 76d575a Compare September 12, 2023 21:24
I pulled in [ajv](https://npm.im/ajv) for this. I had tried to use [z-schema](https://npm.im/z-schema) but I couldn't get it working quickly (apparently you need to supply the metaschema??) so abandoned it.  If there's a more lightweight, _maintained_ solution, I'm happy to try it.
@boneskull
Copy link
Contributor Author

Closing this and opening from new branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants