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

config: Allow configuration of capabilities #423

Merged
merged 7 commits into from
Oct 31, 2023
Merged

Conversation

charlieegan3
Copy link
Member

This is a first pass at making it possible to configure capabilities in regal.

I haven't yet updated the regoArgs to use this from the config since I wanted to get some feedback on the impl first.

Related: #212

@anderseknert
Copy link
Member

Looks great @charlieegan3 👍 I think it makes sense to add a file option too while we do this, so that it's easy to bring your own if you have one already.

This is a first pass at making it possible to configure
capabilities in regal.

I haven't yet updated the regoArgs to use this from the config since
I wanted to get some feedback on the impl first.

Signed-off-by: Charlie Egan <[email protected]>
@charlieegan3
Copy link
Member Author

I've added this in cebcec1, I think it makes sense to have an error when setting the engine and file.

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Looks good! Just two questions, then we can have this merged and start building on top of this 👍

Ignore Ignore `json:"ignore,omitempty" yaml:"ignore,omitempty"`
Rules map[string]Category `json:"rules" yaml:"rules"`
Ignore Ignore `json:"ignore,omitempty" yaml:"ignore,omitempty"`
Capabilities ast.Capabilities `json:"capabilities,omitempty" yaml:"capabilities,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Weird — the formatting looks off here, but there's no linter rule violation 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that doesn't look right... I have fixed it manually in eeda01e

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! I'll look into why the linter didn't flag this.


config.Capabilities.Builtins = append(config.Capabilities.Builtins, result.Capabilities.Plus.Builtins...)

return nil
Copy link
Member

Choose a reason for hiding this comment

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

If no capabilities have been provided, should we default to latest from OPA here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've had a go a finishing this off a little more in 1fff993

Copy link
Member

Choose a reason for hiding this comment

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

Awesome! Thanks 😃 Looks good to me.

The one thing I'm not sure about is passing the capabilities from the config to Rego's eval args. Would that not have the linter (i.e. Regal) itself be limited to whatever capabilities the target policy has? I mean, even if we're linting a Rego file with e.g. a pre-contains OPA version, surely we should be able to use contains in Regal's linter policy?

I think the way we'll want to use the capabilities at least initially, is basically as a datasource for what built-in functions we might encounter in the policy we're linting, and have linter rules be able to declare their dependencies... like how we should skip the custom-has-key-construct if object.keys is not in the capabilities, and so on.

But if we eval with the provided capabilities, it would mean we can't use object.keys, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, I see. I think I got the wrong end of the stick! I can take this part out.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've taken out the changes in 5d79a7b and then added the defaulting back in d292b58

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

Signed-off-by: Charlie Egan <[email protected]>
@anderseknert anderseknert merged commit dd36d70 into main Oct 31, 2023
3 checks passed
@anderseknert anderseknert deleted the capabilities branch October 31, 2023 09:34
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
This is a first pass at making it possible to configure capabilities in regal.

Signed-off-by: Charlie Egan <[email protected]>
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