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

OPA support for persisted bundles with names using special characters in Windows #6915

Closed
alvarogomez93 opened this issue Aug 6, 2024 · 7 comments · Fixed by #6965
Closed

Comments

@alvarogomez93
Copy link
Contributor

alvarogomez93 commented Aug 6, 2024

What is the underlying problem you're trying to solve?

If a bundle uses a special character like such as ? in bundle name in the bundles config, Windows will fail to write the folder that persists the bundle since it uses the bundle name as a basis for the folder name.

For example, if a bundle is called: foo?context=bar, then the directory: foo?context=bar cannot be created to place the bundle.tar.gz inside.

An example config is:

"bundles": {
    "foo": {
...
        "resource": "/bundles/foo",
    },
    "foo?type=context": {
...
        "resource": "/bundles/foo?type=context",
    }
}

Describe the ideal solution

Allow setting a different folder name per bundle in the OPA config file.

Describe a "Good Enough" solution

Strip the special characters of the bundle name before creating the folder.

@anderseknert
Copy link
Member

@alvarogomez93 do you know if two different bundles can exist where the only difference is the query component? If not it would seem like a good enough solution to just strip that out. But if foo and foo?context=data could mean two different bundles altogether, that wouldn't work.

@alvarogomez93
Copy link
Contributor Author

@anderseknert in our case I believe the only difference in the name is the ?context part when we use separate data/policy bundles

@charlieegan3
Copy link
Contributor

charlieegan3 commented Aug 6, 2024

For clarity, here is an example: (thanks @alvarogomez93 for the pointers)

"bundles": {
    "foo": {
        "persist": true,
        "polling": {
            "max_delay_seconds": 15,
            "min_delay_seconds": 10
        },
        "resource": "/bundles/foo"
    },
    "foo?type=context": {
        "persist": true,
        "polling": {
            "max_delay_seconds": 15,
            "min_delay_seconds": 10
        },
        "resource": "/bundles/foo?type=context"
    }
}

@anderseknert
Copy link
Member

Thanks! That means we'll just have to decode it into something that is considered valid for a filename on all systems.

@ashutosh-narkar
Copy link
Member

Adding a new config that specifies the relative persistence path and defaults to the bundle name seems like a good choice.

@anderseknert
Copy link
Member

That would still leave us with a broken default in the case reported, and would put the onus on the user to change the configuration to work around the issue... that they may not even be aware of. So I'd go with just making a simple exception for this case, where we just escape (or transform) values that aren't valid for filesystem paths in any given OS we support.

@ashutosh-narkar
Copy link
Member

Sure. Sorry I meant let's fix this. And the configurable path option seems like good functionality to include.

@ashutosh-narkar ashutosh-narkar moved this from Backlog to Planning - v0.68 in Open Policy Agent Aug 12, 2024
ashutosh-narkar added a commit to ashutosh-narkar/opa that referenced this issue Aug 27, 2024
…ory name

In Windows there are some reserved characters that cannot be used in the names
of files and directories (eg. ?, *). If a bundle name contains these and if it's
configured to be persisted, the operation will fail on Windows. This change attempts
to fix this on Windows systems by escaping any encountered reserved characters before
using them in the bundle persistence path.

Fixes: open-policy-agent#6915

Signed-off-by: Ashutosh Narkar <[email protected]>
ashutosh-narkar added a commit that referenced this issue Aug 27, 2024
…ory name

In Windows there are some reserved characters that cannot be used in the names
of files and directories (eg. ?, *). If a bundle name contains these and if it's
configured to be persisted, the operation will fail on Windows. This change attempts
to fix this on Windows systems by escaping any encountered reserved characters before
using them in the bundle persistence path.

Fixes: #6915

Signed-off-by: Ashutosh Narkar <[email protected]>
@github-project-automation github-project-automation bot moved this from Planning - v0.68 to Done in Open Policy Agent Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants