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

schema: type checker doesn't work with in on typed arrays #5658

Open
anderseknert opened this issue Feb 13, 2023 · 1 comment
Open

schema: type checker doesn't work with in on typed arrays #5658

anderseknert opened this issue Feb 13, 2023 · 1 comment

Comments

@anderseknert
Copy link
Member

schema/input.json

{
    "type": "object",
    "properties": {
        "numbers": {
            "type": "array",
            "items": {
                "type": "number"
            }
        }
    },
    "additionalProperties": false
}

Below policy should not compile, as "admin" is not a number.

policy.rego

package policy

# METADATA
# schemas:
#   - input: schema.input
allow {
    "admin" in input.numbers
}

Switching to use old style iteration however does enforce the type:

"admin" == input.numbers[_]
opa eval -f pretty --schema schema/ -d policy.rego data.policy.allow
1 error occurred: policy/policy.rego:8: rego_type_error: match error
	left  : string
	right : number
@anderseknert
Copy link
Member Author

Looked briefly into this, and while the in is rewritten into an eq check, it seems the type information is somehow lost when looking up the type of the transformed var (__local1__ or whatever). Not immediately apparent to me why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants