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

Add capability to generate Pulumi policies when asked #47

Open
pierskarsenbarg opened this issue Jul 19, 2023 · 1 comment
Open

Add capability to generate Pulumi policies when asked #47

pierskarsenbarg opened this issue Jul 19, 2023 · 1 comment
Labels
kind/enhancement Improvements or new features

Comments

@pierskarsenbarg
Copy link
Member

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

Example prompt: "A typescript pulumi policy to stop security groups having ssh open to the internet"

Would generate something like:

import * as aws from "@pulumi/aws";
import { PolicyPack, validateResourceOfType } from "@pulumi/policy";

new PolicyPack("lambda", {
    policies: [
        {
            name: "security-group-policy",
            description: "Stop security group being open on port 22 to the internet",
            enforcementLevel: "mandatory",
            validateResource: validateResourceOfType(aws.ec2.SecurityGroup, (securitygroup, args, reportViolation) => {
                if(securitygroup.ingress !== undefined && securitygroup.ingress?.length > 0) {
                    if(securitygroup.ingress.find(x => x.fromPort == 22) &&
                        securitygroup.ingress.find(x => x.toPort == 22) &&
                        securitygroup.ingress.find(x => x.cidrBlocks?.indexOf("0.0.0.0/0") !== -1)
                    ) {
                        reportViolation("Security groups must not have port 22 open to the internet")
                    }
                }
                
            })
        }
    ],
});

No idea where you'd get the data to train this on, but I had a conversation about this today and it sounded like a good idea.

Affected area/feature

@pierskarsenbarg pierskarsenbarg added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Jul 19, 2023
@AaronFriel
Copy link

Policy as code sounds like an excellent thing to add to our test set.

I ran a query similar to this twice, and I think arrived at decent results. Curious what you think:

@AaronFriel AaronFriel removed the needs-triage Needs attention from the triage team label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants