Bug 1157830 - Cron cartridge: loading of environment variables underquoted
Summary: Cron cartridge: loading of environment variables underquoted
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: OpenShift Online
Classification: Red Hat
Component: Image
Version: 2.x
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
: ---
Assignee: Vojtech Vitek
QA Contact: libra bugs
URL:
Whiteboard:
Depends On:
Blocks: 1158851 1158868
TreeView+ depends on / blocked
 
Reported: 2014-10-27 19:10 UTC by Daniel Tschan, Puzzle ITC
Modified: 2015-05-15 00:45 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1158851 1158868 (view as bug list)
Environment:
Last Closed: 2015-02-18 16:52:27 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Daniel Tschan, Puzzle ITC 2014-10-27 19:10:24 UTC
Description of problem:
The loading of environment variables (system and user defined) is underquoted, resulting in unwanted word splitting and filename expansion.

Version-Release number of selected component (if applicable):
OpenShift Online as of 10-27-2014.

How reproducible:
Always

Steps to Reproduce:
1. rhc env set NAME="John Doe"
2. Add cron cartridge to any OpenShift app
3. Create cron job .openshift/cron/minutely/env.sh as follows:

#! /bin/sh

env >/tmp/env.txt

4. Wait a minute
5. grep ^NAME= /tmp/env.txt

Actual results:
NAME=John

Expected results:
NAME=John Doe

Additional info:
Naturally the bug also appears on OpenShift Enterprise. Verified with OpenShift Enterprise 2.0.8.

The culprits seem to be the following lines in '/usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh' of the cron cartridge:

local contents=$(< $1)

export $key=$(< $1)

which should instead read:

local contents="$(< $1)"

export $key="$(< $1)"

Comment 1 Vojtech Vitek 2014-10-30 00:09:27 UTC
Hey Daniel, thanks for this bug report and the provided fix. Much appreciated!

Comment 3 Vojtech Vitek 2014-10-30 01:04:40 UTC
Steps to reproduce:
```
rhc app create php php-5.3
rhc cartridge-add cron --app php
cd php
mkdir -p .openshift/cron/minutely
echo -e "#!/bin/sh\nenv>/tmp/env.txt" > .openshift/cron/minutely/env.sh 
chmod +x .openshift/cron/minutely/env.sh
git commit -ama
git push

rhc env set NAME="John Doe" --app php

#Bug:
rhc ssh php "cat /tmp/env.txt | grep NAME=Jo"
NAME=John

#Fix applied:
rhc ssh php "cat /tmp/env.txt | grep NAME=Jo"
NAME=John Doe
```

Comment 4 Vojtech Vitek 2014-10-30 01:05:04 UTC
https://github.com/openshift/origin-server/pull/5915

Comment 7 Jianwei Hou 2014-10-31 06:26:07 UTC
Verified on devenv-stage_1085, the bug is fixed and the env value can be loaded correctly by cron
[php1-jhou.dev.rhcloud.com 54535e8e84bceaf51e000001]\> cat /tmp/env.txt | grep NAME=Jo
NAME=John Doe


Note You need to log in before you can comment on or make changes to this bug.