openshift-origin-node 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of openshift-origin-node might be problematic. Click here for more details.

Files changed (51) hide show
  1. data/COPYRIGHT +1 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +11 -0
  4. data/README.md +3 -0
  5. data/Rakefile +28 -0
  6. data/bin/oo-add-alias +93 -0
  7. data/bin/oo-app-create +110 -0
  8. data/bin/oo-app-destroy +100 -0
  9. data/bin/oo-app-state-show +74 -0
  10. data/bin/oo-authorized-ssh-key-add +83 -0
  11. data/bin/oo-authorized-ssh-key-remove +82 -0
  12. data/bin/oo-broker-auth-key-add +84 -0
  13. data/bin/oo-broker-auth-key-remove +72 -0
  14. data/bin/oo-cartridge-info +70 -0
  15. data/bin/oo-cartridge-list +70 -0
  16. data/bin/oo-connector-execute +94 -0
  17. data/bin/oo-env-var-add +81 -0
  18. data/bin/oo-env-var-remove +78 -0
  19. data/bin/oo-get-quota +64 -0
  20. data/bin/oo-remove-alias +93 -0
  21. data/bin/oo-set-quota +59 -0
  22. data/conf/node.conf +30 -0
  23. data/conf/resource_limits.template +67 -0
  24. data/lib/openshift-origin-node.rb +29 -0
  25. data/lib/openshift-origin-node/config.rb +21 -0
  26. data/lib/openshift-origin-node/environment.rb +26 -0
  27. data/lib/openshift-origin-node/model/application_container.rb +298 -0
  28. data/lib/openshift-origin-node/model/frontend_httpd.rb +346 -0
  29. data/lib/openshift-origin-node/model/node.rb +134 -0
  30. data/lib/openshift-origin-node/model/unix_user.rb +738 -0
  31. data/lib/openshift-origin-node/plugins/unix_user_observer.rb +86 -0
  32. data/lib/openshift-origin-node/utils/shell_exec.rb +115 -0
  33. data/lib/openshift-origin-node/version.rb +23 -0
  34. data/misc/bin/oo-admin-ctl-cgroups +482 -0
  35. data/misc/bin/oo-cgroup-read +25 -0
  36. data/misc/bin/oo-get-mcs-level +29 -0
  37. data/misc/bin/oo-trap-user +248 -0
  38. data/misc/bin/rhcsh +155 -0
  39. data/misc/bin/setup_pam_fs_limits.sh +146 -0
  40. data/misc/bin/teardown_pam_fs_limits.sh +73 -0
  41. data/misc/doc/cgconfig.conf +26 -0
  42. data/misc/etc/openshift-run.conf +1 -0
  43. data/misc/init/openshift-cgroups +56 -0
  44. data/misc/services/openshift-cgroups.service +14 -0
  45. data/openshift-origin-node.gemspec +31 -0
  46. data/rubygem-openshift-origin-node.spec +263 -0
  47. data/test/test_helper.rb +20 -0
  48. data/test/unit/frontend_httpd_test.rb +144 -0
  49. data/test/unit/unix_user_test.rb +95 -0
  50. data/test/unit/version_test.rb +45 -0
  51. metadata +230 -0
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'etc'
4
+
5
+ # When combined with selinux, this script will allow users to read their own
6
+ # cgroups entries but not other users cgroups entries
7
+ euid = Process::Sys.geteuid
8
+ login = Etc.getpwuid(euid).name
9
+
10
+ attribute=ARGV[0]
11
+ unless attribute =~ /\A[a-zA-Z0-9\.\-_]*\z/
12
+ puts "#{attribute} is an invalid attribute"
13
+ exit 1
14
+ end
15
+
16
+ if File.exists? "/cgroup/all/openshift/#{login}/#{attribute}"
17
+ fp = File.new("/cgroup/all/openshift/#{login}/#{attribute}")
18
+ value = fp.gets
19
+ fp.close
20
+ else
21
+ puts "Could not find attribute #{attribute}"
22
+ exit 2
23
+ end
24
+
25
+ puts value
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+
3
+ function usage() {
4
+ echo "Usage: $0 [uid: 1-523776]" >&2
5
+ exit 1
6
+ }
7
+
8
+ function get_mcs_level() {
9
+ # UID=$1
10
+
11
+ SETSIZE=1023
12
+ TIER=$SETSIZE
13
+
14
+ ORD=$1
15
+ while [ $ORD -gt $(($TIER)) ]
16
+ do
17
+ ORD=$(($ORD - $TIER))
18
+ TIER=$(($TIER - 1))
19
+ done
20
+ TIER=$(($SETSIZE - $TIER))
21
+
22
+ echo s0:c$TIER,c$(($ORD + $TIER))
23
+ }
24
+
25
+
26
+ trap usage ERR
27
+ test "$1" -ge 1 &>/dev/null
28
+ test "$1" -le 523776 &>/dev/null
29
+ get_mcs_level "$1"
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/python -tt
2
+
3
+ import sys, os
4
+ import syslog
5
+ import pwd
6
+ import syslog
7
+ import glob
8
+ import base64
9
+ import commands
10
+ import re
11
+ import selinux
12
+
13
+ EXT_LIB = "/usr/libexec/openshift/lib/util"
14
+
15
+ commands_map = {
16
+ "git-receive-pack": "/usr/bin/git-receive-pack",
17
+ "git-upload-pack": "/usr/bin/git-upload-pack",
18
+ "snapshot": "/bin/bash",
19
+ "restore": "/bin/bash",
20
+ "tail": "/usr/bin/tail",
21
+ "rhcsh": "/bin/bash",
22
+ "true": "/bin/true",
23
+ "java": "/bin/bash",
24
+ "scp": "/bin/bash",
25
+ "cd": "/bin/bash",
26
+ "set": "/bin/bash",
27
+ "mkdir": "/bin/bash",
28
+ "test": "/bin/bash",
29
+ "rsync": "/bin/bash",
30
+ "ctl_all": "/bin/bash",
31
+ "deploy.sh": "/bin/bash",
32
+ "rhc-list-ports": "/bin/bash",
33
+ "post_deploy.sh": "/bin/bash",
34
+ "quota": "/usr/bin/quota"
35
+ }
36
+
37
+ comment_re = re.compile("#.*$")
38
+
39
+ #
40
+ # Read in uservars variables.
41
+ #
42
+ def _set_env_uservars(uservars_dir):
43
+ for env in os.listdir(uservars_dir):
44
+ fp = open(os.path.join(uservars_dir, env), 'r')
45
+ env_var = fp.readlines()[0].strip().strip('\'"')
46
+ fp.close()
47
+ os.putenv(env, env_var)
48
+ pass
49
+
50
+ #
51
+ # Read in environment variables
52
+ #
53
+ def read_env_vars():
54
+ # os.putenv
55
+ envdir = os.path.expanduser('~/.env/')
56
+ for env in os.listdir(envdir):
57
+ if env in ['USER_VARS', 'TYPELESS_TRANSLATED_VARS']:
58
+ continue
59
+ elif os.path.isdir(envdir + env):
60
+ if '.uservars' == env:
61
+ _set_env_uservars(envdir + env)
62
+ continue
63
+
64
+ fp = open(os.path.expanduser('~/.env/') + env, 'r')
65
+ env_var = fp.readlines()[0].strip().split('=')[1].strip('\'"')
66
+ fp.close()
67
+ os.putenv(env, env_var)
68
+
69
+ def get_mcs_level(uid):
70
+ cmd = "/usr/bin/oo-get-mcs-level %s" % (uid)
71
+ ret = commands.getstatusoutput(cmd)
72
+ return ret[1]
73
+
74
+ def read_config():
75
+ config = {}
76
+ f = open('/etc/openshift/node.conf','r')
77
+ data = f.read()
78
+ f.close()
79
+ lines = data.split("\n")
80
+ for line in lines:
81
+ clean_line = comment_re.sub("", line) # remove comments
82
+ clean_line = clean_line.strip() # remove leading and trailing white space
83
+ if clean_line != "":
84
+ split_line = clean_line.split("=")
85
+ if len(split_line) != 2:
86
+ syslog.syslog("node config error: %s" % (line))
87
+ sys.stderr.write("Error in node configuration")
88
+ sys.exit(2) # need to set the proper exit code
89
+ value = split_line[1].strip('\'"') # remove quotes from value strings
90
+ config[split_line[0]] = value
91
+ return config
92
+
93
+ #
94
+ # Join the user's cgroup if available
95
+ #
96
+ def join_cgroup():
97
+ """
98
+ Determine a user's cgroup and join it if possible
99
+ """
100
+
101
+ username = pwd.getpwuid(os.getuid())[0]
102
+ pid = os.getpid()
103
+
104
+ # this should come from /etc/openshift/node.conf:OPENSHIFT_CGROUP_ROOT
105
+ cgroup_root = "/cgroup/all/openshift"
106
+ cgroup_user = os.path.join(cgroup_root, username)
107
+ cgroup_tasks = os.path.join(cgroup_user, "tasks")
108
+
109
+ syslog.syslog("user %s: putting process %d in cgroup %s" % (username, pid, cgroup_root))
110
+
111
+ if not os.path.isdir(cgroup_root):
112
+ # raise an exception
113
+ return
114
+
115
+ if not os.path.isdir(cgroup_user):
116
+ # raise an exception
117
+ return
118
+
119
+ if not os.path.isfile(cgroup_tasks):
120
+ # raise an exception
121
+ return
122
+
123
+ # try:
124
+ taskfile = open(cgroup_tasks, 'w')
125
+ taskfile.write(str(pid) + "\n")
126
+ taskfile.flush()
127
+ taskfile.close()
128
+ # except IOError, e:
129
+ # write "can't join cgroup" message
130
+
131
+ if __name__ == '__main__':
132
+ # first self-apply restrictions
133
+ join_cgroup()
134
+ read_env_vars()
135
+ config = read_config()
136
+
137
+ orig_cmd = os.environ.get('SSH_ORIGINAL_COMMAND', "rhcsh")
138
+ syslog.syslog(orig_cmd)
139
+ allargs = orig_cmd.split()
140
+ try:
141
+ basecmd = os.path.basename(allargs[0])
142
+ cmd = commands_map[basecmd]
143
+ except:
144
+ # Catch all, just run the command as is via bash.
145
+ cmd = "/bin/bash"
146
+ str = ' '.join(allargs)
147
+ allargs = ['-c', str]
148
+ if basecmd in ('snapshot',):
149
+ # This gets called with "snapshot"
150
+ allargs = ['snapshot.sh']
151
+ if basecmd in ('restore',):
152
+ # This gets called with "restore <INCLUDE_GIT>"
153
+ include_git = False
154
+ if len(allargs) > 1 and allargs[1] == 'INCLUDE_GIT':
155
+ include_git = True
156
+
157
+ allargs = ['restore.sh']
158
+ if include_git:
159
+ allargs.append('INCLUDE_GIT')
160
+ elif basecmd in ('rhcsh',):
161
+ os.environ["PS1"] = "rhcsh> "
162
+ if len(allargs) < 2:
163
+ allargs = ['--init-file', '/usr/bin/rhcsh', '-i']
164
+ else:
165
+ str = ' '.join(allargs[1:])
166
+ allargs = ['--init-file', '/usr/bin/rhcsh', '-c', str]
167
+ elif basecmd in ('ctl_all',):
168
+ allargs = ['-c', '. /usr/bin/rhcsh > /dev/null ; ctl_all %s' % allargs[-1]]
169
+ elif basecmd in ('java','set','scp', 'cd', 'test', 'mkdir', 'rsync', 'deploy.sh', 'post_deploy.sh', 'rhc-list-ports'):
170
+ str = ' '.join(allargs)
171
+ allargs = ['-c', str]
172
+ elif basecmd in ('tail',):
173
+ files = []
174
+
175
+ files_start_index = 1
176
+ args = []
177
+ add_follow = True
178
+ if allargs[1] == '--opts':
179
+ files_start_index = 3
180
+ args_str = base64.standard_b64decode(allargs[2])
181
+ args = args_str.split()
182
+ for arg in args:
183
+ if arg.startswith(('..', '/')):
184
+ print "All paths must be relative: " + arg
185
+ sys.exit(88)
186
+ elif arg == '-f' or arg == '-F' or arg.startswith('--follow'):
187
+ add_follow = False
188
+
189
+ for glob_list in allargs[files_start_index:]:
190
+ for f in glob.glob(glob_list):
191
+ try:
192
+ if os.path.islink(f) and os.path.lexists(f):
193
+ files.append(f)
194
+ else:
195
+ files.append(f)
196
+ except OSError, e:
197
+ print "Error: %s" % e.strerror
198
+ sys.exit(91)
199
+ if len(files) == 0:
200
+ print "Could not find any files matching glob"
201
+ sys.exit(32)
202
+ allargs = []
203
+ allargs.extend(args)
204
+ if add_follow:
205
+ allargs.append('-f')
206
+ allargs.extend(files)
207
+ elif basecmd in ('git-receive-pack', 'git-upload-pack'):
208
+ # git repositories need to be parsed specially
209
+ thearg = ' '.join(allargs[1:])
210
+ if thearg[0] == "'" and thearg[-1] == "'":
211
+ thearg = thearg.replace("'","")
212
+ thearg = thearg.replace("\\'", "")
213
+ thearg = thearg.replace("//", "/")
214
+
215
+ # replace leading tilde (~) with user's home path
216
+ realpath = os.path.expanduser(thearg)
217
+ if not realpath.startswith(config['GEAR_BASE_DIR']):
218
+ syslog.syslog("Invalid repository: not in openshift_root (%s) - %s: (%s)" %
219
+ (config['GEAR_BASE_DIR'], thearg, realpath))
220
+ print "Invalid repository %s: not in application root" % thearg
221
+ sys.exit(3)
222
+
223
+ if not os.path.isdir(realpath):
224
+ syslog.syslog("Invalid repository %s (%s)" %
225
+ (thearg, realpath))
226
+ print "Invalid repository %s: not a directory" % thearg
227
+ sys.exit(3)
228
+ allargs = [thearg]
229
+
230
+ elif basecmd in ('quota',):
231
+ allargs = []
232
+
233
+ runcon = '/usr/bin/runcon'
234
+ mcs_level = get_mcs_level(os.getuid())
235
+
236
+ target_context = 'unconfined_u:system_r:openshift_t:%s' % mcs_level
237
+ actual_context = selinux.getcon()[1]
238
+ if target_context != actual_context:
239
+ print "Invalid context"
240
+ sys.exit(40)
241
+ # This else is left in because at the time of writing this statement
242
+ # We have a patched ssh running. Remove the exit above and it should
243
+ # work on other platforms.
244
+ os.execv(runcon, [runcon, target_context, cmd] + allargs)
245
+ sys.exit(1)
246
+ else:
247
+ os.execv(cmd, [cmd] + allargs)
248
+ sys.exit(1)
@@ -0,0 +1,155 @@
1
+ #!/bin/bash
2
+
3
+ #. /etc/bashrc
4
+
5
+ [ -f ~/app-root/data/.bash_profile ] && source ~/app-root/data/.bash_profile
6
+
7
+ source /etc/init.d/functions 2> /dev/null
8
+
9
+ # Import Environment Variables
10
+ for f in ~/.env/*
11
+ do
12
+ . $f
13
+ done
14
+
15
+ function welcome {
16
+ cat 1>&2 <<EOF
17
+
18
+ *********************************************************************
19
+
20
+ You are accessing a service that is for use only by authorized users.
21
+ If you do not have authorization, discontinue use at once.
22
+ Any use of the services is subject to the applicable terms of the
23
+ agreement which can be found at:
24
+ https://openshift.redhat.com/app/legal
25
+
26
+ *********************************************************************
27
+
28
+ Welcome to OpenShift shell
29
+
30
+ This shell will assist you in managing OpenShift applications.
31
+
32
+ !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
33
+ Shell access is quite powerful and it is possible for you to
34
+ accidentally damage your application. Proceed with care!
35
+ If worse comes to worst, destroy your application with 'rhc app destroy'
36
+ and recreate it
37
+ !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
38
+
39
+ Type "help" for more info.
40
+
41
+ EOF
42
+ }
43
+
44
+
45
+ function _get_app_ctl_script() {
46
+ bash <<EOF
47
+ source /etc/openshift/node.conf
48
+ source \${CARTRIDGE_BASE_PATH}/abstract/info/lib/util
49
+ get_framework_ctl_script "$@"
50
+ EOF
51
+ }
52
+
53
+
54
+ function ctl_all {
55
+ case "$1" in
56
+ start) start_app.sh ;;
57
+ stop) stop_app.sh ;;
58
+ restart) stop_app.sh; start_app.sh ;;
59
+ esac
60
+ }
61
+
62
+
63
+ function mysql() {
64
+ # Setup default options.
65
+ [ -n "$OPENSHIFT_MYSQL_DB_HOST" ] && hostopt="-h $OPENSHIFT_MYSQL_DB_HOST"
66
+ portopt="-P ${OPENSHIFT_MYSQL_DB_PORT:-3306}"
67
+ useropt="-u ${OPENSHIFT_MYSQL_DB_USERNAME:-'admin'}"
68
+ passopt=--password="$OPENSHIFT_MYSQL_DB_PASSWORD"
69
+
70
+ # Unset default value if it was provided to us.
71
+ for arg in $@; do
72
+ case "$arg" in
73
+ --host=*|-h) unset hostopt ;;
74
+ --port=*|-P) unset portopt ;;
75
+ --user=*|-u) unset useropt ;;
76
+ --password=*|-p) unset passopt ;;
77
+ *) ;;
78
+ esac
79
+ done
80
+
81
+ /usr/bin/mysql ${hostopt} ${portopt} ${useropt} ${passopt} "$@"
82
+
83
+ } # End of mysql function.
84
+
85
+
86
+ function psql() {
87
+ PGDATABASE="$OPENSHIFT_APP_NAME" \
88
+ PGHOST="$OPENSHIFT_POSTGRESQL_DB_HOST" \
89
+ PGPORT="${OPENSHIFT_POSTGRESQL_DB_PORT:-5432}" \
90
+ PGUSER="${OPENSHIFT_POSTGRESQL_DB_USERNAME:-'admin'}" \
91
+ PGPASSWORD="${OPENSHIFT_POSTGRESQL_DB_PASSWORD}" \
92
+ /usr/bin/psql --set HISTFILE="~/app-root/data/.psql_history" "$@"
93
+ } # End of psql function.
94
+
95
+
96
+ function mongo() {
97
+ if test $# -gt 0; then
98
+ uopt=""
99
+ popt=""
100
+ else
101
+ uopt="--username ${OPENSHIFT_MONGODB_DB_USERNAME:-'admin'}"
102
+ [ -n "$OPENSHIFT_MONGODB_DB_PASSWORD" ] && popt="--password $OPENSHIFT_MONGODB_DB_PASSWORD"
103
+ fi
104
+
105
+ if echo "$@" | egrep "\-\-host|$OPENSHIFT_MONGODB_DB_HOST" > /dev/null; then
106
+ hopt="" # Do not override if --host is passed.
107
+ else
108
+ if [ -n "$OPENSHIFT_MONGODB_DB_GEAR_DNS" ]; then
109
+ hopt="${OPENSHIFT_MONGODB_DB_GEAR_DNS:-'127.0.0.1'}:${OPENSHIFT_MONGODB_DB_PORT:-27017}/admin"
110
+ else
111
+ hopt="${OPENSHIFT_MONGODB_DB_HOST:-'127.0.0.1'}:${OPENSHIFT_MONGODB_DB_PORT:-27017}/admin"
112
+ fi
113
+ fi
114
+
115
+ ( unset LD_LIBRARY_PATH; /usr/bin/mongo ${hopt} ${uopt} ${popt} "$@" )
116
+
117
+ } # End of mongo function.
118
+
119
+
120
+ function help {
121
+ cat <<EOF
122
+ Help menu: The following commands are available to help control your openshift
123
+ application and environment.
124
+
125
+ ctl_app control your application (start, stop, restart, etc)
126
+ ctl_all control application and deps like mysql in one command
127
+ tail_all tail all log files
128
+ export list available environment variables
129
+ rm remove files / directories
130
+ ls list files / directories
131
+ ps list running applications
132
+ kill kill running applications
133
+ mysql interactive MySQL shell
134
+ mongo interactive MongoDB shell
135
+ psql interactive PostgreSQL shell
136
+ quota list disk usage
137
+
138
+ EOF
139
+ }
140
+
141
+ alias ctl_app=$(_get_app_ctl_script $OPENSHIFT_GEAR_UUID)
142
+ alias tail_all="/usr/bin/tail -f */logs/*"
143
+
144
+ export PS1="[$OPENSHIFT_GEAR_DNS \W]\> "
145
+ export TMOUT=300
146
+ export SHELL=/bin/bash
147
+ welcome
148
+
149
+ # Since the user is actively using this gear, unidle the gear (if idle).
150
+ which unidle_gear.sh &> /dev/null && unidle_gear.sh "${PS1:+'show-messages'}"
151
+
152
+ if [ -z $SSH_TTY ]; then
153
+ echo "WARNING: This ssh terminal was started without a tty." 1>&2
154
+ echo " It is highly recommended to login with: ssh -t" 1>&2
155
+ fi