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

std.parseYaml #460

Closed
sbarzowski opened this issue Feb 22, 2018 · 19 comments
Closed

std.parseYaml #460

sbarzowski opened this issue Feb 22, 2018 · 19 comments

Comments

@sbarzowski
Copy link
Collaborator

Importing YAML files was requested by multiple people, it was proposed in #196 and popped up in various discussions. Also YAML files are very popular in the Kubernetes communities which are heavy users of jsonnet.

Implementing library function (probably builtin) parseYaml would allow processing yaml files with jsonnet. It would require importing it first through importstr then invoking parseYaml on the result. Later we can think about automatically applying it based on extension or something.

Relatedly imporstr and parseJson should be used rather than import when dealing with json (not jsonnet) files, especially if they are not 100% trusted (consider imporstr "/etc/passwd").

Challenges:

  • YAML is complicated, making it very difficult to keep byte-for-byte compatibility
  • The existing parsers may be slightly non-compliant
  • Safe vs unsafe yaml

@benley, @nikolay

@anguslees
Copy link
Contributor

anguslees commented Mar 5, 2018

Fwiw, here's an example implementation:
https://github.com/ksonnet/kubecfg/blob/5197d89819dfe3527e29cc4cbb0afc3fec9e72f5/utils/nativefuncs.go#L63

In particular, note that a YAML file is actually an array (aka stream) of YAML-encoded values, which implies a function signature slightly different to an otherwise-similar parseJson

@sbarzowski
Copy link
Collaborator Author

Nice

In particular, note that a YAML file is actually an array (aka stream) of YAML-encoded values, which implies a function signature slightly different to an otherwise-similar parseJson

Perhaps we should have both parseYamlStream and parseYaml then.

@PaulRudin
Copy link
Contributor

Regarding the importing of json. Presumably this is just a recommendation, since valid json is valid jsonnet, there's nothing to stop people using import on json files?

@sparkprime
Copy link
Member

Yes it'd be a way to allow people to write scripts that can import "untrusted" JSON, i.e. JSON that worst case has bad values in it, not JSON that reads weird files. Although, to be honest, we should probably just sandbox the filesystem, e.g. not allow imports to escape the CWD.

@teralype
Copy link

teralype commented Nov 5, 2019

Any progress on this?

@sbarzowski
Copy link
Collaborator Author

The std.parseJson part is released. There is no concrete progress on parseYaml/parseYamlStream. We currently have quite a few things in the queue, so it's going to be a while until we get to it. Ofc we're happy to accept PRs.

@aglover-zendesk
Copy link

Although, to be honest, we should probably just sandbox the filesystem, e.g. not allow imports to escape the CWD.

Feature request - please don't do this. I'd rather do imporstr and parseJson or something else to ensure security, rather than be restricted to CWD and child directories. Directory limitations is one of the reasons Kustomize is so unpleasantly restrictive. Storing shared JSONNET libraries and templates outside of the CWD has been a useful pattern.

@sbarzowski
Copy link
Collaborator Author

@aglover-zendesk

Just to be clear, it would still be possible to explicitly add the directory that you are interested in (by adding them to Jsonnet library path, e.g. jsonnet -J "/home/my_user/my_jsonet_stuff"). The proposal was to disallow things like import "/some/absolute/path" or import "../../../../../../etc/passwd". Do you think that would be annoying?

@jjo
Copy link

jjo commented Dec 7, 2019

It would be pretty impactful for us, we use something like <cluster>/<namespace>/component.jsonnet importing e.g. ../../common/component.libsonnet while relying on -J for "base" libraries.
Obviously non-issue if it'd be behind a runtime flag.
Note that projects embedding jsonnet are other stakeholders on this policy/change.

1 similar comment
@jjo
Copy link

jjo commented Dec 7, 2019

It would be pretty impactful for us, we use something like <cluster>/<namespace>/component.jsonnet importing e.g. ../../common/component.libsonnet while relying on -J for "base" libraries.
Obviously non-issue if it'd be behind a runtime flag.
Note that projects embedding jsonnet are other stakeholders on this policy/change.

@aglover-zendesk
Copy link

@sbarzowski using the -J flag for importing content from other dirs seems reasonable. Alternatively having a separate flag to disable the CWD limitation would work, that way users would have to opt in to use the less secure behavior.

@sbarzowski
Copy link
Collaborator Author

sbarzowski commented Dec 8, 2019

Thanks for the feedback. FYI there are no immediate plans to enforce FS sandboxing for importing and if we come back to this in the future, we'll try to do it in the least disruptive way.

@underrun
Copy link

underrun commented Jan 7, 2021

is there any sense of a timeline on when this issue might be more deeply considered?

@sbarzowski sbarzowski changed the title std.parseYaml (and std.parseJson) std.parseYaml Jan 8, 2021
@sbarzowski
Copy link
Collaborator Author

sbarzowski commented Jan 8, 2021

We already have parseJson. I would like to have parseYaml in the next release. We have go-jsonnet implementation ready. We need to add it here as well. There is more discussion about it in in google/go-jsonnet#339.

@pmorch
Copy link
Contributor

pmorch commented Oct 18, 2021

std.parseYaml() exists in the cpp version in the master branch since commit da1490f. It was introduced by the merge of #899.

Interestingly, the documentation says it is:

Available since version x.y.z.

No official release contains commit da1490f yet.

@igorwwwwwwwwwwwwwwwwwwww

That cpp commit landed in https://github.com/google/jsonnet/releases/tag/v0.18.0.

@sbarzowski
Copy link
Collaborator Author

To be closed when we update the docs

@groodt
Copy link
Contributor

groodt commented Sep 7, 2022

Can't this be closed now @sbarzowski ?

The docs website does include parseYaml...

@sbarzowski
Copy link
Collaborator Author

@groodt thanks!

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

No branches or pull requests