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

Safe templating of json in bash scripts #853

Closed
justaugustus opened this issue Aug 20, 2019 · 2 comments · Fixed by #898
Closed

Safe templating of json in bash scripts #853

justaugustus opened this issue Aug 20, 2019 · 2 comments · Fixed by #898
Assignees
Labels
area/release-eng Issues or PRs related to the Release Engineering subproject help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/release Categorizes an issue or PR as relevant to SIG Release.

Comments

@justaugustus
Copy link
Member

There are a few places in our scripts where we template JSON directly in bash e.g.,

release/anago

Lines 1131 to 1138 in c32c094

'{
"tag_name": "'$RELEASE_VERSION_PRIME'",
"target_commitish": "'$RELEASE_BRANCH'",
"name": "'$RELEASE_VERSION_PRIME'",
"body": "See [kubernetes-announce@](https://groups.google.com/forum/#!forum/kubernetes-announce) and ['$CHANGELOG_FILE']('$changelog_url'#'${RELEASE_VERSION_PRIME//\./}') for details.\n\nSHA512 for `kubernetes.tar.gz`: `'$sha_hash'`\n\nAdditional binary downloads are linked in the ['$CHANGELOG_FILE']('$changelog_url'#downloads-for-'${RELEASE_VERSION_PRIME//\./}').",
"draft": '$draft',
"prerelease": '$prerelease'
}' |jq -r '.id')

As @hoegaarden mentions, it'd be nicer/less scary to handle this in a safer way via jq, like this:

release/lib/gitlib.sh

Lines 341 to 352 in c32c094

template='{
"title": $title,
"body": $body,
"milestone": $milestone,
}'
data="$( jq \
--argjson milestone "$milestone" \
--arg body "$body" \
--arg title "$title" \
-c -n "$template"
)"

This is another good one for a Release Manager Associate to take up.

/help
cc: @kubernetes/release-engineering
/area release-eng
/priority important-longterm
/kind cleanup

@k8s-ci-robot
Copy link
Contributor

@justaugustus:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

There are a few places in our scripts where we template JSON directly in bash e.g.,

release/anago

Lines 1131 to 1138 in c32c094

'{
"tag_name": "'$RELEASE_VERSION_PRIME'",
"target_commitish": "'$RELEASE_BRANCH'",
"name": "'$RELEASE_VERSION_PRIME'",
"body": "See [kubernetes-announce@](https://groups.google.com/forum/#!forum/kubernetes-announce) and ['$CHANGELOG_FILE']('$changelog_url'#'${RELEASE_VERSION_PRIME//\./}') for details.\n\nSHA512 for `kubernetes.tar.gz`: `'$sha_hash'`\n\nAdditional binary downloads are linked in the ['$CHANGELOG_FILE']('$changelog_url'#downloads-for-'${RELEASE_VERSION_PRIME//\./}').",
"draft": '$draft',
"prerelease": '$prerelease'
}' |jq -r '.id')

As @hoegaarden mentions, it'd be nicer/less scary to handle this in a safer way via jq, like this:

release/lib/gitlib.sh

Lines 341 to 352 in c32c094

template='{
"title": $title,
"body": $body,
"milestone": $milestone,
}'
data="$( jq \
--argjson milestone "$milestone" \
--arg body "$body" \
--arg title "$title" \
-c -n "$template"
)"

This is another good one for a Release Manager Associate to take up.

/help
cc: @kubernetes/release-engineering
/area release-eng
/priority important-longterm
/kind cleanup

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Aug 20, 2019
@hasheddan
Copy link
Contributor

@justaugustus I am happy to take this one!

/assign @hasheddan

@justaugustus justaugustus added the sig/release Categorizes an issue or PR as relevant to SIG Release. label Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/release-eng Issues or PRs related to the Release Engineering subproject help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/release Categorizes an issue or PR as relevant to SIG Release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants