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

Adding required environment variable rules logic. #1505

Merged
merged 1 commit into from
Sep 9, 2022
Merged

Adding required environment variable rules logic. #1505

merged 1 commit into from
Sep 9, 2022

Conversation

matajoh
Copy link
Member

@matajoh matajoh commented Sep 9, 2022

If an environment variable rule is marked as "required", then it must be defined in the container. This is enforced in the Rego in the following way:

env_ok(pattern, "string", value) {
    pattern == value
}

env_ok(pattern, "re2", value) {
    regex.match(pattern, value)
}

rule_ok(rule, env) {
    not rule.required
}

rule_ok(rule, env) {
    rule.required
    env_ok(rule.pattern, rule.strategy, env)
}

envList_ok(container) {
    every env in input.envList {
        some rule in container.env_rules
        env_ok(rule.pattern, rule.strategy, env)
    }

    every rule in container.env_rules {
        some env in input.envList
        rule_ok(rule, env)
    }
}

Signed-off-by: Matthew A Johnson matjoh@microsoft.com

@matajoh matajoh requested a review from a team as a code owner September 9, 2022 09:48
@matajoh matajoh changed the title Adding required rules logic. Adding required environment variable rules logic. Sep 9, 2022
If an environment variable rule is marked as "required", then it must be defined in the container.
This is enforced in the Rego in the following way:

``` rego
env_ok(pattern, "string", value) {
    pattern == value
}

env_ok(pattern, "re2", value) {
    regex.match(pattern, value)
}

rule_ok(rule, env) {
    not rule.required
}

rule_ok(rule, env) {
    rule.required
    env_ok(rule.pattern, rule.strategy, env)
}

envList_ok(container) {
    every env in input.envList {
        some rule in container.env_rules
        env_ok(rule.pattern, rule.strategy, env)
    }

    every rule in container.env_rules {
        some env in input.envList
        rule_ok(rule, env)
    }
}
```

Signed-off-by: Matthew A Johnson <matjoh@microsoft.com>
@dcantah dcantah merged commit 9f5b8f9 into microsoft:main Sep 9, 2022
@anmaxvl anmaxvl deleted the required-rules-2 branch September 9, 2022 17:59
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.

None yet

3 participants